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
12 // Test the view mechanism
16 #include <istd::ostream.h>
18 enum exp_tag
{ Int
= 1, Ident
, Add
, Sub
, Mul
, Div
};
25 struct { struct exp
* l
, * r
; } children
;
29 typedef struct exp
* Exp
;
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
; }
38 { Exp e
= new exp
; e
->tag
= Add
; e
->u
.children
.l
= a
; e
->u
.children
.r
= b
;
43 { Exp e
= new exp
; e
->tag
= Sub
; e
->u
.children
.l
= a
; e
->u
.children
.r
= b
;
48 { Exp e
= new exp
; e
->tag
= Mul
; e
->u
.children
.l
= a
; e
->u
.children
.r
= b
;
53 { Exp e
= new exp
; e
->tag
= Div
; e
->u
.children
.l
= a
; e
->u
.children
.r
= b
;
63 std::ostream
& operator << (std::ostream
& s
, const Exp
& e
)
68 switch ((e
? e
->tag
: 0)) {
76 return s
<< e
->u
.number
;
81 return s
<< e
->u
.ident
;
86 return s
<< '(' << e
->u
.children
.l
<< " + " << e
->u
.children
.r
<< ')';
91 return s
<< '(' << e
->u
.children
.l
<< " - " << e
->u
.children
.r
<< ')';
96 return s
<< '(' << e
->u
.children
.l
<< " * " << e
->u
.children
.r
<< ')';
101 return s
<< '(' << e
->u
.children
.l
<< " / " << e
->u
.children
.r
<< ')';
112 int eval(const Exp
& e
)
117 switch ((e
? e
->tag
: 0)) {
135 return eval(e
->u
.children
.l
) + eval(e
->u
.children
.r
);
140 return eval(e
->u
.children
.l
) - eval(e
->u
.children
.r
);
145 return eval(e
->u
.children
.l
) * eval(e
->u
.children
.r
);
149 switch ((e
->u
.children
.r
? e
->u
.children
.r
->tag
: 0)) {
153 return eval(e
->u
.children
.l
) / eval(e
->u
.children
.r
);
157 switch (e
->u
.children
.r
->u
.number
) {
161 (e
->u
.children
.l
!= NONE
)
166 cerr
<< "Division by zero\n"; return 0;
171 default: { goto L1
; }
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;
190 void simplify(Exp
& e
)
195 extern void _T_3co_X1_rewrite(Exp
& );
196 _T_3co_X1_rewrite(e
);
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
;
207 cout
<< "Simplified = " << e
<< endl
;
208 assert(eval(e
) == 15);
220 class _T_3co_X1
: public BURS
{
222 _T_3co_X1(const _T_3co_X1
&); // no copy constructor
223 void operator = (const _T_3co_X1
&); // no assignment
225 struct _T_3co_X1_StateRec
* stack__
, * stack_top__
;
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); }
233 inline _T_3co_X1() {}
235 void _T_3co_X1_rewrite(Exp
& _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
248 static const char * _T_3co_X1_file_name
= "T3.pcc";
251 static const TreeTables::State _T_3co_X1_theta_3
[2][2] = {
257 static const TreeTables::State _T_3co_X1_theta_4
[2][2] = {
263 static const TreeTables::State _T_3co_X1_theta_5
[2][2] = {
269 static const TreeTables::State _T_3co_X1_theta_6
[2][2] = {
275 static const TreeTables::State _T_3co_X1_mu_3_0
[6] = {
280 static const TreeTables::State _T_3co_X1_mu_3_1
[6] = {
285 static const TreeTables::State _T_3co_X1_mu_4_0
[6] = {
290 static const TreeTables::State _T_3co_X1_mu_4_1
[6] = {
295 static const TreeTables::State _T_3co_X1_mu_5_0
[6] = {
300 static const TreeTables::State _T_3co_X1_mu_5_1
[6] = {
305 static const TreeTables::State _T_3co_X1_mu_6_0
[6] = {
310 static const TreeTables::State _T_3co_X1_mu_6_1
[6] = {
315 inline void _T_3co_X1::labeler(char const * redex
,int& s__
,int)
322 inline void _T_3co_X1::labeler(Quark redex
,int& s__
,int)
329 void _T_3co_X1::labeler (Exp
& redex
, int& s__
, int r__
)
332 switch((redex
? redex
->tag
: 0)) {
333 case 0: { s__
= 0;} break;
336 s0__
= 0; // int = _0->u.number
340 labeler(redex
->u
.ident
, s0__
, r__
);
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;
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;
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;
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;
369 labeler(redex
->u
.children
.l
,s0__
,r__
);
370 labeler(redex
->u
.children
.r
,s1__
,r__
);
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__
; }
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__
; }
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__
; }
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__
; }
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
410 Adaptive matching = disabled
411 Fast string matching = disabled
412 Inline downcasts = disabled
413 --------------------------------------------------------------------------