GATE CS 2024 Set 1 — Question 37
MCQ+2 / -0.67MediumSyntax-Directed TranslationSemantic AnalysisCompiler Design
Compiler Design → Semantic Analysis → Syntax-Directed Translation
Last updated
Question
Consider the following syntax-directed definition (SDD).
Given "MMLK" as the input, which one of the following options is the CORRECT value computed by the SDD (in the attribute )?
| Production | Semantic Rules |
|---|---|
S → DHTU | |
A.
45
B.
50
C.
55
D.
65
Correct answer
(A) 45
Solution
To find the value of for the input string "MMLK", we first construct the parse tree based on the given grammar productions.1. Parsing the Input "MMLK":
The start symbol is , and the production is
We need to match the input string "MMLK" to the components .
Now we compute the values using the semantic rules.
The start symbol is , and the production is
S → DHTU.We need to match the input string "MMLK" to the components .
- Match : The prefix "MM" matches the expansion of .
- (since the next character is 'L', which belongs to )
- Match : The next character "L" matches the expansion of .
- (since the next character is 'K', and must be skipped)
- Match : There are no 'C' characters. The next character is 'K', which belongs to . Thus, must derive .
- Match : The character "K" matches .
Now we compute the values using the semantic rules.
- For :
- For :
- For :
- For :
- For :
More questions on Semantic Analysis
2024 Set 2 Q21Consider the following two sets: | Set X | Set Y | | :--- | :--- | | P. Lexical Analyzer | 1.…2024 Set 1 Q26Which of the following is/are Bottom-Up Parser(s)?2024 Set 2 Q29Which of the following statements is/are FALSE?2024 Set 1 Q38Consider the following grammar , with as the start symbol. The grammar has three…2024 Set 1 Q39Consider the following pseudo-code. [code] Which one of the following options CORRECTLY specifies…
Practice GATE CS PYQs with adaptive difficulty
Timed practice, skill tracking, and AI explanations — free to start.
Start practicing free