Introduction to Parsers (original) (raw)

Last Updated : 29 May, 2026

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.

Parsing

Parsing

Role of Parser

A parser performs syntactic and semantic analysis of source code by converting tokens into a structured intermediate representation while identifying errors in the code.

Types of Parsing

The parsing is divided into two types

parsers

Types of Parsers

1. Top-Down Parsing

Top-down parsing builds the parse tree from the start symbol toward the input symbols.

Types of Top-Down Parsing

**With Backtracking

**Without Backtracking

2. Bottom-Up Parsing

Bottom-up parsing builds the parse tree from input symbols toward the start symbol.

Types of Bottom-Up Parsing

Bottom-Up vs Top-Down Parser

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