Mercurial > repo
comparison ply-3.8/test/yacc_nested.py @ 7267:343ff337a19b
<ais523> ` tar -xf ply-3.8.tar.gz
author | HackBot |
---|---|
date | Wed, 23 Mar 2016 02:40:16 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
7266:61a39a120dee | 7267:343ff337a19b |
---|---|
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) |