The parsing is started from the leaf nodes of the tree and works upward till it reaches the root node in Bottom-Up parsing. Parsing starts from a sentence and the production rules are applied in the reverse manner and reach the start symbol. The bottom-up parser is depicted below:
For bottom-up parsing two techniques are used by shift-reducing parsing. These techniques are known as shift-step and reduce-step.
A bottom-up parser which is non-recursive and shift-reduce is LR parser. A context-free grammar is used which facilitates the efficient syntax analysis technique. LR parser is also known as LR(k) parsers, where L stands for left-to-right scanning of the input stream; R stands for the construction of right-most derivation in reverse, and k denotes the number of lookahead symbols for making decisions.
An LR Parser can be constructed by using algorithms such as:
The algorithm of an LR parser is as follows:
LL
|
LR
|
Leftmost derivation is done.
|
Rightmost derivation is done.
|
Starts with the root nonterminal on the stack.
|
Ends with the root nonterminal on the stack.
|
Ends when the stack is empty.
|
Starts with an empty stack.
|
Stack is used for designating the expected.
|
Stack is used for designating the already seen.
|
Parse tree is built top-down.
|
Parse tree is built bottom-up.
|
A nonterminal that is off the stack pops up continuously and the corresponding right hand side is pushed.
|
The right hand side of the stack is recognized, is popped and the corresponding nonterminal is pushed.
|
Non-terminals are expanded.
|
Non-terminals are reduced.
|
When one of the stacks is popped, the terminal is read.
|
When the terminals are pushed on the stack, they are read.
|
Pre-order traversal of the parse tree.
|
Post-order traversal of the parse tree.
|
|
|
Compiler Design Related Tutorials |
|
---|---|
Perl Scripting Tutorial | Python Tutorial |
Unix/Linux Tutorial | VLSI Design Tutorial |
Compiler Design Related Interview Questions |
|
---|---|
Perl Scripting Interview Questions | Python Interview Questions |
Systems Software Interview Questions | Basic Programming Interview Questions |
System Verilog Interview Questions | VHDL Interview Questions |
IBM Integration Bus Interview Questions | Advanced C++ Interview Questions |
Basic C Interview Questions | Unix/Linux Interview Questions |
VLSI Design Interview Questions |
Compiler Design Related Practice Tests |
|
---|---|
Perl Scripting Practice Tests | Python Practice Tests |
Systems Software Practice Tests | Basic Programming Practice Tests |
System Verilog Practice Tests | VHDL Practice Tests |
All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.