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

Side by Side Diff: tools/nixysa/third_party/ply-3.1/test/yacc_literal.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_literal.py
3 #
4 # Grammar with bad literal characters
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 = (
15 ('left','+','-'),
16 ('left','*','/'),
17 ('right','UMINUS'),
18 )
19
20 # dictionary of names
21 names = { }
22
23 def p_statement_assign(t):
24 'statement : NAME EQUALS expression'
25 names[t[1]] = t[3]
26
27 def p_statement_expr(t):
28 'statement : expression'
29 print(t[1])
30
31 def p_expression_binop(t):
32 '''expression : expression '+' expression
33 | expression '-' expression
34 | expression '*' expression
35 | expression '/' expression
36 | expression '**' expression '''
37 if t[2] == '+' : t[0] = t[1] + t[3]
38 elif t[2] == '-': t[0] = t[1] - t[3]
39 elif t[2] == '*': t[0] = t[1] * t[3]
40 elif t[2] == '/': t[0] = t[1] / t[3]
41
42 def p_expression_uminus(t):
43 'expression : MINUS expression %prec UMINUS'
44 t[0] = -t[2]
45
46 def p_expression_group(t):
47 'expression : LPAREN expression RPAREN'
48 t[0] = t[2]
49
50 def p_expression_number(t):
51 'expression : NUMBER'
52 t[0] = t[1]
53
54 def p_expression_name(t):
55 'expression : NAME'
56 try:
57 t[0] = names[t[1]]
58 except LookupError:
59 print("Undefined name '%s'" % t[1])
60 t[0] = 0
61
62 def p_error(t):
63 print("Syntax error at '%s'" % t.value)
64
65 yacc.yacc()
66
67
68
69
OLDNEW
« no previous file with comments | « tools/nixysa/third_party/ply-3.1/test/yacc_inf.py ('k') | tools/nixysa/third_party/ply-3.1/test/yacc_misplaced.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698