cs4032_2026T2_Q2_NA.pdf
Compiler Design · Quiz 2 · May 2026
← Course papers · Start practice / exam
Questions and published explanations below are available without starting a test. Some questions may not have a published solution yet.
Question 2 MSQ · 2.0 marks
Consider the regular language
[[IMAGE:2d7550c87a5ff5e1_2_2]]
over the alphabet
[[IMAGE:2d7550c87a5ff5e1_2_3]]
Which of the following strings belong to [[IMAGE:2d7550c87a5ff5e1_2_4]] ? (Select all that apply.)



[[IMAGE:2d7550c87a5ff5e1_2_5]]

[[IMAGE:2d7550c87a5ff5e1_2_6]]

[[IMAGE:2d7550c87a5ff5e1_2_7]]

[[IMAGE:2d7550c87a5ff5e1_2_8]]

[[IMAGE:2d7550c87a5ff5e1_2_9]]

A published solution is not available for this question yet.
Question 3 MCQ · 3.0 marks
A lexical analyzer uses the following rules.
[[IMAGE:2d7550c87a5ff5e1_3_10]]
The keyword rule has **higher priority** than the identifier rule.
Input
[[IMAGE:2d7550c87a5ff5e1_3_11]]
Which of the following gives the correct number of **Keyword**, **Identifier**, and **Number** tokens?


(3,1,0)
(2,2,0)
(3,2,0)
(2,1,1)
A published solution is not available for this question yet.
Question 4 MCQ · 3.0 marks
Convert the following infix expression to postfix notation:
[[IMAGE:2d7550c87a5ff5e1_3_12]]
Which one of the following is the correct postfix expression?

[[IMAGE:2d7550c87a5ff5e1_3_13]]

[[IMAGE:2d7550c87a5ff5e1_3_14]]

[[IMAGE:2d7550c87a5ff5e1_3_15]]

[[IMAGE:2d7550c87a5ff5e1_4_16]]

A published solution is not available for this question yet.
Question 5 MCQ · 3.0 marks
A parser generator performs the following steps:
1. Construct the canonical LR(1) collection of item sets.
2. Merge all states having the same LR(0) core.
3. Construct the ACTION and GOTO tables from the merged automaton.
Which parsing technique is obtained after these steps?
LR(0)
Canonical LR(1)
LALR(1)
SLR(1)
A published solution is not available for this question yet.
Question 6 MCQ · 3.0 marks
Consider the grammar
[[IMAGE:2d7550c87a5ff5e1_4_17]]
The initial state is
[[IMAGE:2d7550c87a5ff5e1_4_18]]
Which of the following is GOTO(I0, b) ?


[[IMAGE:2d7550c87a5ff5e1_4_19]]

[[IMAGE:2d7550c87a5ff5e1_4_20]]

[[IMAGE:2d7550c87a5ff5e1_4_21]]

[[IMAGE:2d7550c87a5ff5e1_5_22]]

A published solution is not available for this question yet.
Question 7 MCQ · 3.0 marks
Consider the grammar:
[[IMAGE:2d7550c87a5ff5e1_5_23]]
A shift-reduce parser is parsing the input:
[[IMAGE:2d7550c87a5ff5e1_5_24]]
The parser has already performed the following actions:
[[IMAGE:2d7550c87a5ff5e1_5_25]]
What should be the **next action**?



Shift [[IMAGE:2d7550c87a5ff5e1_5_26]]

Reduce [[IMAGE:2d7550c87a5ff5e1_5_27]]

Reduce [[IMAGE:2d7550c87a5ff5e1_5_28]]

Accept
A published solution is not available for this question yet.
Question 8 MCQ · 3.0 marks
Consider the production
[[IMAGE:2d7550c87a5ff5e1_6_29]]
The semantic rules are
[[IMAGE:2d7550c87a5ff5e1_6_30]]
Which of the following is the **minimum valid attribute evaluation sequence**?


[[IMAGE:2d7550c87a5ff5e1_6_31]]

[[IMAGE:2d7550c87a5ff5e1_6_32]]

[[IMAGE:2d7550c87a5ff5e1_6_33]]

[[IMAGE:2d7550c87a5ff5e1_6_34]]

A published solution is not available for this question yet.
Question 9 MCQ · 3.0 marks
Consider the following overloaded functions.
[[IMAGE:2d7550c87a5ff5e1_6_35]]
The compiler evaluates the following function calls.
[[IMAGE:2d7550c87a5ff5e1_6_36]]
Which **one** of the following function calls requires **integer promotion** before overload resolution
selects the best match?


[[IMAGE:2d7550c87a5ff5e1_7_37]]

[[IMAGE:2d7550c87a5ff5e1_7_38]]

[[IMAGE:2d7550c87a5ff5e1_7_39]]

[[IMAGE:2d7550c87a5ff5e1_7_40]]

A published solution is not available for this question yet.
Question 10 MCQ · 3.0 marks
An embedded SDT contains the production
[[IMAGE:2d7550c87a5ff5e1_7_41]]
To convert it into an equivalent postfix SDT while preserving the execution point of the action [[IMAGE:2d7550c87a5ff5e1_7_42]]
, which of the following transformations is correct?


[[IMAGE:2d7550c87a5ff5e1_7_43]]

[[IMAGE:2d7550c87a5ff5e1_7_44]]

[[IMAGE:2d7550c87a5ff5e1_7_45]]

