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

Side by Side Diff: tools/nixysa/third_party/ply-3.1/test/yacc_badprec.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
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 # -----------------------------------------------------------------------------
2 # yacc_badprec.py
3 #
4 # Bad precedence 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 precedence = "blah"
15
16 # dictionary of names
17 names = { }
18
19 def p_statement_assign(t):
20 'statement : NAME EQUALS expression'
21 names[t[1]] = t[3]
22
23 def p_statement_expr(t):
24 'statement : expression'
25 print(t[1])
26
27 def p_expression_binop(t):
28 '''expression : expression PLUS expression
29 | expression MINUS expression
30 | expression TIMES expression
31 | expression DIVIDE expression'''
32 if 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 elif t[2] == '/': t[0] = t[1] / t[3]
36
37 def p_expression_uminus(t):
38 'expression : MINUS expression %prec UMINUS'
39 t[0] = -t[2]
40
41 def p_expression_group(t):
42 'expression : LPAREN expression RPAREN'
43 t[0] = t[2]
44
45 def p_expression_number(t):
46 'expression : NUMBER'
47 t[0] = t[1]
48
49 def p_expression_name(t):
50 'expression : NAME'
51 try:
52 t[0] = names[t[1]]
53 except LookupError:
54 print("Undefined name '%s'" % t[1])
55 t[0] = 0
56
57 def p_error(t):
58 print("Syntax error at '%s'" % t.value)
59
60 yacc.yacc()
61
62
63
64
OLDNEW
« no previous file with comments | « tools/nixysa/third_party/ply-3.1/test/yacc_badid.py ('k') | tools/nixysa/third_party/ply-3.1/test/yacc_badprec2.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698