initial
[prop.git] / prop-src / T3.cc
blobea719721b6462e91cb166f4ed3c2c3e76415a833
1 ///////////////////////////////////////////////////////////////////////////////
2 // This file is generated automatically using Prop (version 2.3.4),
3 // last updated on Mar 31, 1997.
4 // The original source file is "T3.pcc".
5 ///////////////////////////////////////////////////////////////////////////////
7 #define PROP_REWRITING_USED
8 #define PROP_QUARK_USED
9 #include <propdefs.h>
10 #line 1 "T3.pcc"
12 // Test the view mechanism
15 #include <assert.h>
16 #include <iostream.h>
18 enum exp_tag { Int = 1, Ident, Add, Sub, Mul, Div };
20 struct exp {
21 enum exp_tag tag;
22 union {
23 int number;
24 const char * ident;
25 struct { struct exp * l, * r; } children;
26 } u;
29 typedef struct exp * Exp;
31 Exp INT(int i)
32 { Exp e = new exp; e->tag = Int; e->u.number = i; return e; }
34 Exp ID(const char * id)
35 { Exp e = new exp; e->tag = Ident; e->u.ident = id; return e; }
37 Exp ADD(Exp a, Exp b)
38 { Exp e = new exp; e->tag = Add; e->u.children.l = a; e->u.children.r = b;
39 return e;
42 Exp SUB(Exp a, Exp b)
43 { Exp e = new exp; e->tag = Sub; e->u.children.l = a; e->u.children.r = b;
44 return e;
47 Exp MUL(Exp a, Exp b)
48 { Exp e = new exp; e->tag = Mul; e->u.children.l = a; e->u.children.r = b;
49 return e;
52 Exp DIV(Exp a, Exp b)
53 { Exp e = new exp; e->tag = Div; e->u.children.l = a; e->u.children.r = b;
54 return e;
57 #line 47 "T3.pcc"
58 #line 58 "T3.pcc"
59 #line 58 "T3.pcc"
60 #line 58 "T3.pcc"
63 ostream& operator << (ostream& s, const Exp& e)
65 #line 61 "T3.pcc"
66 #line 68 "T3.pcc"
68 switch ((e ? e->tag : 0)) {
69 case 0: {
70 #line 62 "T3.pcc"
71 return s << "NONE";
72 #line 62 "T3.pcc"
73 } break;
74 case Int: {
75 #line 63 "T3.pcc"
76 return s << e->u.number;
77 #line 63 "T3.pcc"
78 } break;
79 case Ident: {
80 #line 64 "T3.pcc"
81 return s << e->u.ident;
82 #line 64 "T3.pcc"
83 } break;
84 case Add: {
85 #line 65 "T3.pcc"
86 return s << '(' << e->u.children.l << " + " << e->u.children.r << ')';
87 #line 65 "T3.pcc"
88 } break;
89 case Sub: {
90 #line 66 "T3.pcc"
91 return s << '(' << e->u.children.l << " - " << e->u.children.r << ')';
92 #line 66 "T3.pcc"
93 } break;
94 case Mul: {
95 #line 67 "T3.pcc"
96 return s << '(' << e->u.children.l << " * " << e->u.children.r << ')';
97 #line 67 "T3.pcc"
98 } break;
99 case Div: {
100 #line 68 "T3.pcc"
101 return s << '(' << e->u.children.l << " / " << e->u.children.r << ')';
102 #line 68 "T3.pcc"
103 } break;
104 case 10: {} break;
107 #line 69 "T3.pcc"
108 #line 69 "T3.pcc"
112 int eval(const Exp& e)
114 #line 73 "T3.pcc"
115 #line 81 "T3.pcc"
117 switch ((e ? e->tag : 0)) {
118 case 0: {
119 #line 74 "T3.pcc"
120 return 0;
121 #line 74 "T3.pcc"
122 } break;
123 case Int: {
124 #line 75 "T3.pcc"
125 return e->u.number;
126 #line 75 "T3.pcc"
127 } break;
128 case Ident: {
129 #line 76 "T3.pcc"
130 return 0;
131 #line 76 "T3.pcc"
132 } break;
133 case Add: {
134 #line 77 "T3.pcc"
135 return eval(e->u.children.l) + eval(e->u.children.r);
136 #line 77 "T3.pcc"
137 } break;
138 case Sub: {
139 #line 78 "T3.pcc"
140 return eval(e->u.children.l) - eval(e->u.children.r);
141 #line 78 "T3.pcc"
142 } break;
143 case Mul: {
144 #line 79 "T3.pcc"
145 return eval(e->u.children.l) * eval(e->u.children.r);
146 #line 79 "T3.pcc"
147 } break;
148 case Div: {
149 switch ((e->u.children.r ? e->u.children.r->tag : 0)) {
150 case 0: {
151 L1:;
152 #line 81 "T3.pcc"
153 return eval(e->u.children.l) / eval(e->u.children.r);
154 #line 81 "T3.pcc"
155 } break;
156 case Int: {
157 switch (e->u.children.r->u.number) {
158 case 0: {
159 if (
160 #line 80 "T3.pcc"
161 (e->u.children.l != NONE)
162 #line 80 "T3.pcc"
165 #line 80 "T3.pcc"
166 cerr << "Division by zero\n"; return 0;
167 #line 80 "T3.pcc"
168 } else {
169 goto L1; }
170 } break;
171 default: { goto L1; }
173 } break;
174 case Ident: { goto L1; } break;
175 case Add: { goto L1; } break;
176 case Sub: { goto L1; } break;
177 case Mul: { goto L1; } break;
178 case Div: { goto L1; } break;
179 case 10: { goto L1; } break;
181 } break;
182 case 10: {} break;
185 #line 82 "T3.pcc"
186 #line 82 "T3.pcc"
190 void simplify(Exp& e)
193 #line 87 "T3.pcc"
194 #line 92 "T3.pcc"
195 extern void _T_3co_X1_rewrite(Exp & );
196 _T_3co_X1_rewrite(e);
197 #line 92 "T3.pcc"
198 #line 92 "T3.pcc"
202 int main()
203 { Exp e = ADD(MUL(INT(5),INT(2)),DIV(INT(30),INT(6)));
204 cout << "Expression = " << e << endl;
205 cout << "Eval(" << e << ") = " << eval(e) << endl;
206 simplify(e);
207 cout << "Simplified = " << e << endl;
208 assert(eval(e) == 15);
209 return 0;
212 Exp e =
213 #line 105 "T3.pcc"
214 #line 105 "T3.pcc"
215 CALL(INT(1), INT(2))
216 #line 105 "T3.pcc"
217 #line 105 "T3.pcc"
219 #line 106 "T3.pcc"
220 class _T_3co_X1 : public BURS {
221 private:
222 _T_3co_X1(const _T_3co_X1&); // no copy constructor
223 void operator = (const _T_3co_X1&); // no assignment
224 public:
225 struct _T_3co_X1_StateRec * stack__, * stack_top__;
226 public:
227 void labeler(const char *, int&, int);
228 void labeler(Quark, int&, int);
229 void labeler(Exp & redex, int&, int);
230 inline virtual void operator () (Exp & redex) { int s; labeler(redex,s,0); }
231 private:
232 public:
233 inline _T_3co_X1() {}
235 void _T_3co_X1_rewrite(Exp & _x_)
236 { _T_3co_X1 _r_;
237 _r_(_x_);
240 ///////////////////////////////////////////////////////////////////////////////
242 // This macro can be redefined by the user for debugging
244 ///////////////////////////////////////////////////////////////////////////////
245 #ifndef DEBUG__T_3co_X1
246 #define DEBUG__T_3co_X1(repl,redex,file,line,rule) repl
247 #else
248 static const char * _T_3co_X1_file_name = "T3.pcc";
249 #endif
251 static const TreeTables::State _T_3co_X1_theta_3[2][2] = {
252 { 0, 0 },
253 { 0, 2 }
257 static const TreeTables::State _T_3co_X1_theta_4[2][2] = {
258 { 0, 0 },
259 { 0, 3 }
263 static const TreeTables::State _T_3co_X1_theta_5[2][2] = {
264 { 0, 0 },
265 { 0, 4 }
269 static const TreeTables::State _T_3co_X1_theta_6[2][2] = {
270 { 0, 0 },
271 { 0, 5 }
275 static const TreeTables::State _T_3co_X1_mu_3_0[6] = {
276 0, 1, 0, 0, 0, 0
280 static const TreeTables::State _T_3co_X1_mu_3_1[6] = {
281 0, 1, 0, 0, 0, 0
285 static const TreeTables::State _T_3co_X1_mu_4_0[6] = {
286 0, 1, 0, 0, 0, 0
290 static const TreeTables::State _T_3co_X1_mu_4_1[6] = {
291 0, 1, 0, 0, 0, 0
295 static const TreeTables::State _T_3co_X1_mu_5_0[6] = {
296 0, 1, 0, 0, 0, 0
300 static const TreeTables::State _T_3co_X1_mu_5_1[6] = {
301 0, 1, 0, 0, 0, 0
305 static const TreeTables::State _T_3co_X1_mu_6_0[6] = {
306 0, 1, 0, 0, 0, 0
310 static const TreeTables::State _T_3co_X1_mu_6_1[6] = {
311 0, 1, 0, 0, 0, 0
315 inline void _T_3co_X1::labeler(char const * redex,int& s__,int)
318 s__ = 0;
322 inline void _T_3co_X1::labeler(Quark redex,int& s__,int)
325 s__ = 0;
329 void _T_3co_X1::labeler (Exp & redex, int& s__, int r__)
331 replacement__:
332 switch((redex ? redex->tag : 0)) {
333 case 0: { s__ = 0;} break;
334 case Int: {
335 int s0__;
336 s0__ = 0; // int = _0->u.number
337 s__ = 1;} break;
338 case Ident: {
339 int s0__;
340 labeler(redex->u.ident, s0__, r__);
341 s__ = 0;} break;
342 case Add: {
343 int s0__;
344 int s1__;
345 labeler(redex->u.children.l, s0__, r__);
346 labeler(redex->u.children.r, s1__, r__);
347 s__ = _T_3co_X1_theta_3[_T_3co_X1_mu_3_0[s0__]][_T_3co_X1_mu_3_1[s1__]]; } break;
348 case Sub: {
349 int s0__;
350 int s1__;
351 labeler(redex->u.children.l, s0__, r__);
352 labeler(redex->u.children.r, s1__, r__);
353 s__ = _T_3co_X1_theta_4[_T_3co_X1_mu_4_0[s0__]][_T_3co_X1_mu_4_1[s1__]]; } break;
354 case Mul: {
355 int s0__;
356 int s1__;
357 labeler(redex->u.children.l, s0__, r__);
358 labeler(redex->u.children.r, s1__, r__);
359 s__ = _T_3co_X1_theta_5[_T_3co_X1_mu_5_0[s0__]][_T_3co_X1_mu_5_1[s1__]]; } break;
360 case Div: {
361 int s0__;
362 int s1__;
363 labeler(redex->u.children.l, s0__, r__);
364 labeler(redex->u.children.r, s1__, r__);
365 s__ = _T_3co_X1_theta_6[_T_3co_X1_mu_6_0[s0__]][_T_3co_X1_mu_6_1[s1__]]; } break;
366 default: {
367 int s0__;
368 int s1__;
369 labeler(redex->u.children.l,s0__,r__);
370 labeler(redex->u.children.r,s1__,r__);
371 s__ = 0;} break;
373 switch (s__) {
374 case 5: {
375 #line 91 "T3.pcc"
376 { redex = DEBUG__T_3co_X1(INT((redex->u.children.l->u.number / redex->u.children.r->u.number)),redex,_T_3co_X1_file_name,91,"DIV (INT i, INT j): ...");
377 r__ = 1; goto replacement__; }
378 #line 92 "T3.pcc"
379 } break;
380 case 4: {
381 #line 90 "T3.pcc"
382 { redex = DEBUG__T_3co_X1(INT((redex->u.children.l->u.number * redex->u.children.r->u.number)),redex,_T_3co_X1_file_name,90,"MUL (INT i, INT j): ...");
383 r__ = 1; goto replacement__; }
384 #line 91 "T3.pcc"
385 } break;
386 case 3: {
387 #line 89 "T3.pcc"
388 { redex = DEBUG__T_3co_X1(INT((redex->u.children.l->u.number - redex->u.children.r->u.number)),redex,_T_3co_X1_file_name,89,"SUB (INT i, INT j): ...");
389 r__ = 1; goto replacement__; }
390 #line 90 "T3.pcc"
391 } break;
392 case 2: {
393 #line 88 "T3.pcc"
394 { redex = DEBUG__T_3co_X1(INT((redex->u.children.l->u.number + redex->u.children.r->u.number)),redex,_T_3co_X1_file_name,88,"ADD (INT i, INT j): ...");
395 r__ = 1; goto replacement__; }
396 #line 89 "T3.pcc"
397 } break;
403 ------------------------------- Statistics -------------------------------
404 Merge matching rules = yes
405 Number of DFA nodes merged = 11
406 Number of ifs generated = 1
407 Number of switches generated = 4
408 Number of labels = 1
409 Number of gotos = 8
410 Adaptive matching = disabled
411 Fast string matching = disabled
412 Inline downcasts = disabled
413 --------------------------------------------------------------------------