summaryrefslogtreecommitdiff
path: root/ext/ply/example/calc/calc.py
diff options
context:
space:
mode:
authorGabe Black <gblack@eecs.umich.edu>2009-08-17 00:21:57 -0700
committerGabe Black <gblack@eecs.umich.edu>2009-08-17 00:21:57 -0700
commita43ae579dd3128a0ced2238532f26d99db197361 (patch)
tree271a90c0fdfde8b58180ee494c528a3fbec57588 /ext/ply/example/calc/calc.py
parent32c8514b450a7dda77a3963d00642fcc5de658da (diff)
parenta6b39c07d9d03955382a0e930b363c6e6fd4b942 (diff)
downloadgem5-a43ae579dd3128a0ced2238532f26d99db197361.tar.xz
Merge with head.
Diffstat (limited to 'ext/ply/example/calc/calc.py')
-rw-r--r--ext/ply/example/calc/calc.py24
1 files changed, 13 insertions, 11 deletions
diff --git a/ext/ply/example/calc/calc.py b/ext/ply/example/calc/calc.py
index 987ce8019..b92378043 100644
--- a/ext/ply/example/calc/calc.py
+++ b/ext/ply/example/calc/calc.py
@@ -8,6 +8,9 @@
import sys
sys.path.insert(0,"../..")
+if sys.version_info[0] >= 3:
+ raw_input = input
+
tokens = (
'NAME','NUMBER',
)
@@ -20,11 +23,7 @@ t_NAME = r'[a-zA-Z_][a-zA-Z0-9_]*'
def t_NUMBER(t):
r'\d+'
- try:
- t.value = int(t.value)
- except ValueError:
- print "Integer value too large", t.value
- t.value = 0
+ t.value = int(t.value)
return t
t_ignore = " \t"
@@ -32,11 +31,11 @@ t_ignore = " \t"
def t_newline(t):
r'\n+'
t.lexer.lineno += t.value.count("\n")
-
+
def t_error(t):
- print "Illegal character '%s'" % t.value[0]
+ print("Illegal character '%s'" % t.value[0])
t.lexer.skip(1)
-
+
# Build the lexer
import ply.lex as lex
lex.lex()
@@ -58,7 +57,7 @@ def p_statement_assign(p):
def p_statement_expr(p):
'statement : expression'
- print p[1]
+ print(p[1])
def p_expression_binop(p):
'''expression : expression '+' expression
@@ -87,11 +86,14 @@ def p_expression_name(p):
try:
p[0] = names[p[1]]
except LookupError:
- print "Undefined name '%s'" % p[1]
+ print("Undefined name '%s'" % p[1])
p[0] = 0
def p_error(p):
- print "Syntax error at '%s'" % p.value
+ if p:
+ print("Syntax error at '%s'" % p.value)
+ else:
+ print("Syntax error at EOF")
import ply.yacc as yacc
yacc.yacc()