Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
52 views10 pages

Scanning and Parsing-2

SS and Os scanning and parsing

Uploaded by

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

Scanning and Parsing-2

SS and Os scanning and parsing

Uploaded by

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

SCANNING

AND
PARSING
SUBMITT ED BY MAR IYA SHIBI
SCANNING
▪Scanning is the process of recognizing the lexical components in a source
string.
▪ The lexical features of a language can be specified using Type-3 or regular
grammars.
▪This facilitates automatic construction of efficient recognizers for the lexical
features of the language.
▪The scanner generator LEX generates such recognizers from the string
specifications input to it.
.
PARSING
▪ Check the validity of a source string, and to determine its syntactic structure.
▪The process of turning a stream of tokens into a parse tree, according to the rules of grammar.
▪For an invalid string the parser issues diagnostic messages reporting the cause and nature of error(s)
in the string.
▪For a valid string it builds a parse tree to reflect the sequence of derivations or reductions performed
during parsing.

The parse tree is passed on to the subsequent phases of the compiler. The fundamental step in parsing
is to derive a string from an NT, or reduce a string to an NT. This gives rise to two fundamental
approaches to parsing-top down parsing and bottom up parsing, respectively.
▪ Syntax Analyzer (Parser): Syntax analyzer creates the syntactic structure
of the given source program. This syntactic structure is mostly a parse
tree. The syntax of a programming is described by a Context-Free
Grammar (CFG).

▪ The syntax analyzer (parser) checks whether a given source program


satisfies the rules implied by a context-free grammar or not. If it satisfies,
the parser creates the parse tree of that program. Otherwise the parser
gives the error messages.
BOTTOM-UP PARSING
▪Constructs the parse tree from the bottom (leaves) to the top (root).
▪A bottom up parser constructs a parse tree for a source string through a
sequence of reductions.
▪The source string is valid if it can be reduced to S, the distinguished symbol
of G. If not, an error is to be detected and reported during the process of
reduction.
▪Bottom up parsing proceeds in a left-to-right manner, i.e. attempts at
reduction start with the first symbol(s) in the string and proceed to the right.
A typical stage during bottom up parsing is depicted as follows:
Algorithm
1. Identify the handle of the current string form.
2. If a handle exists, reduce it. Go to Step 1.
3. If the current string form = 'S' then exit with success else report error and
exit with failure.
Algorithm-Naïve Bottom Up
Parsing
1. SSM: 1; n :=0;
2.r :=n
3. Compare the string of r symbols to the left of SSM with all RHS alternatives in G which have a length
of r symbols.
4. If a match is found with a production A ::= alpha, then reduce the string of r symbols to the NT A. n:=
n - r + 1 Go to Step 2;
5. r:= r - 1r > 0 go to Step 3;
6. If no more symbols exist to the right of SSM then if current string form =^ S then exit with success
else report error and exit with failure
7. SSM: SSM + 1; n:= n + 1 ; Go to Step 2;

You might also like