answersLogoWhite

0


Best Answer

#include<iostream.h>

#include<conio.h>

#include<string.h>

class parse

{

int nt,t,m[20][20],i,s,n,p1,q,k,j;

char p[30][30],n1[20],t1[20],ch,b,c,f[30][30],fl[30][30];

public:

int scant(char);

int scannt(char);

void process();

void input();

};

int parse::scannt(char a)

{

int c=-1,i;

for(i=0;i<nt;i++)

{

if(n1[i]==a)

{

return i;

}

}

return c;

}

int parse::scant(char b)

{

int c1=-1,j;

for(j=0;j<t;j++)

{

if(t1[j]==b)

{

return j;

}

}

return c1;

}

void parse::input()

{

cout<<"Enter the number of productions:";

cin>>n;

cout<<"Enter the productions one by one"<<endl;

for(i=0;i<n;i++)

cin>>p[i];

nt=0;

t=0;

}

void parse::process()

{

for(i=0;i<n;i++)

{

if(scannt(p[i][0])==-1)

n1[nt++]=p[i][0];

}

for(i=0;i<n;i++)

{

for(j=3;j<strlen(p[i]);j++)

{

if(p[i][j]!='e')

{

if(scannt(p[i][j])==-1)

{

if((scant(p[i][j]))==-1)

t1[t++]=p[i][j];

}

}

}

}

t1[t++]='$';

for(i=0;i<nt;i++)

{

for(j=0;j<t;j++)

m[i][j]=-1;

}

for(i=0;i<nt;i++)

{

cout<<"Enter first["<<n1[i]<<"]:";

cin>>f[i];

}

for(i=0;i<nt;i++)

{

cout<<"Enter follow["<<n1[i]<<"]:";

cin>>fl[i];

}

for(i=0;i<n;i++)

{

p1=scannt(p[i][0]);

if((q=scant(p[i][3]))!=-1)

m[p1][q]=i;

if((q=scannt(p[i][3]))!=-1)

{

for(j=0;j<strlen(f[q]);j++)

m[p1][scant(f[q][j])]=i;

}

if(p[i][3]=='e')

{

for(j=0;j<strlen(fl[p1]);j++)

m[p1][scant(fl[p1][j])]=i;

}

}

for(i=0;i<t;i++)

cout<<"\t"<<t1[i];

cout<<endl;

for(j=0;j<nt;j++)

{

cout<<n1[j];

for(i=0;i<t;i++)

{

cout<<"\t"<<" ";

if(m[j][i]!=-1)

cout<<p[m[j][i]];

}

cout<<endl;

}

}

void main()

{

clrscr();

parse p;

p.input();

p.process();

getch();

}

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Top down parser source code in c plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you Open a text file as C plus plus source code?

All C++ source code is is a text file with the .cpp extension. So if you save your code as *****.cpp then it is automatically C++ source code.


How do you check a user's text input in C plus plus?

Use an SLR parser algorithm.


Source code of DSR and AODV in C plus plus?

code source de dsr sous omnet++4.1 en .cc


What is a source code file in c plus plus?

A source code file is a plain-text file containing C++ instructions. The instructions must be compiled and linked to create a native machine code executable.


What is the differentiate of turbo c from turbo c plus plus?

Turbo C compiles c source. turbo c++ compiles c++ source code.


A c plus plus code name sumcpp saved on a diskis it process or job?

It is neither. It is a source file.


Where do you get c plus plus software?

A good open source IDE for C++ would be Code::Blocks or Notepad++.


Can anyone provide me a executable C or C plus plus language source code for netstat in Windows XP environment?

Netstat for Windows is provided by Microsoft itself, so you're unlikely to find any source code for it. However you may find Linux versions of Netstat source code available. The functionality may differ to some extent, but how useful they are will depend on why you need the source code in the first place.


What do you mean by running of a program in c plus plus?

In order to run a C++ program the program must be compiled and linked to create an executable. It is the executable that actually runs, not the source code. The source code is simply the human-readable code the compiler requires to generate object code for the linker which produces the machine-readable code. However, when the executable is executed within a debugging environment, we can set breakpoints in the source code and step through the source code just as if the source itself were executing, as would be the case if C++ were an interpreted language. Unlike an interpreted language where we can change the source code and see the results immediately, the source code (or at least the portion that has changed) must be recompiled to accommodate the changes.


Bus ticket booking plus java source code?

i need coding for bus booking


Is NotePad Plus Plus a compiler?

Notepad++ is a text editor, not a compiler. You can however, enter source code into Notepad++ and then compile it with a compiler such as GCC.


Can you do c plus plus programming on a mac?

You may use one of several open source compilers and code editors (or even IDEs) to develop and compile C++ code that will operate on a Mac.