UNIT 2 Notes CD
UNIT 2 Notes CD
• SLR parser
• LALR parser
• Canonical LR parser
SLR Parser
• LR parser is also called as SLR parser
• a grammar for which SLR parser can be constructed is called SLR grammar
Starts from the start symbol Starts from the input symbols
Works from top to bottom of the tree Works from bottom to top of the tree
Tries to build the parse tree Tries to reduce input to start symbol
May struggle with left recursion Can handle left recursion well
• Backtracking is used when there are multiple choices, and the first one fails.
o Left Factoring
Example:
Original Grammar (has left recursion):
E→E+T|T
T→T*F|F
F → ( E ) | id
After Removing Left Recursion:
E → T E'
E' → + T E' | ε
T → F T'
T' → * F T' | ε
F → ( E ) | id
Uses only synthesized attributes Uses both synthesized and inherited attributes
Less flexible for complex semantic needs More flexible in many semantic designs
• It is accepted by a special machine called a Pushdown Automaton (PDA) that uses a stack to
keep track of things.
• CFLs are great at handling nested structures like brackets: (( )), { { } }, etc.
• CFLs are more powerful than regular languages but not as powerful as all computer
languages.
Properties :
1. Closure Properties
2. Decision Properties
Can decide:
3. Deterministic property
A syntax tree is a simplified form of a parse tree, focusing only on the meaningful parts of an
expression.
2. mkleaf(id, entry)
3. mkleaf(num, val)