-
Notifications
You must be signed in to change notification settings - Fork 2
/
autoprojparser.py
58 lines (46 loc) · 1.07 KB
/
autoprojparser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import autoprojtokens
#import jsgrammar
import ply.lex as lex
import ply.yacc as yacc
start = 'exp'
precedence = (
('left', 'NUMBER'),
# ('left', 'ANDAND'),
# ('left', 'EQUALEQUAL'),
# ('left', 'LT', 'LE', 'GT', 'GE'),
# ('left', 'PLUS', 'MINUS'),
# ('left', 'TIMES', 'DIVIDE'),
# ('right', 'NOT'),
)
tokens = (
'NEWLINE',
'TAB',
'SPACE',
# 'ASSIGNMENT',
'ARRAYEACH',
'DO',
'LOOPVAR',
'PUTS',
'END',
'IDENTIFIER',
'NUMBER',
'OPERATOR',
'LEFTBRACKET',
'RIGHTBRACKET',
)
def p_exp_call(p):
'exp : NUMBER'
p[0] = ("call", p[1])
# def p_exp_number(p):
# 'exp : number'
# p[0] = ("number", p[1])
# def p_optargs(p):
# 'optargs : args'
# p[0] = p[1] # the work happens in "args"
def p_error(p):
print "Syntax error in input!"
# here's some code to test with
rubylexer = lex.lex(module=autoprojtokens)
rubyparser = yacc.yacc()
rubyast = rubyparser.parse("71", lexer=rubylexer)
print rubyast