0% found this document useful (0 votes)
12 views

Syntax Analysis

Syntax Analysis is the second phase of compiler design, where the input string is checked against the formal grammar rules to ensure correct syntax. It involves creating a parse tree and detecting syntax errors, with two main parsing techniques: Top-Down and Bottom-Up. Top-Down parsing includes predictive and recursive descent methods, while Bottom-Up parsing includes LR, SLR, LALR, and CLR techniques.

Uploaded by

DA Drawcord
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Syntax Analysis

Syntax Analysis is the second phase of compiler design, where the input string is checked against the formal grammar rules to ensure correct syntax. It involves creating a parse tree and detecting syntax errors, with two main parsing techniques: Top-Down and Bottom-Up. Top-Down parsing includes predictive and recursive descent methods, while Bottom-Up parsing includes LR, SLR, LALR, and CLR techniques.

Uploaded by

DA Drawcord
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Compiler Construction

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.

Following are important tasks perform by the parser in compiler design:

 Helps you to detect all types of Syntax errors

 Find the position at which error has occurred

 Clear & accurate description of the error.

 Recovery from an error to continue and find further errors in the


code.

 Should not affect compilation of “correct” programs.

 The parse must reject invalid texts by reporting syntax errors

Parsing Techniques
Compiler Construction

Parsing techniques are divided into two different groups:

 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.

Two types of Top-down parsing are:

1. Predictive Parsing:

Predictive parse can predict which production should be used to


replace the specific input string. The predictive parser uses look-ahead
point, which points towards next input symbols. Backtracking is not an
issue with this parsing technique. It is known as LL(1) Parser

2. Recursive Descent Parsing:

This parsing technique recursively parses the input to make a prase


tree. It consists of several small functions, one for each nonterminal in
the grammar.

Bottom-Up Parsing

In the bottom up parsing in compiler design, the construction of the


parse tree starts with the leave, and then it processes towards its root.
It is also called as shift-reduce parsing. This type of parsing in compiler
design is created with the help of using some software tools.
Compiler Construction

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.

LALR :A Look-Ahead LR (LALR) parser is a software tool used in compiler design


to convert human-readable text into a structured representation that computers
can read. LALR stands for "look ahead left right"

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

Difference between Top Down Parsing and Bottom Up


Parsing
Top-Down Parsing Bottom-Up Parsing

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.

Bottom-up parsing can be defined as an


Top-down parsing attempts to find the left
attempt to reduce the input string to the
most derivations for an input string.
start symbol of a 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.

Example: Recursive Descent parser. Example: Shift Reduce parser.

You might also like