0% found this document useful (0 votes)
18 views24 pages

Compiler Design QB CS1602A

The document is a question bank for the Compiler Design course at S.A. Engineering College for the academic year 2023-2024. It includes a detailed syllabus covering various units such as lexical analysis, parsing, syntax-directed definitions, and storage organization, along with a series of questions categorized into Part-A and Part-B for each unit. The questions assess different cognitive levels, from remembering basic concepts to analyzing and applying knowledge in compiler design.

Uploaded by

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

Compiler Design QB CS1602A

The document is a question bank for the Compiler Design course at S.A. Engineering College for the academic year 2023-2024. It includes a detailed syllabus covering various units such as lexical analysis, parsing, syntax-directed definitions, and storage organization, along with a series of questions categorized into Part-A and Part-B for each unit. The questions assess different cognitive levels, from remembering basic concepts to analyzing and applying knowledge in compiler design.

Uploaded by

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

S.A.

ENGINEERING COLLEGE
(An Autonomous Institution, Affiliated to Anna University)
QUESTION BANK
EVEN SEMESTER, 2023 - 2024

B.E. Computer Science and Engineering


ACADEMIC YEAR: 2023-2024 (EVEN)
SUBJECT CODE: CS1602A
SUBJECT TITLE: COMPILER DESIGN
COURSE CO-ORDINATOR: Dr.M.Nalini
SEM/YEAR: VI/ III
UNIT I
SYLLABUS:
Structure of a compiler – Lexical Analysis – Role of Lexical Analyzer – Input Buffering – Specification of
Tokens – Recognition of Tokens – Lex – Finite Automata – Regular Expressions to Automata – Minimizing
DFA, Applications of Compiler.

PART-A
MAR BTL COMPETEN
S. NO QUESTIONS CO
KS LEVEL CE

State any 2 reasons why phases of compiler should be


1. 1 2 BTL-1 Remember
grouped.

2. What are the functions of pre-processor? 1 2 BTL-1 Remember

Draw and illustrate the components and interactions


3. of a language processing system through a diagram, 1 2 BTL-2 Understand
highlighting its key elements and their relationships.
Differentiate environment and state. Show their
4. 1 2 BTL-2 Understand
respective mapping diagram.

Describe the languages denoted by the following


5. 1 2 BTL-2 Understand
regular expression : a(a|b)*b.

Give the structure and functionality of a transition


6. diagram used to differentiate identifiers and keywords 1 2 BTL-2 Understand
in programming languages.

7. List out all error recovery actions in lexical analyzer. 1 2 BTL-1 Remember

Identify and differentiate the token names and their


8. corresponding values for the statement "E = M * C ** 1 2 BTL-2 Understand
2".

9. Describe the structure of Lex program. 1 2 BTL-1 Remember

State any 2 reasons why phases of compiler should be


10. 1 2 BTL-1 Remember
grouped.
11. What are the issues to be considered in the 1 2 BTL-1 Remember
design of lexical analyzer?

12. Define concrete and abstract syntax with 1 2 BTL-1 Remember


example.

13. What are the possible error recovery actions in 1 2 BTL-1 Remember
lexical analyzer?

14. 1 2 BTL-1 Remember


Mention few cousins of compiler.

15. 1 2 BTL-2 Understand


Write a short notes on buffer pairs.

PART-B

Explain the compilation process; illustrate the


1. importance of each phase. Apply the result of a 1 13 BTL-3 Apply
particular phase given the input a=(b+c)*(b+c)*2."

Solve and construct the given regular expression to


2. 1 13 BTL-3 Apply
minimized DFA using optimization method (a|b)*a(a|b)
Apply optimization strategies to Construct the
3. minimized DFA for the following regular expression 1 13 BTL-3 Apply
(0+1)*(0+1) 10

i. Illustrate the following term: compiler, interpreter,


Translator and differentiate between them.
4. 1 13 BTL-3 Apply
ii. Briefly explain compiler construction tools with
example

Illustrate the distinction between the Analysis Phase and


Synthesis Phase. Provide detailed explanations
5. 1 13 BTL-3 Analyze
supported by diagrams and examples, highlighting the
significance of each phase.

Analyze the compilation process for the expression


c=a+b*5, delineating the phases and passes while
6. 1 13 BTL-4 Analyze
highlighting their respective purposes and the intricate
interplay within the compiler design framework.

With a detailed analysis, construct the output of each


phase in the compiler design process for the expression i
7. = i * 70 + j + 2. Investigate and differentiate the output 1 13 BTL-4 Analyze
yielded by each stage, emphasizing the role and
transformation occurring in every phase.

