2744expt6 Parser

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

Experiment No.

6
Parser
Aim: Simulate Top-down type of parser (Recursive Descent Parser) for the given grammar.
Software Requirement: 
Turbo C++ / Python /Java
Theory :
Parsing is the process to determine whether the start symbol can derive the program or not. If
the Parsing is successful then the program is a valid program otherwise the program is
invalid. 
There are generally two types of Parsers: 
Top-Down Parsers: 
 In this Parsing technique we expand the start symbol to the whole program.
 Recursive Descent and LL parsers are the Top-Down parsers.
2. Bottom-Up Parsers: 
 In this Parsing technique we reduce the whole program to start symbol.
 Operator Precedence Parser, LR(0) Parser, SLR Parser, LALR Parser and CLR Parser
are the Bottom-Up parsers.

Recursive Descent Parser: 
It is a kind of Top-Down Parser. A top-down parser builds the parse tree from the top to
down, starting with the start non-terminal. A Predictive Parser is a special case of Recursive
Descent Parser, where no Back Tracking is required. 
By carefully writing a grammar means eliminating left recursion and left factoring from it,
the resulting grammar will be a grammar that can be parsed by a recursive descent parser.
The procedure attempts to "match" the right hand side of some production for a non-
terminal.
 To match a terminal symbol, the procedure compares the terminal symbol to the input; if
they agree, then the procedure is successful, and it consumes the terminal symbol in the
input (that is, moves the input cursor over one symbol).
 To match a non-terminal symbol, the procedure simply calls the corresponding procedure
for that non-terminal symbol (which may be a recursive call, hence the name of the
technique).

Algorithm:
1. Read the input string. 
2. Write procedures for the non terminals.
3. Verify the next token equals to non terminals if it satisfies match the non terminal. 
4. If the input string does not match print error.
Conclusion:
Recursive Descent Parser for given grammar has been designed successfully for the given
grammar., by analyzing the grammar details, and applying basic high-level programming
knowledge and taking hardware details into consideration.
LOs achieved: LO3
POs achieved: PO1, PO2, PO3, PO4, PO8, PO10
PSOs achieved: PSO1, PSO2

You might also like