BEU Question paper compiler design solution 2022

a) Which of the following derivations does a top-down parser use while parsing an input string? The input is assumed to be scanned in left to right order.

(i) Leftmost derivation
(ii) Leftmost derivation traced out in reverse
(iii) Rightmost derivation
(iv) Rightmost derivation traced out in reverse

(b) What is the maximum number of reducemoves that can be taken by a bottom-upparser for a grammar with no epsilon-and unit-production (i.e., of type A->and A->a) to parse a string with ntokens?

(i) n/2
(ii)n – 1
(iii) 2n – 1
(iv) 2 ^ n

(c) In a bottom-up evaluation of a syntaxdirected definition, inherited attributescan

(i) always be evaluated
(ii) be evaluated only if the definitionis L-attributed
(iii) be evaluated only if the definitionhas synthesized attributes
(iv) never be evaluated

(d) Consider the grammar shown below:

S -> CC

C -> cC / d

The grammar is

(i) LL(1)
(ii) SLR(1) but not LL(1)
(iii) LALR(1) but not SLR(1)
(iv) LR(1) but not LALR(1)

(e) The lexical analyzer takesand produces a stream ofoutput.as inputas

(i) source program, tokens
(ii) token, source program
(iii) Either of the two
(iv) None of the above

(f) In a compiler, when is the keyboards ofa language are recognized?

(i) During the lexical analysis of aprogram
(ii) During parsing of the program
(iii) During the code generation
(iv) During the data flow analysis

(g) How many tokens are there in thefollowing C statement?printf l “j=\%d, & j =\%x^ prime prime , j, & j)

(i) 4
(ii) 5
(iii) 9
(iv) 10

(h) Given the following expression grammar:

E E FIF+EF FF-Flid Which of the following is true?

(i) has higher precedence than +
(ii) – has higher precedence than
(ii) + and -have same precedence
(iv) + has higher precedence than

(i) Shift reduce parsers are

(i) top-down parser
(ii) bottom-up parser
(iii) may be top-down or bottom-up
(iv) None of the above

ALL in one pdf BEU PYQ solution is provided below

2. (a) Write a lexical analyzer program to identify strings, sequences, comments, reserved words and identifiers.

(b) Explain about the criterions of code optimization as sources machine dependent and independent types.

3. (a) Construct the non-recursive predictive parse table for the given grammar and check the acceptance of input string “abfcg”: S→A, AaB/Ad, B→ bBC/f, C→ cg

(b) What is the relationship with lexical analyzer, regular expressions and transition diagram? Give an example

4. (a) Explain the type system in type checker. Write the syntax directed definition for type checker.

(b) What is activation record? Explain its usage in stack allocation strategy. How is it different from heap allocation?

  1. (a) Draw and explain the runtime memory organization static storage allocation strategy with pros and cons.

(b) Differentiate inherited and synthesized attributes with an example.

  1. (a) Define dataflow analysis. List out the procedures to analyze the data flow of structured programs.

(b) Draw a block diagram of phases of a compiler and indicate the main functions of each phase.

  1. (a) What is intermediate code? Translate the expression

(a+b)/(c+d) (a+b/c)-d into quadruples, triples and indirect triples.

(b) Explain reducible and non-reducible flow graphs with an example each.

  1. (a) What is machine-dependent optimiza- tion? Explain how peephole techniques function in this.

(b) Explain how type checking and error reporting are performed in compiler. Draw syntax tree and DAG for the statement a=(a+b+c)^(b+c)*b+c

  1. Explain the following with suitable example:

(a) Function preserving optimization techniques

(b) Reference counting garbage collectors

(c) Elimination of loop invariant variable

(d) Strength reduction

CLICK HERE TO JOIN WHATSAPP GROUP

Compiler Design 2022 BEU QUESTION SOLUTION ==>> Download

Compiler Design 2022 Question paper ==>> Download

BEU CSE SOLUTION = Computer Network 2022 Computer Science BEU question paper solution

Leave a Comment