diff python/burg.x @ 319:8d07a4254f04

Work on burg
author Windel Bouwman
date Sat, 18 Jan 2014 18:58:43 +0100
parents e84047f29c78
children 44f336460c2a
line wrap: on
line diff
--- a/python/burg.x	Tue Dec 31 12:38:15 2013 +0100
+++ b/python/burg.x	Sat Jan 18 18:58:43 2014 +0100
@@ -1,15 +1,30 @@
 
-from tree import Tree
-%tokens ':' ';' '(' ')' ',' template id number '%%' header
+%tokens ':' ';' '(' ')' ',' template id number '%%' '%terminal'
 
 %%
 
-rule: id ':' tree template cost { self.add_rule($1, $3, $4, $5) };
+burgdef: directives '%%' rules;
+
+directives:
+          | directives directive;
 
-cost: number { return number.val };
+directive: termdef;
+
+termdef: '%terminal' termids;
+
+termids:
+       | termids termid;
 
-tree: id { return Tree($1) }
-    | id '(' tree ')' { return Tree($1, $3) }
-    | id '(' tree ',' tree ')' { return Tree($1, $3, $5) };
+termid: id { self.system.add_terminal($1.val) };
+
+rules:
+     | rules rule;
+
+rule: id ':' tree cost template { self.system.add_rule($1.val, $3, $4, $5.val) };
 
+cost: number { return $1.val };
 
+tree: id { return self.system.tree($1.val) }
+    | id '(' tree ')' { return self.system.tree($1.val, $3) }
+    | id '(' tree ',' tree ')' { return self.system.tree($1.val, $3, $5) };
+