annotate python/burg.x @ 318:e84047f29c78

Add burg and yacc initial attempts
author Windel Bouwman
date Tue, 31 Dec 2013 12:38:15 +0100
parents
children 8d07a4254f04
rev   line source
318
e84047f29c78 Add burg and yacc initial attempts
Windel Bouwman
parents:
diff changeset
1
e84047f29c78 Add burg and yacc initial attempts
Windel Bouwman
parents:
diff changeset
2 from tree import Tree
e84047f29c78 Add burg and yacc initial attempts
Windel Bouwman
parents:
diff changeset
3 %tokens ':' ';' '(' ')' ',' template id number '%%' header
e84047f29c78 Add burg and yacc initial attempts
Windel Bouwman
parents:
diff changeset
4
e84047f29c78 Add burg and yacc initial attempts
Windel Bouwman
parents:
diff changeset
5 %%
e84047f29c78 Add burg and yacc initial attempts
Windel Bouwman
parents:
diff changeset
6
e84047f29c78 Add burg and yacc initial attempts
Windel Bouwman
parents:
diff changeset
7 rule: id ':' tree template cost { self.add_rule($1, $3, $4, $5) };
e84047f29c78 Add burg and yacc initial attempts
Windel Bouwman
parents:
diff changeset
8
e84047f29c78 Add burg and yacc initial attempts
Windel Bouwman
parents:
diff changeset
9 cost: number { return number.val };
e84047f29c78 Add burg and yacc initial attempts
Windel Bouwman
parents:
diff changeset
10
e84047f29c78 Add burg and yacc initial attempts
Windel Bouwman
parents:
diff changeset
11 tree: id { return Tree($1) }
e84047f29c78 Add burg and yacc initial attempts
Windel Bouwman
parents:
diff changeset
12 | id '(' tree ')' { return Tree($1, $3) }
e84047f29c78 Add burg and yacc initial attempts
Windel Bouwman
parents:
diff changeset
13 | id '(' tree ',' tree ')' { return Tree($1, $3, $5) };
e84047f29c78 Add burg and yacc initial attempts
Windel Bouwman
parents:
diff changeset
14
e84047f29c78 Add burg and yacc initial attempts
Windel Bouwman
parents:
diff changeset
15