in Compiler Design edited by
9,543 views
39 votes
39 votes

Match the following according to input (from the left column) to the compiler phase (in the right column) that processes it:
$$\begin{array}{|l|l|}\hline \text{P. Syntax tree}  &  \text{i. Code generator} \\\hline  \text{Q. Character stream} & \text{ii. Syntax analyser} \\\hline  \text{R. Intermediate representation} & \text{iii. Semantic analyser} \\\hline  \text{S. Token stream} & \text{iv. Lexical analyser} \\\hline \end{array}$$

  1. $\text{P-ii; Q-iii; R-iv; S-i}$
  2. $\text{P-ii; Q-i; R-iii; S-iv}$
  3. $\text{P-iii; Q-iv; R-i; S-ii}$
  4. $\text{P-i; Q-iv; R-ii; S-iii}$
in Compiler Design edited by
by
9.5k views

5 Answers

38 votes
38 votes
Best answer

Correct Option: C

  • Q - iv because Character stream is given as input to lexical analyser
  • P - iii Syntax tree is given as input to semantic analyser
  • R - i Intermediate code given as input to code generator
  • S - ii  Token stream  given as input to syntax analyser
edited by

4 Comments

Intermediate code given as input to code generator.

Isn’t this is code optimiser??

0
0
Optimized intermediate code is given input to Target code generation.
1
1
Yup, that can also be true. Thanks for telling. :)
0
0
15 votes
15 votes
Answer will be C

Because

1. Syntax tree will be produced by syntax analysis phase and it will be given to semantic analyser

2. Character stream will be taken from source code and given to lexical analyser

3. Intermediate code will be produced by semantic analyser and give to code generator

4. Token stream will be produced by lexical analyser and given to syntax analyser

Hope you got the point and you please refer dragon book I.e. compilers book by Ullman

2 Comments

Is Intermediate code generated by semantic analyser ?

There is Intermediate code generator for generating intermediate code right
0
0

 you are correct.

1
1
6 votes
6 votes
(C)

Step1: Lexer uses character stream to create the tokens
Step2: Syntax analyzer takes the tokens to create syntax tree.
Step3: Semantic analyzer is the next phase of the parser which takes syntax tree as input
Step4: Code generator takes the final parse tree and generates the intermediate code.

The matching is done as per the input for each stage.
edited by

1 comment

Detailed and specific answer! :D
0
0
4 votes
4 votes
Answer is C

Character stream - LA
Token Strean - Syntax Analyzer

Syntax tree - Semantic Analyzer

Intermediate representation - Code Generator
by
Answer:

Related questions