[[IMAGE:2d7550c87a5ff5e1_8_46]]

A published solution is not available for this question yet.
Question 11 NAT · 3.0 marks
Consider the alphabet
[[IMAGE:2d7550c87a5ff5e1_8_47]]
[[IMAGE:2d7550c87a5ff5e1_8_48]]


A published solution is not available for this question yet.
Question 12 NAT · 3.0 marks
Consider the following operator grammar:
[[IMAGE:2d7550c87a5ff5e1_8_49]]
An operator-precedence parser is used to parse the expression
[[IMAGE:2d7550c87a5ff5e1_9_50]]
using the following precedence and associativity rules:
• [[IMAGE:2d7550c87a5ff5e1_9_51]] has higher precedence than [[IMAGE:2d7550c87a5ff5e1_9_52]] .
• Both operators are left associative .
Ignoring the end marker [[IMAGE:2d7550c87a5ff5e1_9_53]] , how many reduce operations are performed by the parser while
parsing the expression?





A published solution is not available for this question yet.
Question 13 MSQ · 4.0 marks
Consider the grammar
[[IMAGE:2d7550c87a5ff5e1_9_54]]
and the following recursive descent parser.
[[IMAGE:2d7550c87a5ff5e1_10_55]]
Assume that:
• Parsing starts by calling [[IMAGE:2d7550c87a5ff5e1_10_56]] .
• [[IMAGE:2d7550c87a5ff5e1_10_57]] consumes the current input symbol only if it matches the expected symbol.
• Any call that reports an error (i.e., executes [[IMAGE:2d7550c87a5ff5e1_10_58]] ) immediately causes the parse to
fail, even if the final lookahead is [[IMAGE:2d7550c87a5ff5e1_10_59]] .
• After [[IMAGE:2d7550c87a5ff5e1_10_60]] returns, the input is accepted only if no error has been reported and the current
lookahead is [[IMAGE:2d7550c87a5ff5e1_10_61]] .
Which of the following input strings is/are accepted?








[[IMAGE:2d7550c87a5ff5e1_10_62]]

[[IMAGE:2d7550c87a5ff5e1_11_63]]

[[IMAGE:2d7550c87a5ff5e1_11_64]]

[[IMAGE:2d7550c87a5ff5e1_11_65]]

A published solution is not available for this question yet.
Question 14 MCQ · 2.0 marks
A context-free grammar contains the productions
[[IMAGE:2d7550c87a5ff5e1_11_66]]
Which language is generated?

[[IMAGE:2d7550c87a5ff5e1_11_67]]

[[IMAGE:2d7550c87a5ff5e1_11_68]]

All strings over [[IMAGE:2d7550c87a5ff5e1_11_69]]

[[IMAGE:2d7550c87a5ff5e1_11_70]]

A published solution is not available for this question yet.
Question 15 MCQ · 2.0 marks
Consider the following statements about SLR(1), Canonical LR(1), and LALR(1) parsers.
1. Every SLR(1) grammar is also an LALR(1) grammar.
2. Every LALR(1) grammar is also an LR(1) grammar.
3. Every LR(1) grammar is also an LALR(1) grammar.
Which of the following is correct?
Only 1 and 2
Only 2 and 3
Only 1 and 3
1, 2 and 3
A published solution is not available for this question yet.
Question 16 MCQ · 4.0 marks
Consider the grammar.
[[IMAGE:2d7550c87a5ff5e1_12_71]]
Which of the following correctly gives **FIRST(S)** and **FOLLOW(X)**?

FIRST(S) = {p, q, r, s}
FOLLOW(X) = {r, s, $}
FIRST(S) = {p, q, r, s, ε}
FOLLOW(X) = {r, s}
FIRST(S) = {p, q, s}
FOLLOW(X) = {$}
FIRST(S) = {p, q, r, s}
FOLLOW(X) = {r, s}
A published solution is not available for this question yet.
Question 17 MSQ · 3.0 marks
A student wants the exponentiation operator ( [[IMAGE:2d7550c87a5ff5e1_12_72]] ) to have higher precedence than multiplication.
They write the following Bison declarations.
[[IMAGE:2d7550c87a5ff5e1_13_73]]
For the expression
[[IMAGE:2d7550c87a5ff5e1_13_74]]
which of the following statements are correct? (Select all that apply.)



The expression is parsed as [[IMAGE:2d7550c87a5ff5e1_13_75]] .

The expression is parsed as [[IMAGE:2d7550c87a5ff5e1_13_76]] .

The [[IMAGE:2d7550c87a5ff5e1_13_77]] declaration makes [[IMAGE:2d7550c87a5ff5e1_13_78]] right-associative.


The value of the expression is [[IMAGE:2d7550c87a5ff5e1_13_79]] .

A published solution is not available for this question yet.
Question 18 MSQ · 3.0 marks
Consider the SDD.
[[IMAGE:2d7550c87a5ff5e1_13_80]]
Which of the following statements are correct?

[[IMAGE:2d7550c87a5ff5e1_14_81]] is a synthesized attribute.

[[IMAGE:2d7550c87a5ff5e1_14_82]] is typically provided by the lexical analyzer.

This SDD requires inherited attributes for expression evaluation.
[[IMAGE:2d7550c87a5ff5e1_14_83]] is inherited because it depends on [[IMAGE:2d7550c87a5ff5e1_14_84]] .


The attribute evaluation naturally proceeds from the leaves toward the root.
A published solution is not available for this question yet.