2 * This header (everything before the first "%%") is copied
3 * directly to the output.
10 #define MBTREE_TYPE MBTree
12 typedef struct _MBTree MBTree;
19 %% these are the monoburg definition
21 # This is the start of the definitions
22 # comments start with a '#' as first line character
26 # we must fisrt define the terminals
27 # with or without numbers
29 %term Assign Constant Fetch=3 Four=8 Mul=5 Plus=6 AltFetch=7
32 # optional start nonterminal
44 int ern = mono_burg_rule (tree->state, MB_NTERM_addr);
45 printf ("%s\n", mono_burg_rule_string [ern]);
51 addr: Plus(con,Mul(Four,reg)) 2
53 int ern = mono_burg_rule (tree->state, MB_NTERM_addr);
54 printf ("%s\n", mono_burg_rule_string [ern]);
60 int ern = mono_burg_rule (tree->state, MB_NTERM_reg);
61 printf ("%s\n", mono_burg_rule_string [ern]);
64 reg: Assign(addr,reg) 1
66 int ern = mono_burg_rule (tree->state, MB_NTERM_reg);
67 printf ("%s\n", mono_burg_rule_string [ern]);
70 %% the rest is also copied directly to the output
71 /* everything below the second "%%" is also copied directly
76 create_tree (int op, MBTree *left, MBTree *right)
78 MBTree *t = g_new0 (MBTree, 1);
88 reduce (MBTree *tree, int goal)
91 int ern = mono_burg_rule (tree->state, goal);
92 guint16 *nts = mono_burg_nts [ern];
95 mono_burg_kids (tree, ern, kids);
97 // printf ("TEST %d %d %s %d\n", goal, ern, mono_burg_rule_string [ern], nts [0]);
99 for (i = 0; nts [i]; i++)
100 reduce (kids [i], nts [i]);
102 n = (tree->left != NULL) + (tree->right != NULL);
104 if (n) { /* not a terminal */
105 // printf ("XXTE %s %d\n", mono_burg_rule_string [ern], n);
106 if (mono_burg_func [ern])
107 mono_burg_func [ern] (tree, NULL);
109 g_warning ("no code for rule %s\n",
110 mono_burg_rule_string [ern]);
112 if (mono_burg_func [ern])
113 g_warning ("unused code in rule %s\n",
114 mono_burg_rule_string [ern]);
124 l = create_tree (MB_TERM_Constant, NULL, NULL);
126 r = create_tree (MB_TERM_Fetch, l, NULL);
127 l = create_tree (MB_TERM_Constant, NULL, NULL);
129 r = create_tree (MB_TERM_Assign, l, r);
130 l = create_tree (MB_TERM_Four, NULL, NULL);
132 r = create_tree (MB_TERM_Mul, l, r);
133 l = create_tree (MB_TERM_Constant, NULL, NULL);
135 l = create_tree (MB_TERM_Plus, l, r);
137 t = create_tree (MB_TERM_Fetch, l, NULL);
139 s = mono_burg_label (t, NULL);
143 reduce (t, MB_NTERM_reg);