7267
|
1 import sys
|
|
2
|
|
3 if ".." not in sys.path: sys.path.insert(0,"..")
|
|
4
|
|
5 from ply import lex, yacc
|
|
6
|
|
7 t_A = 'A'
|
|
8 t_B = 'B'
|
|
9 t_C = 'C'
|
|
10
|
|
11 tokens = ('A', 'B', 'C')
|
|
12
|
|
13 the_lexer = lex.lex()
|
|
14
|
|
15 def t_error(t):
|
|
16 pass
|
|
17
|
|
18 def p_error(p):
|
|
19 pass
|
|
20
|
|
21 def p_start(t):
|
|
22 '''start : A nest C'''
|
|
23 pass
|
|
24
|
|
25 def p_nest(t):
|
|
26 '''nest : B'''
|
|
27 print(t[-1])
|
|
28
|
|
29 the_parser = yacc.yacc(debug = False, write_tables = False)
|
|
30
|
|
31 the_parser.parse('ABC', the_lexer)
|
|
32 the_parser.parse('ABC', the_lexer, tracking=True)
|
|
33 the_parser.parse('ABC', the_lexer, tracking=True, debug=1)
|