Skip to content

Instantly share code, notes, and snippets.

@barik
Created February 28, 2014 03:32
Show Gist options
  • Save barik/9264676 to your computer and use it in GitHub Desktop.
Save barik/9264676 to your computer and use it in GitHub Desktop.
Grammar
def p_exp_int(p):
'exp : INT'
p[0] = ast.Num(p[1], p.lineno(1))
def p_exp_bool_true(p):
'exp : TRUE'
p[0] = ast.Bool(True, p.lineno(1))
def p_exp_bool_false(p):
'exp : FALSE'
p[0] = ast.Bool(False, p.lineno(1))
...
def p_exp_binary(p):
'''
exp : exp PLUS exp
| exp MINUS exp
| exp STAR exp
| exp SLASH exp
| exp MOD exp
| exp EQ exp
| exp NEQ exp
| exp GT exp
| exp LT exp
| exp GE exp
| exp LE exp
'''
p[0] = ast.BinOp(p[1], p[2], p[3], p.lineno(3))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment