0% found this document useful (0 votes)
2K views4 pages

Compiler Design Practical Exam Questions

This document contains a list of 25 questions for a Compiler Design practical examination. The questions cover topics such as regular expressions, finite automata, grammars, parsing, code generation, and storage allocation. It provides registration numbers for the students to write their names. It also specifies the marks split up for different components like programs, output, viva, etc. The total marks for the exam are 100.

Uploaded by

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

Compiler Design Practical Exam Questions

This document contains a list of 25 questions for a Compiler Design practical examination. The questions cover topics such as regular expressions, finite automata, grammars, parsing, code generation, and storage allocation. It provides registration numbers for the students to write their names. It also specifies the marks split up for different components like programs, output, viva, etc. The total marks for the exam are 100.

Uploaded by

Kisan Sakthi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
  • List of Questions
  • Marks Distribution

SRM INSTITUTE OF SCIENCE AND TECHNOLOGY

RAMAPURAM
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
MODEL PRACTICAL EXAMINATION
ACADEMIC YEAR 2020-2021 (EVEN SEMESTER)
YEAR/SEM: III/VI

SUB. CODE/SUB. TITLE: 18CS304J/ COMPILER DESIGN

LIST OF QUESTIONS
1. Write a C Program to convert the following Regular Expression in to NFA: a/b
Reg No: 66, 91,116
2. Convert the following regular expression (RE) to deterministic finite automaton (DFA) using
c program : (a+b)*
Reg No: 67,92,117
3. Write a program to convert NFA to DFA . Consider the expression is : (a/b)*abb
Reg No: 68,93,118
4. Write a program to compute first an follow for the given grammar.
E -> E+T, E -> T, T -> T*F, T -> F, F -> (E) / id
Reg No: 69,94,119
5. write a C program to Compute of Follow and Trailing Sets for the following grammar:
E -> E+T, E -> T, T -> T*F, T -> F, F -> (E) / id
Reg No: 70,95,120
6. write a C program to Compute of Follow and Trailing Sets for the following grammar:
E ->TE’ , E’ -> +TE’/e , T -> FT’, T’ -> *FT’/e, F -> (E)/ id
Reg No: 71,96,121
7. Write a Program to compute Predictive Parsing for the given grammar. Give input string as
“ba”. S ->AaAb | BbBa, A -> Є, B->Є
Reg No: 72,97,122
8. Write a Program to compute Recursive Descent Parsing for the given grammar. Give input
string as “ba”.
S ->AaAb | BbBa, A -> Є, B->Є
Reg No: 73,98,123
9. Write a program to implement shift reduce parsing for the following grammar:
E -> E+E, E -> E/E, E -> E*E, E->a/b. Check whether the input string a+b is valid or not.
Reg No: 74,99,124
10. Write a program to implement shift reduce parsing for the following grammar:
E -> E+E, E -> E * E, E->i. Check whether the input string i+i*i is valid or not.
Reg No: 75,100,125
11. write a code for LR(0) Parser for Following Production:
E->E+T
                                    T->T*F/F
                                    F->(E)/char
Reg No: 76,101,126
12. Write a C program to construct DAG for the following expression:
((a*(b-c))+((b-c)*d))
Reg No: 77,102,127
13. Write a program to generate code generation from the following 3AC :
T1= a+b; T2=c+d; T3=T1+T2
Reg No: 78,103,128
14. Write a program to convert the following infix notation in to postfix :
a+b*c/(d-e^f)
Reg No: 79,104,129
15. Write a program to convert the following infix notation in to prefix :
a+b*c/(d-e^f).
Reg No: 80,105,130
16. Write a program to Compute LR(0) items for the string x*y+z.
Reg No: 81,106
17. Write a program to compute FOLLOW for the following grammar?
E ->TE’ , E’ -> +TE’/e , T -> FT’, T’ -> *FT’/e, F -> (E)/ id
Reg No: 82,107
18. Construct a recursive descent parser for the following grammar:
E ->TE’ , E’ -> +TE’/e , T -> FT’, T’ -> *FT’/e, F -> (E)/ id
Note: e represents null character
Reg No: 83,108
19. Write a c Program to construct LL(1) parsing for the given string : i*i+I
Reg No: 84,109
20. Write a program to construct recursive descent parser for the following grammar :
E ->E+T|T, T ->TF|F, F->F* |a|b
Reg No: 85,110
21. Write a program to construct Predictive Parser for the following grammar:
S-> (L) |a, L-> L, S|S. Construct the behavior of the parser on the sentence (a,a) using the
grammar specified above.
Reg No: 86,111
22. Write a program to Construct A simple Code Generator for the following statement
x:= y + z.
Reg No: 87,112
23. Write a program to construct Shift reduce Parser for the following grammar:
S-> (L) |a, L-> L, S|S. Construct the behavior of the parser on the sentence(a, (a,a)) using
the grammar specified above.
Reg No: 88,113
24. Write a program to Construct A simple Code Generator for the following statement
x:= y – z, t=x.
Reg No: 89,114
[Link] a program to Implement Storage Allocation.
Reg No: 90,115