1 13 BTL-2 Understand

8. (i) Discuss about the input buffering scheme in lexical


Analyzer.(6)
(ii) Construct a NFA using Thompson’s construction
algorithm for the regular expression (a|b)*abb (a|b)* and
convert into DFA.(7)

Construct a DFA directly from the regular expression


9. 1 13 BTL-2 Understand
(a|b)* abb without constructing NFA.

Write the briefly about input buffering, specifications of


10. 1 13 BTL-2 Understand
tokens, recognition of tokens.

UNIT II
SYLLABUS:

Role of Parser – Grammars – Error Handling – Context-free grammars – Writing a grammar –Top Down Parsing
- General Strategies Recursive Descent Parser Predictive Parser-LL(1) Parser-Shift Reduce Parser-LR Parser-LR
(0)Item Construction of SLR Parsing Table -Introduction to LALR Parser - Error Handling and Recovery in
Syntax Analyzer-YACC.

PART-A
MARK K COMPETENC
S.NO QUESTIONS CO
S LEVEL E
2 2 BTL-2 Understand

1. Elimination of immediate left recursion for the


following grammar.
E → E + T| T
T → T * F| F
F → ( E )| id

2. Define an ambiguous grammar. 2 2 BTL-1 Remember

Discover FIRST and FOLLOW for the following


3. grammar S→+SS | *SS | a
2 2 BTL-2 Understand

4. Differentiate Top down parsing and Bottom up Parsing. 2 2 BTL-2 Understand

5. Define Handle Pruning. 2 2 BTL-1 Remember

6. Define syntax tree. Give an example? 2 2 BTL-1 Remember

7. What are the different levels of syntax error handler? 2 2 BTL-1 Remember

8. Generate the structure of YACC program. 2 2 BTL-1 Remember


Show the syntax tree for the following assignment
9. statement: a:=b*-c+b*-c.
2 2 BTL-2 Understand

10. Define Recursive Descent Parsing. 2 2 BTL-1 Remember

11. List the factors to be considered for top-down parsing.

Eliminate Left Recursion for the grammar A→Ac|Aad|


12. bd

What are the various conflicts that occur during shift


13. reducing Parsing?

Why SLR and LALR are more economical to construct


14. than canonical LR?

15. What are kernel and non-kernel items?

PART-B
Develop stack based implementation to construct shift
reduce parsing for the grammar
E->E+E
1. E->E*E 2 13 BTL-3 Apply
E->(E)
E->id and demonstrate its application on the input string
id1+id2*id3.

Analyze the given grammar


S →AS|b
2. A→SA|a 2 13 BTL-4 Analyze
Construct the SLR parse table for the grammar. Estimate
the actions of the parser for the input string “abab”.

Apply stack based Implementation to construct shift


reduce parsing for the grammar
3. S→ (L) | a
2 13 BTL-3 Apply
L→ L, S | a
Show whether the following string will be accepted or not.
(a, ((a, a), (a, a)))

Consider the given grammar


E→E+T|T
T→T*F|F
F → (E) | id
4. along with the input string "id1 + id2 * id3" to determine
2 13 BTL-4 Analyze
if the grammar is LL(1). Perform the following tasks:
i. Elimination left recursion.
ii. Find First and Follow.
iii. Generate the Parsing Table.
iv. Stack Implementation for input string.
Analyze the following grammar
E→E+T|T
5. T → TF | F
2 13 BTL-4 Analyze
F→F*|a|b
Construct the SLR parse table for the grammar. Estimate
the actions of the parser for the input string “a * b + a”

Consider the given grammar:


S → if ( E ) S | if ( E ) S else S
6. S → other
2 13 BTL-4 Analyze
E → expr
Analyze the ambiguity for the following string.
if ( expr ) if ( expr ) other else other

Analyse the following grammar


S →CC|b
C→aC|d
7. Construct the LALR parse table for the grammar and 2 13 BTL-4 Analyze
analyze the parser actions step-by-step for the input string
"aadd", correlating each action with the LALR parsing
process.

Consider the following grammar


S →AA
A→Aa|b
8. 2 13 BTL-4 Analyze
Construct the CLR parse table for the grammar.
Distinguish the actions of the parser for the input string
“bba”

9. Check whether the grammer is LALR(1) but not SLR(1)


S-->Aa/bAc/dc/bda
A-->d

Find LALR for the given grammer and parse the sentence
10. (a+b)*
E->E+T|T, T->T*F|F,F->(E)|id

UNIT III
SYLLABUS:

