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:
A, B and C
A syntax-directed translation (SDT) attaches semantic rules or actions to grammar productions; they are evaluated as the parser recognizes the productions, computing attributes of grammar symbols. Aho–Ullman list its main uses as type checking, intermediate (three-address) code generation and syntax-tree construction.
A — Correct. Type expressions are synthesized and checked through attributes such as E.type attached to expression productions.
B — Correct. Attributes such as E.addr and E.code with gen() actions emit three-address code during parsing.
C — Correct. Actions such as E.node = new Node('+', E1.node, T.node) build the syntax tree bottom-up.
D — Not an SDT application. Valid tokens are recognized by the lexical analyser using regular expressions and finite automata before parsing starts; SDT rules operate on tokens that have already been recognized and are attached to context-free productions, not to token patterns.
Every choice that includes D credits SDT with the scanner's job, and choices that drop A or B omit genuine applications, leaving only the set of A, B and C.
A, B and C option is correct.
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 :
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 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 :