Mercurial > lcfOS
comparison python/burg.x @ 319:8d07a4254f04
Work on burg
author | Windel Bouwman |
---|---|
date | Sat, 18 Jan 2014 18:58:43 +0100 |
parents | e84047f29c78 |
children | 44f336460c2a |
comparison
equal
deleted
inserted
replaced
318:e84047f29c78 | 319:8d07a4254f04 |
---|---|
1 | 1 |
2 from tree import Tree | 2 %tokens ':' ';' '(' ')' ',' template id number '%%' '%terminal' |
3 %tokens ':' ';' '(' ')' ',' template id number '%%' header | |
4 | 3 |
5 %% | 4 %% |
6 | 5 |
7 rule: id ':' tree template cost { self.add_rule($1, $3, $4, $5) }; | 6 burgdef: directives '%%' rules; |
8 | 7 |
9 cost: number { return number.val }; | 8 directives: |
9 | directives directive; | |
10 | 10 |
11 tree: id { return Tree($1) } | 11 directive: termdef; |
12 | id '(' tree ')' { return Tree($1, $3) } | |
13 | id '(' tree ',' tree ')' { return Tree($1, $3, $5) }; | |
14 | 12 |
13 termdef: '%terminal' termids; | |
15 | 14 |
15 termids: | |
16 | termids termid; | |
17 | |
18 termid: id { self.system.add_terminal($1.val) }; | |
19 | |
20 rules: | |
21 | rules rule; | |
22 | |
23 rule: id ':' tree cost template { self.system.add_rule($1.val, $3, $4, $5.val) }; | |
24 | |
25 cost: number { return $1.val }; | |
26 | |
27 tree: id { return self.system.tree($1.val) } | |
28 | id '(' tree ')' { return self.system.tree($1.val, $3) } | |
29 | id '(' tree ',' tree ')' { return self.system.tree($1.val, $3, $5) }; | |
30 |