in Compiler Design
431 views
0 votes
0 votes
  1. Consider the given  grammar of syntax directed translation scheme and answer the following: (2 MARKS)                                                                                          

X → X1/Y | Y

Y → Z – Y1 | Z

Z → 2 | 5 | 7 | 8

    1. Write down the semantic rules of the above grammar productions
    2. Draw the annotated parse tree for  7-8-5/2
in Compiler Design
431 views

1 Answer

2 votes
2 votes

​​​​​​a.

$X → X1 \ / \  Y $   { X.$val$ = X1.$val$ / Y.$val$ }

         |  $Y$  { X.$val$ = Y.$val$ }

 

$Y → Z \ – \ Y1 $ { Y.$val$ = Z.$val$ – Y.$val$ }

         | Z  { Y.$val$ = Z.$val$ }

 

$Z → 2 \ | \ 5 \ | \ 7 \ | \ 8 $ { Z.$val$ = digit.$lexval$ }

 

 

b. $ Annotated \ Parse \ Tree :$

 

 

Remember here, “$-$” has higher precedence than “$/$”

and “$-$” is Right Associative while “$/$” is Left Associative

 

edited by

Related questions