Consider the following grammar, where P is the starting symbol,
n stands for decimal numbers in the input, id stands for
identifier, i stands for the keyword if , e stands
for the keyword else , and +, *, (, ), {, }, and = are operators with
usual meanings:
P | -> | { S } |
S | -> | E | E ; S | I |
E | -> | E + T | T | id = E |
T | -> | T * F | F |
F | -> | n | ( E ) |
I | -> | i ( E ) { S } | i ( E ) { S } e { S } |
Write a program using bison that accepts input according to the above
grammar and produces equivalent steps in an assembly language. The assembly
language has the following statements:
MOV X, Y
| ; X = Y
| ADD X, Y | ; X += Y
| MULT X, Y | ; X *= Y
| CMP X, Y | ; Update ME flags as X-Y
| | ; E-flag = (X == Y); M-flag = (X < Y)
| JMP C, Y | ; Goto X, if C is satisfied;
C is of 4 bits: mMeE
| | ; if m = 1, test (M == M-flag), else ignore M-flag;
| | ; if e = 1, test (E == E-flag); else ignore E-flag;
|
Utpal Sharma
Course instructor
26-09-06
|