Marks Split-up:

Aim & Procedure 20 Marks


Programs 40 Marks
Output & Results 30 Marks
Viva 10 Marks
Total 100 Marks
EXAMINER-I EXAMINER-II

Common questions

Powered by AI

Transforming an infix expression to postfix typically uses a stack data structure following the Shunting Yard algorithm: Process input left to right, pushing operators onto the stack considering precedence and associativity, and popping to the output when higher-precedence is met. Parentheses pull expressions together shifting control, yielding postfix as operands are output first, before operators, resulting in: abc*de^f-/+ .

A code generator for x := y + z can include the following steps: 1) Use intermediate code representations, such as three-address code. 2) Map expression to specific instructions for the target architecture. For example: generate an instruction to load y into a register, add z to this register, and store the result in memory location of x .

Challenges include left-recursion removal since it’s unsuitable for recursive descent. Alternations and multiple derivation paths introduce complexity as backtracking or lookahead is needed to disambiguate. Implementing predictive parsing tables with sophisticated FIRST and FOLLOW sets supports eliminating ε-productions and distinguishing paths based on input handling .

To design a Predictive Parser, construct parser tables with entries corresponding to specific input tokens and stack symbols. Use FIRST and FOLLOW sets to guide table entries. For the input (a,a), trace: push starting symbol S. At '(', use rule S -> (L). For L, use L -> L, S | S with input iteratively splitting at ',' and matching terminal 'a', spanning nested structures in a top-down fashion, resulting in a valid parse .

To compute 'FIRST' sets, analyze grammar rules to find terminals that appear at the start of derivations: 'FIRST(E)' includes {(, id} from both 'E -> E+T' and 'E -> T'. 'FOLLOW' sets are found by determining which terminals can appear directly following each variable in derivations using specific rules such as: If a production X -> αYβ exists, everything in 'FIRST(β)' (except ε) is in 'FOLLOW(Y)'. Repeat until no more changes can be identified .

Generating three-address code involves breaking complex expressions into simpler instructions. Every sub-expression gets a temporary variable if needed, ensuring operations like load, perform arithmetic, and store are separated. Equality constraints allocate temp variables reflecting computational dependencies and intermediate values, making subsequent optimizations like line addressing, dead code elimination feasible .

The process involves several steps: 1) Convert the regular expression into an NFA using Thompson's construction. 2) Define a start state for the NFA. 3) Create a DFA whose states correspond to sets of NFA states (subset construction method). 4) Continue processing from initial NFA state, grouping transitions, and marking the DFA acceptance states corresponding to the NFA’s acceptance states .

An LR(0) parser constructs a parse stack based on states from a DFA and makes parsing decisions via shift/reduce actions by looking at the current state and input. It uses grammar specific tables for parsing directly. A shift-reduce parser utilizes a stack to hold grammar symbols and inputs are matched through shifts and reduces without pre-computed states, potentially backtracking without LR format optimizations .

For shift-reduce parsing, start with an empty stack and shift input symbols (a and +) one by one while continually checking the top of the stack. Reduce whenever a valid production rule (E -> a or E -> E+E) matches with sequence stack content ensuring stack eventually reduces to start symbol completely. Failed final reduction or incomplete inputs indicate an invalid case; successful reduction confirms validity .

Predictive parsers rely on top-down parsing strategies that inherently struggle with left recursion, which causes infinite loops on recursive calls. Eliminating left recursion transformation ensures a deterministic parsing path, compatible with lookahead mechanisms to decide actions based on FIRST sets. This facilitates immediate recursive descent decisions avoiding undecidable loops and enabling LL(1) transformations .

You might also like