<s> import sys <EOL> if "<STR_LIT:..>" not in sys . path : sys . path . insert ( <NUM_LIT:0> , "<STR_LIT:..>" ) <EOL> import ply . yacc as yacc <EOL> from calclex import tokens <EOL> names = { } <EOL> def p_statement_assign ( t ) : <EOL> '<STR_LIT>' <EOL> names [ t [ <NUM_LIT:1> ] ] = t [ <NUM_LIT:3> ] <EOL> def p_statement_expr ( t ) : <EOL> '<STR_LIT>' <EOL> print ( t [ <NUM_LIT:1> ] ) <EOL> def p_expression_binop ( t ) : <EOL> '''<STR_LIT>''' <EOL> if t [ <NUM_LIT:2> ] == '<STR_LIT:+>' : t [ <NUM_LIT:0> ] = t [ <NUM_LIT:1> ] + t [ <NUM_LIT:3> ] <EOL> elif t [ <NUM_LIT:2> ] == '<STR_LIT:->' : t [ <NUM_LIT:0> ] = t [ <NUM_LIT:1> ] - t [ <NUM_LIT:3> ] <EOL> elif t [ <NUM_LIT:2> ] == '<STR_LIT:*>' : t [ <NUM_LIT:0> ] = t [ <NUM_LIT:1> ] * t [ <NUM_LIT:3> ] <EOL> elif t [ <NUM_LIT:2> ] == '<STR_LIT:/>' : t [ <NUM_LIT:0> ] = t [ <NUM_LIT:1> ] / t [ <NUM_LIT:3> ] <EOL> def p_expression_uminus ( t ) : <EOL> '<STR_LIT>' <EOL> t [ <NUM_LIT:0> ] = - t [ <NUM_LIT:2> ] <EOL> def p_expression_group ( t ) : <EOL> '<STR_LIT>' <EOL> t [ <NUM_LIT:0> ] = t [ <NUM_LIT:2> ] <EOL> def p_expression_number ( t ) : <EOL> '<STR_LIT>' <EOL> t [ <NUM_LIT:0> ] = t [ <NUM_LIT:1> ] <EOL> def p_expression_name ( t ) : <EOL> '<STR_LIT>' <EOL> try : <EOL> t [ <NUM_LIT:0> ] = names [ t [ <NUM_LIT:1> ] ] <EOL> except LookupError : <EOL> print ( "<STR_LIT>" % t [ <NUM_LIT:1> ] ) <EOL> t [ <NUM_LIT:0> ] = <NUM_LIT:0> <EOL> def p_error ( t ) : <EOL> print ( "<STR_LIT>" % t . value ) <EOL> yacc . yacc ( ) </s>
