Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(628)

Side by Side Diff: tools/nixysa/third_party/ply-3.1/test/yacc_uprec2.py

Issue 2043006: WTF NPAPI extension. Early draft. Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 10 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/nixysa/third_party/ply-3.1/test/yacc_uprec.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 # -----------------------------------------------------------------------------
2 # yacc_uprec2.py
3 #
4 # A grammar with a bad %prec specifier
5 # -----------------------------------------------------------------------------
6 import sys
7
8 if ".." not in sys.path: sys.path.insert(0,"..")
9 import ply.yacc as yacc
10
11 from calclex import tokens
12
13 # Parsing rules
14
15 # dictionary of names
16 names = { }
17
18 def p_statement_assign(t):
19 'statement : NAME EQUALS expression'
20 names[t[1]] = t[3]
21
22 def p_statement_expr(t):
23 'statement : expression'
24 print(t[1])
25
26 def p_expression_binop(t):
27 '''expression : expression PLUS expression
28 | expression MINUS expression
29 | expression TIMES expression
30 | expression DIVIDE expression'''
31 if t[2] == '+' : t[0] = t[1] + t[3]
32 elif t[2] == '-': t[0] = t[1] - t[3]
33 elif t[2] == '*': t[0] = t[1] * t[3]
34 elif t[2] == '/': t[0] = t[1] / t[3]
35
36 def p_expression_uminus(t):
37 'expression : MINUS expression %prec'
38 t[0] = -t[2]
39
40 def p_expression_group(t):
41 'expression : LPAREN expression RPAREN'
42 t[0] = t[2]
43
44 def p_expression_number(t):
45 'expression : NUMBER'
46 t[0] = t[1]
47
48 def p_expression_name(t):
49 'expression : NAME'
50 try:
51 t[0] = names[t[1]]
52 except LookupError:
53 print("Undefined name '%s'" % t[1])
54 t[0] = 0
55
56 def p_error(t):
57 print("Syntax error at '%s'" % t.value)
58
59 yacc.yacc()
60
61
62
63
OLDNEW
« no previous file with comments | « tools/nixysa/third_party/ply-3.1/test/yacc_uprec.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698