Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/dabeaz/ply
Browse files Browse the repository at this point in the history
  • Loading branch information
dabeaz committed Jan 31, 2017
2 parents 3335be2 + 11eb4cf commit 2ba2f31
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions example/yply/ylex.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ def t_code_error(t):


def t_error(t):
print "%d: Illegal character '%s'" % (t.lexer.lineno, t.value[0])
print t.value
print("%d: Illegal character '%s'" % (t.lexer.lineno, t.value[0]))
print(t.value)
t.lexer.skip(1)

lex.lex()
Expand Down
32 changes: 16 additions & 16 deletions example/yply/yparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ def p_defsection(p):
'''defsection : definitions SECTION
| SECTION'''
p.lexer.lastsection = 1
print "tokens = ", repr(tokenlist)
print
print "precedence = ", repr(preclist)
print
print "# -------------- RULES ----------------"
print
print("tokens = ", repr(tokenlist))
print()
print("precedence = ", repr(preclist))
print()
print("# -------------- RULES ----------------")
print()


def p_rulesection(p):
'''rulesection : rules SECTION'''

print "# -------------- RULES END ----------------"
print("# -------------- RULES END ----------------")
print_code(p[2], 0)


Expand All @@ -49,7 +49,7 @@ def p_definition_literal(p):

def p_definition_start(p):
'''definition : START ID'''
print "start = '%s'" % p[2]
print("start = '%s'" % p[2])


def p_definition_token(p):
Expand Down Expand Up @@ -138,7 +138,7 @@ def p_rules(p):
rulecount = 1
for r in rule[1]:
# r contains one of the rule possibilities
print "def p_%s_%d(p):" % (rulename, rulecount)
print("def p_%s_%d(p):" % (rulename, rulecount))
prod = []
prodcode = ""
for i in range(len(r)):
Expand All @@ -155,17 +155,17 @@ def p_rules(p):
embed_count += 1
else:
prod.append(item)
print " '''%s : %s'''" % (rulename, " ".join(prod))
print(" '''%s : %s'''" % (rulename, " ".join(prod)))
# Emit code
print_code(prodcode, 4)
print
print()
rulecount += 1

for e, code in embedded:
print "def p_%s(p):" % e
print " '''%s : '''" % e
print("def p_%s(p):" % e)
print(" '''%s : '''" % e)
print_code(code, 4)
print
print()


def p_rule(p):
Expand Down Expand Up @@ -204,7 +204,7 @@ def p_morerules(p):
p[0] = p[1]
p[0].append(p[3])

# print "morerules", len(p), p[0]
# print("morerules", len(p), p[0])


def p_rulelist(p):
Expand Down Expand Up @@ -241,4 +241,4 @@ def print_code(code, indent):
return
codelines = code.splitlines()
for c in codelines:
print "%s# %s" % (" " * indent, c)
print("%s# %s" % (" " * indent, c))
8 changes: 4 additions & 4 deletions example/yply/yply.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,23 @@
from ply import *

if len(sys.argv) == 1:
print "usage : yply.py [-nocode] inputfile"
print("usage : yply.py [-nocode] inputfile")
raise SystemExit

if len(sys.argv) == 3:
if sys.argv[1] == '-nocode':
yparse.emit_code = 0
else:
print "Unknown option '%s'" % sys.argv[1]
print("Unknown option '%s'" % sys.argv[1])
raise SystemExit
filename = sys.argv[2]
else:
filename = sys.argv[1]

yacc.parse(open(filename).read())

print """
print("""
if __name__ == '__main__':
from ply import *
yacc.yacc()
"""
""")

0 comments on commit 2ba2f31

Please sign in to comment.