Syntax Directed Definitions, Evaluation Orders for Syntax Directed Definitions, Intermediate Languages:
Syntax Tree, Three Address Code, Types and Declarations, Translation of Expressions, Type Checking.

PART-A
K
S.NO QUESTIONS CO MARKS COMPETENCE
LEVEL

1. What is backpatching? 3 2 BTL-1 Remember

2. Identify the properties of intermediate languages 3 2 BTL-2 Understand


3. Enumerate the methods of translating Boolean
3 2 BTL-1 Remember
expressions.

4. Write down syntax directed definition of a simple


3 2 BTL-1 Remember
desk calculator

5. Define Annotated parse tree. 3 2 BTL-1 Remember

6. What are the various methods of implementing


3 2 BTL-1 Remember
three address statements?

7. Extend the three address code for a=b*-c+b*-c. 3 2 BTL-2 Remember

8. Construct the syntax tree for the expression


3 2 BTL-2 Understand
a=b+c*10

9. Describe the rule for type checking 3 2 BTL-2 Understand


10. Differentiate Synthesized Attribute and Inherited 3 2 BTL-2 Remember
Attribute.

Convert the expression a * – (b + c) into three


11. address code. 3 2 BTL-2 Remember

12. Mention the two rules for type checking.

13. What is an activation tree?

14. What is the use of a control stack?

Give the 2 attributes of syntax directed translation


15. into 3-addr code?

PART-B

Distinguish a Syntax directed definition for


1. constructing syntax tree for assignment statement
3 13 BTL-4 Analyze
S-> id := E
E -> E1+E2 | E1*E2|-E1|(E1)|id
2. Discover the intermediate code for the flow of
3 13 BTL-4 Analyze
control statements? Explain with example

Design simple code generator algorithm and


3. evaluate the code sequence for d = (a-b) + (a-c) + 3 13 BTL-4 Analyze
(a-c)

4. Construct the quadruples, triple and indirect triples


3 13 BTL-3 Apply
for the expression = (a*b)+(c+d)-(a+b+c+d)

5. Illustrate (a or b) and (c < d) and (d < e) into three


3 13 BTL-3 Apply
address statements using back patching

Correlate intermediate code for the following code


segment along with the required syntax directed
translation scheme:
1.If (a>b)
x=a+b
else
x=a-b
where a & x are of real and b of int type data
3 13 BTL-4 Analyze
6.
2.int a,b ;
float c
a=10
switch (a)
{
Case 10: c=1;
Case 20: c=2;
}
Analyze the SDD annotated parse tree expressions
for the given mathematical expressions:
a) 3 * 5 + 4n
3 13 BTL-4 Analyze
7. b) 3 * 5, emphasizing the intricacies and
relationships between the components within the
parse tree structure.

Construct syntax directed definitions for arithmetic


8. expression. Explain the construction of syntax tree 3 13 BTL-3 Apply
and decorated parse tree with example

Explain in detail about the specification of a simple


9. type checker for statements, expression and
functions.

Explain three address codes and its types. How


10. would you implement the three Address statements?
Explain with suitable examples.
UNIT IV
SYLLABUS:

Storage Organization, Stack Allocation Space, Access to Non-local Data on the Stack, Heap Management -
Issues in Code Generation - Design of a simple Code Generator.

PART-A
K
S.NO QUESTIONS CO MARKS COMPETENCE
LEVEL

1. What are the Limitations of static allocation 4 2 BTL-1 Remember

2. List the types of storage allocation strategies 4 2 BTL-1 Remember

3. What are the strategies applied in storage


4 2 BTL-1 Remember
allocations?

4. Differentiate between stack and heap allocation 4 2 BTL-2 Understand

5. Define symbol table. 4 2 BTL-1 Remember


6. Differentiate between static allocations and stack
4 2 BTL-2 Understand
allocations

What are the uses of register and address


7. 4 2 BTL-1 Remember
descriptors in code generation?

What are the issues in the design of code


8. 4 2 BTL-1 Remember
generators?

9. Describe in detail on global data flow analysis. 4 2 BTL-2 Understand

Summarize a suitable approach for computing the


10. hash function? 4 2 BTL-2 Understand

Define activation record and list out the fields in


11. it.

12. What do you mean by binding of names?


13. List Dynamic Storage allocation techniques.

14. When procedure call occurs, What are the taken?

15.

PART-B

Compare and contrast storage allocation


strategies, including static allocation, stack
1. allocation, heap allocation, and register allocation, 4 13 BTL-3 Apply
using examples to illustrate their advantages and
disadvantages across different scenarios.

