Syntax Analysis
Syntax Analysis
Syntax Analysis
Syntax Analysis is a second phase of the compiler design process in which the
given input string is checked for the confirmation of rules and structure of the
formal grammar. It analyses the syntactical structure and checks if the given input
is in the correct syntax of the programming language or not.
Syntax Analysis in Compiler Design process comes after the Lexical analysis phase.
It is also known as the Parse Tree or Syntax Tree. The Parse Tree is developed with
the help of pre-defined grammar of the language. The syntax analyzer also checks
whether a given program fulfills the rules implied by a context-free grammar. If it
satisfies, the parser then creates the parse tree of that source program.
Otherwise, it will display error messages.
Parsing Techniques
Compiler Construction
Top-Down Parsing,
Bottom-Up Parsing
Top-Down Parsing
In the top-down parsing construction of the parse tree starts at the root
and then proceeds towards the leaves.
1. Predictive Parsing:
Bottom-Up Parsing
LR(0):An LR(0) parser is a type of LR parser that stores LR(0) automaton states in
its stack. LR stands for "Left to Right" and "Rightmost derivation". LR parsing is a
bottom-up parsing technique that's often used to parse large grammars.
SLR:In compiler design, an SLR parser is a type of parser that is used to find the
correct bottom-up parse of an input stream. SLR stands for Simple Left-to-right
Rightmost-derivation Parser.
CLR:In compiler design, a CLR parser, also known as a canonical LR parser or LR(1)
parser, is a bottom-up parsing algorithm that analyzes and processes
programming languages. It's based on the LR parsing technique, which stands for
"left-to-right, rightmost derivation in reverse"
Compiler Construction
It is a parsing strategy that first looks at the It is a parsing strategy that first looks at
highest level of the parse tree and works the lowest level of the parse tree and
down the parse tree by using the rules of works up the parse tree by using the rules
grammar. of grammar.
In this parsing technique we start parsing In this parsing technique we start parsing
from the top (start symbol of parse tree) to from the bottom (leaf node of the parse
down (the leaf node of parse tree) in a top- tree) to up (the start symbol of the parse
down manner. tree) in a bottom-up manner.
This parsing technique uses Left Most This parsing technique uses Right Most
Derivation. Derivation.
The main leftmost decision is to select what The main decision is to select when to use
production rule to use in order to construct a production rule to reduce the string to
the string. get the starting symbol.