Compiler Design Un 2 2m
Compiler Design Un 2 2m
Environmental Sciences
Professional English and Sustainability -
Professional English - - II - HS3252 Discrete Mathematics GE3451
I - HS3152 - MA3354
Statistics and Theory of Computation
Matrices and Calculus Numerical Methods - Digital Principles and - CS3452
3rd Semester
4th Semester
- MA3151 MA3251 Computer Organization
1st Semester
2nd Semester
8th Semester
6th Semester
Question Bank
Prepared By,
https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com
4931_GRACE College of Engineering, Thoothukudi
UNIT II
SYNTAX ANALYSIS
2 marks
1. What is the output of syntax analysis phase? What are the three general typesof
parsers for grammars?
Parser (or) parse tree is the output of syntax analysis phase.
General types of parsers:
1) Universal parsing
2) Top-down
3) Bottom-up
2. What are the different strategies that a parser can employ to recover from a
syntactic error?
Panic modePhrase
level
Error productions
Global correction
6. Define context free language. When will you say that two CFGs are equal?
A language that can be generated by a grammar is said to be a context free language. Iftwo
grammars generate the same language, the grammars are said to be equivalent.
CS3501_CD
https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com
4931_GRACE College of Engineering, Thoothukudi
10. Why do we use regular expressions to define the lexical syntax of a language?
i. The lexical rules of a language are frequently quite simple, and to describe them we do
not need a notation as powerful as grammars.
ii. Regular expressions generally provide a more concise and easier to understand
notation for tokens than grammars.
iii. More efficient lexical analyzers can be constructed automatically from regular
expressions than from arbitrary grammars.
iv. Separating the syntactic structure of a language into lexical and non lexical parts provides
a convenient way of modularizing the front end of a compiler into two manageable-sized
components.
11. When will you call a grammar as the left recursive one?
A grammar is a left recursive if it has a nonterminal A such that there is a
derivation A A for some string .
https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com
4931_GRACE College of Engineering, Thoothukudi
https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com
4931_GRACE College of Engineering, Thoothukudi
24. What are the disadvantages of operator precedence parsing? May/June 2007
i. It is hard to handle tokens like the minus sign, which has two different precedences.
ii. Since the relationship between a grammar for the language being parsed and the operator
– precedence parser itself is tenuous, one cannot always be sure the parser accepts exactly
the desired language.
iii. Only a small class of grammars can be parsed using operator precedence techniques.
29. Why SLR and LALR are more economical to construct than canonical LR?
For a comparison of parser size, the SLR and LALR tables for a grammar always have
the same number of states, and this number is typically several hundred states for a language
like Pascal. The canonical LR table would typically have several thousand states for the
same size language. Thus, it is much easier and more economical to construct SLR and
LALR tables than the canonical LR tables.
CS3501_CD
https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com
4931_GRACE College of Engineering, Thoothukudi
PART B
1. Explain left recursion and Left Factoring.
2. Eliminate left recursion and left factoring for the following grammar.
E→E+T|E-T|T
T → a | b | ( E ).
5. Evaluate predictive parsing table and parse the string id+id*id. find FIRST and FOLLOW.
E→E+T | T T→T*F | F
F→(E) | id
9. What are the Error recovery techniques used in Predictive parsing? Explain in detail.
10. Analyze the following grammar is a LR(1) grammar and construct LALR parsing table.
S → Aa | bAc | dC | bda
A→ d.
Parse the input string bdc using the table generated.
11. Define SLR (1) parser. Describe the Steps for the SLR parser.
12. Predict the following grammar for generate the SLR parsing table.
E→E+T | T
T→T*F | F
CS3501_CD
https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com
4931_GRACE College of Engineering, Thoothukudi
CS3501_CD
https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
Click on Subject/Paper under Semester to enter.
Environmental Sciences
Professional English and Sustainability -
Professional English - - II - HS3252 Discrete Mathematics GE3451
I - HS3152 - MA3354
Statistics and Theory of Computation
Matrices and Calculus Numerical Methods - Digital Principles and - CS3452
3rd Semester
4th Semester
- MA3151 MA3251 Computer Organization
1st Semester
2nd Semester
8th Semester
6th Semester