wiz-icon
MyQuestionIcon
MyQuestionIcon
2
You visited us 2 times! Enjoying our articles? Unlock Full Access!
Question

Consider the following grammar (that admits a series of declarations, followed by expressions) and the associated syntax directed translation (SDT) actions, given as pseudo-code:

PD E

D int ID {record that ID.|exeme is of type int}

D bool ID {record that ID.|exeme is of type bool}

EE1+E2 {check thatE1. type=int; set E.type:=int}

E!E1 {check thatE1. type = bool; set E. type: = bool}

EID {set E.type: = int}

With respect to the above grammar, which one of the following choices is correct?

A
The actions can be used to type-check syntactically correct integer variable declarations and integer expressions.
Right on! Give the BNAT exam to get a 100% scholarship for BYJUS courses
B
The actions will lead to an infinite loop.
No worries! We‘ve got your back. Try BYJU‘S free classes today!
C
The actions can be used to type-check syntactically correct boolean variable declarations and boolean expressions.
No worries! We‘ve got your back. Try BYJU‘S free classes today!
D
The actions can be used to correctly type-check any syntactically correct program.
No worries! We‘ve got your back. Try BYJU‘S free classes today!
Open in App
Solution

The correct option is A The actions can be used to type-check syntactically correct integer variable declarations and integer expressions.
1. PD E
2. D int ID {record that ID. lexeme is of type int}
3. D bool ID {record that ID. lexeme is of type bool}
4. EE1+E2 {check thatE1.type=E2.type=int; set E.type = int}
5. E!E1 {check that E1. type = bool;set E.type = bool}
6. EID {set E. type = int}

Rules 2 and 3 are used for entry into the symbol table. Rule 4 is used for type checking of the integer expression. But, in rule 6 only int type is set.

Hence answer is option (a).

flag
Suggest Corrections
thumbs-up
0
similar_icon
Similar questions
View More
Join BYJU'S Learning Program
similar_icon
Related Videos
thumbnail
lock
4 Sides and 1 Diagonal
MATHEMATICS
Watch in App
Join BYJU'S Learning Program
CrossIcon