Skip to content

Instantly share code, notes, and snippets.

@x3ro
Created January 19, 2012 21:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save x3ro/1642916 to your computer and use it in GitHub Desktop.
Save x3ro/1642916 to your computer and use it in GitHub Desktop.
#!/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