From e1270f81bdc81f5a575b34c2d2c294bdde3e6f4f Mon Sep 17 00:00:00 2001 From: Nathan Binkert Date: Sun, 16 Aug 2009 13:39:58 -0700 Subject: ply: update PLY to version 3.2 --- ext/ply/example/newclasscalc/calc.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) mode change 100644 => 100755 ext/ply/example/newclasscalc/calc.py (limited to 'ext/ply/example/newclasscalc') diff --git a/ext/ply/example/newclasscalc/calc.py b/ext/ply/example/newclasscalc/calc.py old mode 100644 new mode 100755 index 7f29bc821..a12e498b2 --- a/ext/ply/example/newclasscalc/calc.py +++ b/ext/ply/example/newclasscalc/calc.py @@ -14,7 +14,9 @@ import sys sys.path.insert(0,"../..") -import readline +if sys.version_info[0] >= 3: + raw_input = input + import ply.lex as lex import ply.yacc as yacc import os @@ -51,10 +53,10 @@ class Parser(object): s = raw_input('calc > ') except EOFError: break - if not s: continue + if not s: continue yacc.parse(s) - + class Calc(Parser): tokens = ( @@ -80,7 +82,7 @@ class Calc(Parser): try: t.value = int(t.value) except ValueError: - print "Integer value too large", t.value + print("Integer value too large %s" % t.value) t.value = 0 #print "parsed number %s" % repr(t.value) return t @@ -90,9 +92,9 @@ class Calc(Parser): def t_newline(self, t): r'\n+' t.lexer.lineno += t.value.count("\n") - + def t_error(self, t): - print "Illegal character '%s'" % t.value[0] + print("Illegal character '%s'" % t.value[0]) t.lexer.skip(1) # Parsing rules @@ -110,7 +112,7 @@ class Calc(Parser): def p_statement_expr(self, p): 'statement : expression' - print p[1] + print(p[1]) def p_expression_binop(self, p): """ @@ -144,11 +146,14 @@ class Calc(Parser): try: p[0] = self.names[p[1]] except LookupError: - print "Undefined name '%s'" % p[1] + print("Undefined name '%s'" % p[1]) p[0] = 0 def p_error(self, p): - print "Syntax error at '%s'" % p.value + if p: + print("Syntax error at '%s'" % p.value) + else: + print("Syntax error at EOF") if __name__ == '__main__': calc = Calc() -- cgit v1.2.3