GATE CS 2021,Set-1,Q26:Consider the following grammar (that admits a series of declarations, follow

Опубликовано: 07 Апрель 2026
на канале: Monalisa CS
2,575
89

GATE CS 2021,Set-1,Q26: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:
P→ D*E*
D→ int ID{record that ID.lexeme is of type int}
D→ bool ID{record that ID.lexeme is of type bool}
E→ E1+E2{check that E1.type=E2.type=int;set E.type :=int}
E→ !E1{check that E1.type=bool; set E.type:=bool}
E→ ID{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 correctly type-check any syntactically correct program
(B) The actions can be used to type-check syntactically correct integer variable declarations and integer expressions
(C) The actions can be used to type-check syntactically correct boolean variable declarations and boolean expressions.
(D) The actions will lead to an infinite loop
Ans :(B) The actions can be used to type-check syntactically correct integer variable declarations and integer expressions
----------------------------------------------
Subscribe my channel for more updates    / monalisacs  
----------------------------------------------------------
Join Telegram GATE CS study group: https://t.me/MonalisaCS
----------------------------------------------------------------
Compiler Design Lectures :   • Ch 1.1:Language Processing System |CD Lect...  
----------------------------------------------------------------
Compiler Design PYQ :   • Ch 1.1:Language Processing System |CD Lect...  
----------------------------------------------------------------------
Theory Of Computation Lectures    • Video  
-------------------------------------------------------------------
TOC GATE PYQ:    • GATE CS 2010,Q39:Let L={w ∈ (0 + 1)* | w h...  
-------------------------------------------------------------------
Data Structure Lecture:    • Data Structure Syllabus for GATE  
---------------------------------------------------------------------
Data Structure PYQ:    • Data Structure Syllabus for GATE  
-----------------------------------------------------------------------
#GATE_2021#GATE_CSE#Compiler_Design_PYQ