Unit Ii 2 Marks
Unit Ii 2 Marks
Unit Ii 2 Marks
3. Give two examples for each of top down parser and bottom up parser.
Top down parser
Recursive descent parser
Predictive parser
Bottom up parser
Operator precedence parser
Simple LR (SLR) parser
An abstract syntax tree (AST), or just syntax tree, is a tree representation of the abstract syntactic
structure of source code written in a programming language. Each node of the tree denotes a construct
occurring in the source code. The syntax is 'abstract' in the sense that it does not represent every detail
that appears in the real syntax.
5. Derive the string and construct a syntax tree for the input string ceaedbe using the grammar
S->SaA|A, A->AbB|B, B->cSd|e
6. Construct an equivalent unambiguous grammar for the grammar S-> aSbS | bSaS | ε
is the unique alternative that derives a string beginning with ‘a’. (i.e) The proper alternative must be
detectable by looking at only the first symbol it derives.
A β AI
AI α AI | ε
For a grammar to be LR(1), we must be able to recognize the occurrence of the right side of a
production, having seen all of what is derived from that right side with 1 input symbol of look ahead.
This requirement is far less stringent that LL grammars. LR grammars can describe more languages that
LL grammars.
S -> (L) | a
L -> S LI
LI -> ,S LI | ε
An LR(0) item of a grammar G is a production of G with a dot at some position of the right side. Thus,
production A → XYZ yields the four items
A→ .XYZ
A→ X.YZ
A→ XY.Z
A→ XYZ.
Look ahead character is used to resolve shift reduce conflicts that may arise in SLR parsers for certain
grammars. CLR parser produces right most derivation in reverse.
13. Eliminate left factoring if there is one from the following grammar.
S AaB | Aac | d
A d
B ε
Ans:
The productions of S has left factors (S AaB | Aac )
Elimination of Left factors :
Productions of the form A αβ1 | αβ2 can be rewritten as
A αA’
A’ β 1 | β2
S AaS’
S’ B|c
20. When a grammar is said to be a CLR grammar? List out the steps in CLR parsing.
A grammar whose CLR parsing table has no multiply deifned entries is said to be LR(1) or CLR
grammar. A grammar for which a CLR parser can be constructed is said to be a CLR grammar.