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 :
(A), (B), (C) Only
A syntax tree (abstract syntax tree) is the condensed parse tree produced at the end of syntax analysis. Each interior node is an operator and its children are operands, and it is the main data structure passed to the later phases of the compiler.
(A) Type checking is done on the syntax tree: the semantic analyser walks it, attaches types to nodes and checks that operators receive compatible operands.
(B) Code generation can be driven directly by the syntax tree: a post-order traversal emits three-address code or target instructions for each node.
(C) Code optimisation uses it: constant folding, common sub-expression detection (turning the tree into a DAG) and algebraic simplification are performed on tree nodes.
(D) Error handling is not a task the syntax tree is built for; syntax errors are detected and recovered from by the parser while the tree is still being constructed, so this is not counted among the tasks achieved using the tree.
So type checking, code generation and code optimisation are the tasks; choices including error handling or dropping type checking are wrong.
(A), (B), (C) Only option is correct.
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:
COMPILER is used to?
| Grammar (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)$ |
| Grammar (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$ |
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: