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

Write A Programme To Parse Using Brute Force Technique of Topdown Parsing

The document describes developing a recursive descent parser. It explains that a recursive descent parser is a top-down parser that builds a parse tree from the top down starting with the start non-terminal. It also notes that removing left recursion and left factoring from a grammar results in a grammar that can be parsed with a recursive descent parser. An example grammar is given to illustrate this, showing the grammar before and after removing left recursion.

Uploaded by

SAJAL AGARWAL
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)
742 views

Write A Programme To Parse Using Brute Force Technique of Topdown Parsing

The document describes developing a recursive descent parser. It explains that a recursive descent parser is a top-down parser that builds a parse tree from the top down starting with the start non-terminal. It also notes that removing left recursion and left factoring from a grammar results in a grammar that can be parsed with a recursive descent parser. An example grammar is given to illustrate this, showing the grammar before and after removing left recursion.

Uploaded by

SAJAL AGARWAL
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/ 3

2.

WRITE A PROGRAMME TO PARSE USING BRUTE FORCE TECHNIQUE OF


TOPDOWN PARSING.
#include<iostream.h>
#include<conio.h>
void main()
{
Int a[30];
clrscr();
int min=10000,temp=0,i,lev,n,noofc,z;
printf("please enter how many number");
cin>>n;
for(i=0;i<n;i++)
a[i]=0;
cout<<"enter value of root";
cin>>a[0];
for(i=1;i<=n/2;i++)
{
cout<<"please enter no of child of parent with value"<<a[i-1]<<":";
cin>>noofc;
for(int j=1;j<=noofc;j++)
{
z=(i)*2+j-2;
cout<<"please enter value of child";
cin>>a[z];
}
}
for(i=n-1;i>=n/2;i--)
{
temp=0;
for(int j=i+1;j>=1;j=j/2)
temp=temp+a[j-1];
if(temp<min)
min=temp;
cout<<"temp min is"<<temp<<"\n";
}
cout<<"min is"<<min;
getch();
}
5.DEVELOP A RECURSIVE DESCENT PARSE
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.
Example:
BEFORE REMOVING LEFT AFTER REMOVING LEFT

RECURSION RECURSION

E –> E + T | T E –> T E’

T –> T * F | F E’ –> + T E’ | e

F –> ( E ) | id T –> F T’

T’ –> * F T’ | e

F –> ( E ) | id

You might also like