Consider the following two syntax-directed definitions SDD1 and SDD2 for type
declarations.
π· is the start symbol, and πππ‘, πππππ‘ and ππ are the three terminals. The non-terminal
π1 is the same as π and the non-terminal π·1 is the same as π·. Here, the subscript is
used to differentiate the grammar symbols on the two sides of a production. The
function ππ’π‘ updates the symbol table with the type information for an identifier.
Let P and Q be the languages specified by grammars G1 and G2, respectively.
Which of the following statements is/are true?
SDD1
Grammar
(G1)
Semantic Rules
π· βπ π
π·. π‘π¦ππ = π. π‘π¦ππ
π. π‘π¦ππ = π. π‘π¦ππ
π β πππ‘
π. π‘π¦ππ = πππ‘
π β πππππ‘
π. π‘π¦ππ = πππππ‘
πβπ1 ππ
π1. π‘π¦ππ= π. π‘π¦ππ
ππ’π‘(ππ. πππ‘ππ¦, π. π‘π¦ππ)
π β ππ
ππ’π‘(ππ. πππ‘ππ¦, π. π‘π¦ππ)
SDD2
Grammar
(G2)
Semantic Rules
π·βπ·1 ππ
π·. π‘π¦ππ= π·1. π‘π¦ππ
ππ’π‘(ππ. πππ‘ππ¦, π·1. π‘π¦ππ)
π· β π ππ
π·. π‘π¦ππ = π. π‘π¦ππ
ππ’π‘(ππ. πππ‘ππ¦, π. π‘π¦ππ)
π βπππ‘
π. π‘π¦ππ = πππ‘
π β πππππ‘
π. π‘π¦ππ = πππππ‘
A quicker way to settle all four options is to run a concrete declaration, say \(int\ a\ b\ c\), through both grammars and track what each SDD actually computes, rather than staring at the rules in the abstract.
Step 1: Same strings, same language. G1 builds the identifier list bottom-up using \(V \to V_1\ id \mid id\), so it accepts \(T\) followed by any non-empty chain of ids: first \(a\), then \(a\ b\), then \(a\ b\ c\). G2 builds the same list using \(D \to D_1\ id \mid T\ id\), again \(T\) followed by one or more ids. You cannot find a string accepted by one grammar and rejected by the other - both describe exactly 'T followed by a non-empty sequence of ids', so \(P = Q\), which confirms option (A).
Step 2: Where does the type value travel in SDD1? Compute \(T.type = int\) first, bottom-up from the terminal. At \(D \to T\ V\), \(D.type\) is synthesized from \(T\), but \(V.type\) is set equal to \(T.type\) - the value moves from a sibling into a nonterminal that will expand further down, which is exactly what makes it an inherited attribute. The recursive rule \(V \to V_1\ id\) repeats this by setting \(V_1.type = V.type\), again pushing the same value further down the tree. Since \(D.type\) and \(T.type\) are synthesized while \(V.type\) and \(V_1.type\) are inherited, SDD1 is a mixed, L-attributed scheme - not a purely inherited one. So option (C), which claims SDD1 has 'only inherited attributes', overreaches and is false.
Step 3: Where does the type value travel in SDD2? Every rule here computes a value strictly from its children: \(D.type = T.type\) or \(D.type = D_1.type\), and \(T.type\) comes straight from the terminal. No rule ever pushes a value down into an already-expanded child; everything flows upward toward the root. That is precisely the definition of an S-attributed, fully synthesized SDD, so option (B) holds.
Step 4: Does the symbol table end up the same either way? Walking through \(int\ a\ b\ c\): SDD1 fixes the type as \(int\) at the top from \(T\), threads it down through \(V\) and \(V_1\), and fires \(put(id.entry, int)\) once for each of \(a\), \(b\), \(c\). SDD2 fixes \(T.type = int\) at the base of its recursive chain and fires \(put(id.entry, int)\) once as each \(D_1\) layer reduces, again once per identifier. Either way, every identifier in the declaration ends up mapped to \(int\) in the symbol table - the propagation mechanism differs, but the resulting entries are identical, so option (D) is also true.
Putting the four checks together: options (A), (B), and (D) are correct, while (C) is incorrect.
Final answer: (A), (B), (D)
Consider the control flow graph shown. Which one of the following choices correctly lists the set of live variables at the exit point of each basic block? 
Consider the following definition of a lexical token id for an identifier in a programming language, using extended regular expressions: \[ \text{letter} \;\;\rightarrow\;\; [A\!-\!Za\!-\!z] \] \[ \text{digit} \;\;\rightarrow\;\; [0\!-\!9] \] \[ \text{id} \;\;\rightarrow\;\; \text{letter (letter | digit)}^* \] Which one of the following Non-deterministic Finite-state Automata with $\epsilon$-transitions accepts the set of valid identifiers? (A double-circle denotes a final state). 