Professional Documents
Culture Documents
Kovilvenni-614 403
1. Define NFA.
A non-deterministic finite automaton (NFA) is a mathematical model that consists of:
1. S- a set of states
2. -a set of input symbols (alphabet)
3. Move- a transition function move to map state-symbol pairs to sets of states.
4. S0-a start (initial) state
5. F- a set of accepting states (final states)
2. Define DFA.
A deterministic finite automaton (DFA) is a special form of a NFA.
No state has - transition
For each symbol a and state s, there is at most one labelled edge a leaving s. i.e. transition
function is from pair of state-symbol to state (not set of states).
3. What are error recovery actions in lexical analyzer?
1. Deleting an extraneous character.
2. Inserting a missing character.
3. Replacing an incorrect character by a correct character.
4. Transporting two adjacent characters.
4. What is Buffer Pair?
To reduce the amount of overhead required to process an input character, a buffer has
been used. It is divided into 2 N-character halves where N is the number of characters on
one disk block.
5. What is sentinel?
The sentinel is a special character used to represent the end of the buffer which cannot
be a part of the source program.
: : E : : : = : : M : * : eof :c : : : : eof
The errors due to undefined variables incompatible operands, etc., are called
semantic errors.
4. Define derivation.
The process of expanding the start symbol of the grammar to a desired string of
terminals by a sequence of intermediary strings is called derivation.
5. Define ambiguous grammar.
A grammar is said to be ambiguous if there exists more than one parse tree for the
same sentence. It can have more than one leftmost and rightmost derivation.
6. What are the two ways of top-down parsing?
i) Recursive descent parsing.
ii) Predictive parsing
7. Define recursive descent parsing.
The parser consists of a set of manually recursive routines which may require
backtracking to create a parse tree and it also requires repeated scanning of the input.
8. What are the advantages of LR parsing?
i) LR parser can recognize virtually all programming language constructs in
CFG.
ii) It is the most general backtracking technique known.
iii) Can detect syntax errors quickly.
9. Define LL(1) grammar.
A grammar is an LL(1) grammar if all productions satisfies the following conditions.
i) For each production A ->1|2|.....|n ,
FIRST (i) n FIRST(j)= for all ij
ii) If nonterminal X can derive an empty string, then
FIRST(X) n FOLLOW(X) =
A grammar is said to be operator grammar if there does not exist and production
rule with right hand side.
i) As
ii) Two non terminals appearing consecutively
Eg. E E+E
E id
11. Immediate Left Recursive Grammar
A grammar is left recursive if it has a non-terminal A such that there is a
derivation.
A A
Top-down parser techniques cannot handle left-recursive grammars
12. Left Factoring
A predictive parser ( a top-down parser without backtracking) insists that the
grammar must be left-factored
A 1|2 where is non-empty and the first symbols of 1 and 2 (if they have
one ) are different.
Rewrite the grammar as follows
A A
A 1|2 so we can immediately expand A to A
13. Eliminate left recursion for the following grammar
A A|
Eliminate as
A A
A aA
Given: E E+T
E TE
E TE|?
14. What is Recursive Descent Parsing?
It is a top-down parser which requires backtracking. (if a choice of a production
rule does not work, we backtrack to try other alternatives). But it is not efficient.
15. What is predictive parser?
It is a recursive descent top down parser without backtracking.
It consists of stack, input buffer and finite control and tries to find the leftmost
derivation.
Recursive Predictive Parsing is a special form of Recursive Descent parsing
without backtracking.
Non-Recursive (Table Driven) predictive parser is also called as LL(1) parser.
16. How do you find FIRST and FOLLOW?
FIRST () is a set of the terminal symbol which occur as first symbols in strings
derived from where is any string of grammar symbols. If derives to , then is
also in FIRST ().
FOLLOW(A) is the set of the terminals which occur immediately after (follow) the
non-terminal A in the strings derived from the starting symbol.
- A terminal a is in FOLLOW (A) if S Aa
- $ is in FOLLOW(A) if S A
17. Write an algorithm for finding FOLLOW.
i) If S is the start symbol $ is in FOLLOW(S)
ii) If A B is a production rule
Everything in FIRST() is FOLLOW(B) except
iii) If (A B is a production rule ) or
(A B is a production rule and is in FIRST())
Everything in FOLLOW(A) is in FOLLOW(B)
18. What is operator precedence parser?
Parse all LR(1) grammars where two consecutive non terminals never appear in
the right-hand side of any rule and no epsilon present in the right side.
19. Define Handle.
Handle of a string is the substring that matches right side of a production and
whose reduction to the non terminal on the left side of the production represents one
step along the reverse of a right most derivation.
20. What is LL(1) grammar?
A grammar whose parsing table has no multiply-defined entries is said to be LL(1)
grammar.
L- left most derivation
L-input scanned from left to right
1- One input symbol used as a look-head symbol to determine parser action
21. Examples for LL(1) grammar.
i) Left Recursive Grammar
ii) Ambiguous Grammar
22. What are the Error Recovery techniques?
Panic-Mode error recovery
- Skipping the input symbols until a synchronizing token is found
- Each empty entry in the parsing table is filled with a pointer to a specific error
routine to take care that error case.
23. What is Bottom-up parser?
A bottom-up parser creates the parse tree of the given input starting from leaves
towards the root.
A bottom-up parser tries to find the right-most derivation of the given input in the
reverse order.
24. Define Shift Reduce Parser.
Bottom-up parsing is also known as shift-reduce parsing because its two main
actions are shift and reduce.
- At each shift action, the current symbol in the input string is pushed to a stack.
- At each reduction step, the symbols at the top of the stack (this symbol
sequence is the right side of a production) will replaced by the non-terminal at
the left side of that production.
- There are also two more actions: accept and error.
25. What are the conflicts encountered while parsing?
Stack contents and the next input symbol may not decide action:
- Shift/reduce conflict : whether make a shift operation or a reduction.
- Reduce/reduce conflict: the parser cannot decide which of several reductions
to make.
26. What are the categories of shift reduce parser?
There are two main categories of shift reduce parser.
1. Operator-precedence parser
- Simple, but only a small class of grammars.
2. LR-parsers
- Covers wide range of grammars.
1. SLR- simple LR parser
2. LR- most general LR parser
3. LALR-intermediate LR parser (lookhead LR parser)
27. What is LR(k) parsing?
L-left to right canning
R- right most derivation
K- lookhead
28. Write short note on closure operation.
If I is a set of LR(0) items for a grammar G, then closure(I) is the set of LR(0) items
constructed from I by the two rules:
Deducing at compile time that the value of an expression is a constant and using the constant
instead.
In order to perform code optimization and code generation in a good manner, a compiler
needs to collect information about the program as a whole and to distribute this
information to each block in the flow graph. This can be performed by Global Data-flow
analysis.