Professional Documents
Culture Documents
What Is Syntax Analysis?: Syntax Analysis Is A Second Phase of The Compiler Design Process in
What Is Syntax Analysis?: Syntax Analysis Is A Second Phase of The Compiler Design Process in
What Is Syntax Analysis?: Syntax Analysis Is A Second Phase of The Compiler Design Process in
Parsing Techniques
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.
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
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.
Error – Recovery Methods
Common Errors that occur in Parsing in System Software
A parser should able to detect and report any error found in the program.
So, whenever an error occurred the parser. It should be able to handle it
and carry on parsing the remaining input. A program can have following
types of errors at various compilation process stages. There are five
common error-recovery methods which can be implemented in the parser
Panic-Mode recovery
In the case when the parser encounters an error, this mode ignores
the rest of the statement and not process input from erroneous input
to delimiter, like a semi-colon. This is a simple error recovery method.
In this type of recovery method, the parser rejects input symbols one
by one until a single designated group of synchronizing tokens is
found. The synchronizing tokens generally using delimiters like or.
Phrase-Level Recovery:
Compiler corrects the program by inserting or deleting tokens. This
allows it to proceed to parse from where it was. It performs correction
on the remaining input. It can replace a prefix of the remaining input
with some string this helps the parser to continue the process.
Error Productions
Error production recovery expands the grammar for the language
which generates the erroneous constructs. The parser then performs
error diagnostic about that construct.
Global Correction:
The compiler should make less number of changes as possible while
processing an incorrect input string. Given incorrect input string a and
grammar c, algorithms will search for a parse tree for a related string
b. Like some insertions, deletions, and modification made of tokens
needed to transform an into b is as little as possible.
Grammar:
A grammar is a set of structural rules which describe a language.
Grammars assign structure to any sentence. This term also refers to the
study of these rules, and this file includes morphology, phonology, and
syntax. It is capable of describing many, of the syntax of programming
languages.
The non-terminal symbol should appear to the left of the at least one
production
The goal symbol should never be displayed to the right of the::= of any
production
A rule is recursive if LHS appears in its RHS
Notational Conventions
Notational conventions symbol may be indicated by enclosing the element
in square brackets. It is an arbitrary sequence of instances of the element
which can be indicated by enclosing the element in braces followed by an
asterisk symbol, { ... }*.
It is a choice of the alternative which may use the symbol within the single
rule. It may be enclosed by parenthesis ([,] ) when needed.
Two types of Notational conventions area Terminal and Non-terminals
1.Terminals:
2.Nonterminals:
Grammar Derivation
Grammar derivation is a sequence of grammar rule which transforms the
start symbol into the string. A derivation proves that the string belongs to
the grammar's language.
Left-most Derivation
When the sentential form of input is scanned and replaced in left to right
sequence, it is known as left-most derivation. The sentential form which is
derived by the left-most derivation is called the left-sentential form.
Right-most Derivation
Rightmost derivation scan and replace the input with production rules, from
right to left, sequence. It's known as right-most derivation. The sentential
form which is derived from the rightmost derivation is known as right-
sentential form.
The syntax analyser mainly deals with recursive The lexical analyser eases the task of the syntax
constructs of the language. analyser.
The syntax analyser works on tokens in a source The lexical analyser recognizes the token in a
program to recognize meaningful structures in the source program.
programming language.
It receives inputs, in the form of tokens, from It is responsible for the validity of a token supplied
lexical analysers. by the syntax analyser