0% found this document useful (0 votes)
17 views3 pages

Compiler Design Important Questions

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views3 pages

Compiler Design Important Questions

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

UNIT 1 IMPORTANT QUESTIONS

1. Discuss the compilation process for the following statement. a:=b+c*100;


2. Write a LEX program to count the number of Vowels and Consonants in a given String.
3. Illustrate the importance of Cross Compiler and Boot Strapping with an example.
[Link] the types of Input buffering with an example.
[Link] in detail about Phases of Compiler with an example.
6 How Recognition of Tokens is done in Lexical Analysis?
7. Summarize the concept Language Processing System.
8. Write a LEX program to implement a simple Calculator.
9. How Specification of Tokens are different from Recognition of Tokens? Justify your answer.
10. Discuss in detail about Role of a Lexical Analyzer with a neat sketch.
11. Write a LEX program to recognize and count the number of Identifiers in a given input file.
12. Demonstrate the types of Input buffering with an example.
13. Discuss in detail about LEX tool with example.

UNIT 2 IMPORTANT QUESTIONS


1. Consider the following grammar
A->Abd | Aa | a
B->Be | b .
Eliminate left recursion from the above grammar.
[Link] Grammar
E->TE’
E->+TE’ | €
T->FT’
T’->*FT’ | €
F-> (E) | id.
Find the FIRST and FOLLOW functions for the above grammar.
[Link] Error recovery in Predictive Parsing achieved? Explain briefly.
4. Construct the recursive descent parser for the following grammar
E->TE’
E’->+TE’|€
T->FT’
T->*FT’|€
F->(E)|id
5. Construct Recursive Descent Parser for the following Grammar
S->Aa|bAc|bBa
A->d
B->d
6. Illustrate the role of a Parser with a neat sketch.
7. Show that the following grammar is LL(1)
S->AaAb | BbBa
A->€
B->€
8. Write down the problems that arises in Top Down parsing.
9. Eliminate Left Recursion from the following grammar
S->Aa | b
A->Ac|Sd|€
10. Consider the following grammar
E->T+E|T
T->V*T|V
V->id.
Write down procedures for non terminals of the grammar to make a recursive descent
parser.
11. Construct Predictive parsing table for following grammar
S->A
A->aB | Ad
B->bBC|f
C->g. Also parse the string for the input “abfgd”.
UNIT 3 IMPORTANT QUESTIONS
[Link] is Shift Reduce Parser? Construct Shift Reduce Parser for the following grammar
E->E –E | E * E | id.
Parse the input string “id1-id2*id3”.
[Link] in detail about YACC-Parser Generator model.
[Link] CLR (LR(1)) parsing table for the following grammar
S->CC
C->aC | d and parse the string "aadd".
[Link] Error recovery in LR Parsing achieved? Explain briefly.
[Link] an Operator Precedence parser for the following grammar
E->EAE |(E ) | -E | id
A->+ | -| * | / | ^
[Link] is handle pruning? Discuss in detail with an example.
7. How ambiguous Grammars are handled in Bottom Up parsing?
[Link] the Following Grammar
{S->A#, A->Bb, B->cC, B->cCc, C->dA, A->a}
(i) Generate the set of LR(1) items
(ii)Is the Grammar LR(1)? If not, Why?
9. S->CC
C->aC
C->d. Construct set of LR(1) items for LALR Parser.
10. Construct an Operator precedence parser for the following grammar
S->iEtS | iEtSeS | a
E->b|c|d
Where a,b,c,d,e,i,t are terminals.
11. Construct the collection of LR(0) item sets and draw the goto graph for the following grammar
S->SS | a | €.
Indicate conflicts (if any) in the various states of the SLR parser.
12. Construct a CLR parsing table for the following grammar
S->aSA | €
A->bS | c

UNIT 4 IMPORTANT QUESTIONS


1. Construct quadruples, triples and indirect triples for the following statement.
-(a+b)*(c+d)-(a+b+c)
2. Illustrate the concept of Syntax Directed Definition(SDD) with example.
[Link] the process of Static Single Assignment.
[Link] the syntax tree for the expression x*y-5+z using three routines.
[Link] is Activation Record? Discuss parameters present in Activation record with a neat sketch.
[Link] Storage Allocation Strategies
[Link] Postfix translation schemes and Parser-Stack implementation of postfix SDTs.
[Link] Translation of Assignment Statements is achieved in Syntax Directed Translation?
9. Construct Annotated Parse tree and Dependency graph for the input string 1#2&3 with the help
of following Production Table

[Link]. Productions Semantic Rules

1. S⇢A&B [Link] = [Link] + [Link]

2. A ⇢ A1 # B [Link] = [Link] * [Link]

[Link] = [Link]

3. A1 ⇢ B [Link] = [Link]

4. B ⇢ digit [Link] = [Link]


[Link] is Three Address Statement? Construct quadruple, triple and indirect triple for the
expression a+b*c/e↑f+b*c
[Link] synthesized attribute and Inherited attribute.
[Link] in detail about polish notation and Static Single Assignment.
[Link] the concept of parameter passing in Run Time Environment.
14. Construct the syntax directed definition to produce a syntax tree for Boolean expressions
15. Construct syntax tree and postfix notation for the following expression: (a+(b*c)^d-e/(f+g)

UNIT 5 IMPORTANT QUESTIONS


1. Discuss about the principle sources of code optimization techniques with example.
2. How loops in flow graph are constructed? Explain.
3. Discuss briefly about Peep Hole Optimization with examples.
4. What are the issues in design of a code generator?
5. Discuss in detail about DAG representation of basic blocks.
[Link] the following program code:
Prod=0;
I=1;
Do{
Prod=prod+a[i]*b[i];
I=i+1;
}while (i<=10);
a. Partition in into blocks
b. Construct the flow graph
7. Explain Loop Optimization and common sub expression Elimination techniques with suitable
examples
8. Write short notes on Register allocation and assignment.
9. Elaborate Simple Code Generation algorithm.
[Link] Data Flow Analysis is achieved in Code Generation?
11. Construct a DAG and write the sequence of Instructions for the expression a+a*(b-c)+(b-c)*d

Common questions

Powered by AI

Peep-hole optimization inspects small instruction sequences for patterns suitable for replacement with optimized code, enhancing performance. It tackles issues like redundant or suboptimal instructions and can significantly reduce execution time and size, making it crucial for final-stage optimization in modern compilers .

A shift-reduce parser uses a stack and input buffer mechanism to handle syntax analysis, shifting symbols until a recognizable pattern (handle) appears, which it then reduces to a non-terminal. Its advantage is robustness in error handling and efficiency, as it reduces a broad range of grammars, unlike LL parsers that require grammar restrictions like absence of left recursion .

Code optimization relies on eliminating redundancies, reducing resource consumption, and enhancing execution speed. Techniques include constant folding, loop unrolling, and strength reduction. For example, loop unrolling reduces the overhead of loop control statements by duplicating loop bodies, thus potentially doubling execution speed .

Generating a set of LR(1) items involves creating items by merging states with identical cores and computing lookahead for potential reductions. Challenges include handling conflicts, especially when grammar ambiguities or overlapping rules exist, which complicates state transitions and parsing decision-making .

Compiler phases are structured into lexical analysis, syntax analysis, semantic analysis, optimization, and code generation. This separation is pivotal for transforming high-level code into efficient machine code systematically. For instance, the syntax analysis phase uses a parse tree to ensure code structure correctness before optimization, which enhances runtime efficiency .

An SDD associates semantic rules with grammar productions to facilitate attribute evaluation. For instance, in translating expressions, an SDD can define how arithmetic operators combine attribute values to produce a result, using attributes like 'val' to hold expression results, such as for `E -> E1 + T` where `E.val = E1.val + T.val` .

Left recursion in grammars is problematic for top-down parsers as it causes infinite loops. To resolve this, left recursion is eliminated by restructuring the grammar, often introducing new non-terminals. This transformation is crucial to convert grammars into forms suitable for predictive parsing, ensuring efficient parsing operations .

Cross compilers are essential for generating code for a different type of system than the one on which they are running, supporting diverse hardware architectures. Bootstrapping refers to the process of writing a simple compiler (or interpreter) for a programming language and then using it to implement newer versions. For example, a cross compiler is used when developing mobile applications on a desktop computer, and bootstrapping is critical in initial compiler development phases to ensure the new compiler can compile more advanced versions of itself .

Specification of tokens defines what constitutes a valid token pattern using regular expressions, while recognition involves identifying these tokens in the input stream using finite automata. The specification outlines the rules, whereas recognition applies these rules to partition the input .

Annotated parse trees extend typical parse trees by including attribute values at each node, necessary for syntax-directed translation. Dependency graphs visualize attribute evaluation order, vital for ensuring dependencies are correctly resolved during translation. They help in systematically generating intermediate code based on semantic rules derived from the parse tree .

You might also like