Illustrate how symbol tables are constructed and


managed during the compilation process. Provide
2. examples of symbol tables and explain how they 4 13 BTL-3 Apply
store information about identifiers, such as
variables, functions, and types.

Categorize the issues arise during the design of


3. code generator? Explain how these issues are 4 13 BTL-4 Analyze
handled. Give suitable examples.
Analyze the sequence of stack allocation
4. processes for a function call and describe in detail 4 13 BTL-4 Analyze
about the stack allocation in memory management

5. Determine various ways of implementing for


4 8 BTL-3 Apply
symbol table and compare merits and demerits

Identify a suitable representation for symbol


tables of procedure oriented languages and how
6. 4 8 BTL-3 Apply
names can be looked up in the symbol table?
Discuss

Analyze simple code generator algorithm and


7. generate the code sequence for d = (a-b) + (a-c) + 4 13 BTL-4 Analyze
(a-c)

8. Explain about run time storage management.

What is a symbol table? What type of information


is stored in it? Discuss on the use of the data
9. structures (i) arrays (ii)Linked lists (iii) Binary
search trees for implementing a symbol table.
What are different storage allocation strategies.
10.
Explain.

UNIT V
SYLLABUS:

Principal Sources of Optimization – Peep-hole optimization - DAG- Optimization of Basic Blocks- Global
Data Flow Analysis - Efficient Data Flow Algorithm.

PART-A
MAR COMPETENC
S.NO QUESTIONS CO K LEVEL
KS E

1. Describe the addressing mode and associated


5 2 BTL-2 Understand
costs in the target machine.

2. Discover and sketch DAG for a=(a*b+c) -


5 2 BTL-2 Understand
(a*b+c)

3. State the advantages of DAGs? 5 2 BTL-1 Remember

4. What are the characteristics of peephole


5 2 BTL-1 Remember
optimization?
5. Mention some of the major optimization
5 2 BTL-1 Remember
techniques?

6. What are the methods available in loop


5 2 BTL-1 Remember
optimization?

7. What are the principle sources of optimization? 5 2 BTL-1 Remember

8. What is data flow analysis? 5 2 BTL-1 Remember

9. What are the properties of optimizing compiler? 5 2 BTL-1 Remember

10. Summarize the constructs for optimization in 5 2 BTL-2 Understand


basic block.

11. What is meant by Common Sub-expressions? 5 2 BTL-1 Remember


12. What do you mean by copy propagation?

13. What is meant by peephole optimization?

Draw DAG to represent


14. a[i] = b[i];
a[i]=&t;

15. How do you calculate the cost of an instruction?

PART-B

Analyze a systematic procedure for conducting


1. global data flow analysis on a complex software
5 13 BTL-4 Analyze
system, including equations and give own
examples to clarify the process.

5 13 BTL-3 Apply

2. Define DAG. Construct and solve a DAG and


write the sequence of instructions for the
expression.
a+a*(b-c)+(b-c) * d

Analyze and write an algorithm for constructing


DAG and apply it for the following 3 address
code.
3. d=b*c 5 13 BTL-4 Analyze
e=a+b
b=b*c
a=e-d

Apply the Directed Acyclic Graphs (DAGs) for


4. basic blocks, including an example to illustrate 5 13 BTL-3 Apply
their function and structure.

Consider the following basic block-


L10:
S1 = 4 x I
S2 = addr(A) – 4
S3 = S2[S1]
S4 = 4 x I
S5 = addr(B) – 4
S6 = S5[S4]
5. S7 = S3 x S6 5 13 BTL-4 Analyze
S8 = PROD + S7
PROD = S8
S9 = I + 1
I = S9
If I <= 20 goto L10
Evaluate and sketch a Directed Acyclic Graph
(DAG) and identify local common sub-
expressions.
Apply peephole optimization techniques,
6. providing detailed explanations along with an 5 13 BTL-3 Apply
illustrative example.

Apply the common sub expression-- elimination,


copy propagation and transformations for moving
7. 5 13 BTL-3 Apply
loop invariant computations in detail with an
example?

Explain the structure – preserving transformations


8. for basic blocks.

Explain the principle sources of code optimization


9. in detail.

(i) Explain in detail about optimization of basic


blocks.
(ii) Construct the DAG for the following Basic
block and Explain it.
T1 := a * a
10. T2 := a * b
T3 := 2 * T2
T4 := T1 + T3
T5 := b * b
T6 := T4 + T5
COURSE COORDINATOR EVALUATOR HoD/CSE

You might also like