Created
January 19, 2012 21:39
-
-
Save x3ro/1642916 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf8 -*- | |
# T → g(b|c)d | |
import sys | |
parseInput = sys.argv[1] | |
def match(parseInput, val, i): | |
if len(parseInput)-1 < i: | |
raise Exception("Too short") | |
print "Checking if '%s' is '%s' => %r" % (parseInput[i], val, parseInput[i]==i) | |
return parseInput[i] == i | |
def T(parseInput, i): | |
if match(parseInput, 'g', i): | |
if(match(parseInput, 'b', i+1)): | |
True | |
elif match(parseInput, 'c', i+1): | |
True | |
else: | |
raise Exception("nope") | |
if match(parseInput, 'd', i+2): | |
True | |
else: | |
raise Exception("nope") | |
else: | |
raise Exception("nope") | |
T(parseInput, 0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment