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
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]);
59 int ern = mono_burg_rule (tree->state, MB_NTERM_reg);
60 printf ("%s\n", mono_burg_rule_string [ern]);
63 reg: Assign(addr,reg) 1
65 int ern = mono_burg_rule (tree->state, MB_NTERM_reg);
66 printf ("%s\n", mono_burg_rule_string [ern]);
69 %% the rest is also copied directly to the output
70 /* everything below the second "%%" is also copied directly
75 create_tree (int op, MBTree *left, MBTree *right)
77 MBTree *t = g_new0 (MBTree, 1);
87 reduce (MBTree *tree, int goal)
90 int ern = mono_burg_rule (tree->state, goal);
91 guint16 *nts = mono_burg_nts [ern];
94 mono_burg_kids (tree, ern, kids);
96 // printf ("TEST %d %d %s %d\n", goal, ern, mono_burg_rule_string [ern], nts [0]);
98 for (i = 0; nts [i]; i++)
99 reduce (kids [i], nts [i]);
101 n = (tree->left != NULL) + (tree->right != NULL);
103 if (n) { /* not a terminal */
104 // printf ("XXTE %s %d\n", mono_burg_rule_string [ern], n);
105 if (mono_burg_func [ern])
106 mono_burg_func [ern] (tree, NULL);
108 g_warning ("no code for rule %s\n",
109 mono_burg_rule_string [ern]);
111 if (mono_burg_func [ern])
112 g_warning ("unused code in rule %s\n",
113 mono_burg_rule_string [ern]);
123 l = create_tree (MB_TERM_Constant, NULL, NULL);
125 r = create_tree (MB_TERM_Fetch, l, NULL);
126 l = create_tree (MB_TERM_Constant, NULL, NULL);
128 r = create_tree (MB_TERM_Assign, l, r);
129 l = create_tree (MB_TERM_Four, NULL, NULL);
131 r = create_tree (MB_TERM_Mul, l, r);
132 l = create_tree (MB_TERM_Constant, NULL, NULL);
134 l = create_tree (MB_TERM_Plus, l, r);
136 t = create_tree (MB_TERM_Fetch, l, NULL);
138 s = mono_burg_label (t, NULL);
142 reduce (t, MB_NTERM_reg);