SDD1Grammar (G1) Semantic Rules $D \rightarrow T\ V$ $D.type = T.type$
$V.type = T.type$$T \rightarrow int$ $T.type = int$ $T \rightarrow float$ $T.type = float$ $V \rightarrow V_1\ id$ $V_1.type = V.type$
$put(id.entry, V.type)$$V \rightarrow id$ $put(id.entry, V.type)$
SDD2Grammar (G2) Semantic Rules $D \rightarrow D_1\ id$ $D.type = D_1.type$
$put(id.entry, D_1.type)$$D \rightarrow T\ id$ $D.type = T.type$
$put(id.entry, T.type)$$T \rightarrow int$ $T.type = int$ $T \rightarrow float$ $T.type = float$
$D$ is the start symbol, and $int$, $float$ and $id$ are the three terminals. The non-terminal $V_1$ is the same as $V$ and the non-terminal $D_1$ is the same as $D$. Here, the subscript is used to differentiate the grammar symbols on the two sides of a production. The function $put$ 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?
This solution examines two syntax-directed definitions (SDD1 and SDD2) to determine the validity of statements regarding their languages and attribute computations.
Grammar G1 (associated with SDD1) has the following structure:
Grammar G1 generates strings starting with a type ($int$ or $float$) followed by one or more identifiers. For instance, $int a$ or $float x y$ are valid strings in language P.
Grammar G2 (associated with SDD2) has the following structure:
Grammar G2 also generates strings starting with a type ($int$ or $float$) followed by one or more identifiers. For instance, $int a$ or $float x y$ are valid strings in language Q.
Since both grammars generate the same set of strings (a type followed by one or more identifiers), languages P and Q are identical. Thus, Statement A is true.
Let's analyze the attributes in SDD2:
All attributes computed and used ($T.type$, $D.type$, and the type argument for $put$) are synthesized. An S-attributed definition requires all attributes to be synthesized. Therefore, SDD2 is S-attributed. Thus, Statement B is true.
Analyzing attributes in SDD1:
SDD1 contains synthesized attributes ($D.type$, $T.type$) and uses attributes ($V.type$) in a way consistent with L-attributed definitions. However, because it possesses synthesized attributes, it does not contain *only* inherited attributes. Thus, Statement C is false.
We compare the $put$ operations in both SDDs:
In SDD1:
In SDD2:
Both SDD1 and SDD2 correctly associate the declared type ($int$ or $float$) with each identifier via the $put$ function. Therefore, the same entries are added to the symbol table. Thus, Statement D is true.
COMPILER is used to?
Which of the following statement(s) are correct?
A. Syntax Directed Translation can be applied in Type Checking.
B. Syntax Directed Translation can be used in 3-address code generation.
C. Syntax Directed Translation can be used in construction of syntax tree.
D. Syntax Directed Translation can be used to recognize valid tokens.
Choose the most appropriate answer from the options given below:
Which of the following tasks could be attained using syntax trees in compiler design ?
(A) Type Checking
(B) Code Generation
(C) Code Optimization
(D) Error Handling
Choose the correct answer from the options given below :