Last active
April 19, 2016 12:14
-
-
Save DiegoAscanio/9d7cf666c4ffa1fe0abe0f3c103cc0ba 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
error = lambda t: pass # hipotetico | |
getToken = lambda: pass # hipotetico | |
token = getToken() | |
def eat(t): | |
if token == t: | |
token = getToken() | |
else | |
error() | |
EXPR,IF,FOR,OTHER,SEMICOLON,OPEN_BRACKET,CLOSE_BRACKET=(1,2,3,4,5,6) # definicao dos tokens para essa primeira gramitca | |
def stmt(): | |
if token == EXPR: | |
eat(EXPR) | |
eat(SEMICOLON) | |
elif token == IF: | |
eat(OPEN_BRACKET) | |
eat(IF) | |
eat(EXPR) | |
eat(CLOSE_BRACKET) | |
stmt() | |
elif token == FOR: | |
eat(FOR) | |
eat(OPEN_BRACKET) | |
optexpr() | |
eat(SEMICOLON) | |
optexpr() | |
eat(SEMICOLON) | |
optexpr() | |
eat(CLOSE_BRACKET) | |
stmt() | |
elif token == OTHER: | |
eat(OTHER) | |
else: | |
error() | |
def optexpr(): | |
if token == EXPR: | |
eat(EXPR) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment