![]() |
VOOZH | about |
Parsing is also known as syntactic analysis, is the process of analyzing a sequence of tokens to determine their grammatical structure according to the rules of a language. It organizes tokens into a parse tree or syntax tree, which represents the structural relationship between different parts of the input.
A parser performs syntactic and semantic analysis of source code by converting tokens into a structured intermediate representation while identifying errors in the code.
The parsing is divided into two types
Top-down parsing builds the parse tree from the start symbol toward the input symbols.
With Backtracking
Without Backtracking
Bottom-up parsing builds the parse tree from input symbols toward the start symbol.
Feature | Top-Down Parsing | Bottom-Up Parsing |
|---|---|---|
Direction | Builds the parse tree from root to leaves | Builds the parse tree from leaves to root |
Derivation | Uses leftmost derivation | Uses rightmost derivation in reverse |
Working Approach | Starts from the start symbol | Starts from the input string |
Efficiency | Simpler but can be slower with backtracking | More efficient for complex grammars |
Complexity | Easier to implement | More complex to implement |
Example Parsers | Recursive Descent Parser, LL Parser | Shift-Reduce Parser, LR Parser |