Backtracking. Left Recursion. Left Factoring

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

16. Define Ambiguous Grammar.

an ​ambiguous grammar​ is a context-free ​grammar​ for which there exists a string that
can have more than one leftmost derivation or parse tree

17. Which parser needs pre-processing of Context-Free Grammar?


Top down parser

18. Which derivation a top-down parser generates?


Leftmost derivation

19. In LL(1), what both L’s stand for?


the first L stands for scanning the input from left to right, the second L stands for
producing a leftmost derivation

20. What Are the Problems with Top-Down Parsing?


Backtracking. Left recursion. Left factoring.

21. What is left recursion? What is the problem with left recursion?
The grammar of the form,

S --> S / a / b

called left recursive where S is any non Terminal and a, and b are any set of terminals.

Problem with Left Recursion:

If a left recursion is present in any grammar then, during parsing in the syntax analysis
part of compilation there is a chance that the grammar will create an infinite loop. This is
because at every time of production of grammar S will produce another S without
checking any condition.

22. What is a Viable Prefix? (in bottom up parsing)


Viable Prefix​ is a ​prefix​ of a right-sentential form that does not continue past the right
end of the rightmost handle of that sentential form. This clearly means that a ​viable
prefix​ has a handle at its rightmost end.
23. What is handle?

A ​handle​ of a string is a substring that matches the right side of a production, and
whose reduction to the nonterminal on the left side of the production represents one
step along the reverse of a rightmost derivation.

24. List the Properties of LR Parser.


non-recursive, shift-reduce, bottom-up parser.

25. Mention the Types of LR Parsers

In the LR parsing, "L" stands for left-to-right scanning of the input.

"R" stands for constructing a right most derivation in reverse.

● SLR(1) – Simple LR Parser:


○ Works on smallest class of grammar
○ Few number of states, hence very small table
○ Simple and fast construction
● LR(1) – LR Parser:
○ Works on complete set of LR(1) Grammar
○ Generates large table and large number of states
○ Slow construction
● LALR(1) – Look-Ahead LR Parser:
○ Works on intermediate size of grammar
○ Number of states are same as in SLR(1)
● CLR(1) - canonical LR parser

You might also like