next up previous
Next: Exercise 2. Up: Quiz7 Previous: Guidelines.

Exercise 1.

We consider the following translation scheme.
S $ \longmapsto$ A {C.i := A.sC
S $ \longmapsto$ AB {C.i := A.sC
A $ \longmapsto$ int {A.s := int.val}
B $ \longmapsto$ id {}
C $ \longmapsto$ int {C.s := C.i + int.val}
where S, A, B, C are non-terminals, int and id are terminals, C.i is an inherited attribute, A.s and int.val are synthesized attributes. Write a YACC program for this translation scheme.

Answer 1  
S     : A C 
      | A B M C
      ;
A     : TOK_INT {$$ = $1; }
      ;
B     : TOK_ID
      ;
M     :   /* empty */  {$$ = $-2; }
      ;
C     :  TOK_INT {$$ = $-1 + $1; } 
      ;


next up previous
Next: Exercise 2. Up: Quiz7 Previous: Guidelines.
Marc Moreno Maza
2004-12-02