answersLogoWhite

0


Best Answer

\\ Token Separation \\

Write a program to identify and generate the tokens present in the given input

#include<stdio.h>

#include<conio.h>

#include<string.h>

#include<iostream.h>

int key = 0;

char expr[100];

char cont[][20]={"CONTROLS","for","do","while","NULL",};

char cond[][20]={"CONDITION","if","then","NULL"};

char oprt[][20]={"OPERATOR","+","-","*","/","%","<","<=",">",">=","=","(",")","NULL"};

char branch[][20]={"BRANCHING","goto","jump" ,"NULL"};

void checking(char[],char[][20]);

void main()

{

int i,j,l,k,m,n;

char sbexpr[50],txt[3];

clrscr();

cout<<"Enter the expression:";

gets(expr);

for(i=0;expr[i]!=NULL;i++)

{

key=0;

for(j=i,k=0;expr[j]!=32 && expr[j]!=NULL;i++,j++,k++)

sbexpr[k]=expr[j];

sbexpr[k]=NULL;

if(key==0) checking(sbexpr,cond);

if(key==0) checking(sbexpr,cont);

if(key==0) checking(sbexpr,branch);

if(key==0)

{

for(m=0;sbexpr[m]!=NULL;m++)

{

key=0;

txt[0]= sbexpr[m];

txt[1] = NULL;

if(key==0) checking(txt,oprt);

if((key==0) ((sbexpr[m]>=97 && sbexpr[m]<=122) (sbexpr[m]>=65 && sbexpr[m]<=90)))

{

cout<<"\n"<<sbexpr[m]<<"------->"<<"Identifier\n";

key = 1;

}

}

}

if(key == 0)

{

cout<<"\n"<<sbexpr<<"------->"<<"Address\n";

key = 1;

}

}

getch();

}

void checking (char expr[],char check[][20])

{

for(int i=1;strcmp(check[i],"NULL")!=0;i++)

{

if(strcmp(expr,check[i])==0)

{

cout<<expr<<"------>"<<check[0]<<"\n";

key = 1;

}

}

}

User Avatar

Wiki User

16y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago

#include
#include
#include
#include

int key = 0;
char expr[100];
char cont[][20]={"CONTROLS","for","do","while","NULL",};
char cond[][20]={"CONDITION","if","then","NULL"};
char oprt[][20]={"OPERATOR","+","-","*","/","%","<","<=",">",">=","=","(",")","NULL"};
char branch[][20]={"BRANCHING","goto","jump" ,"NULL"};
void checking(char[],char[][20]);
void main()
{
int i,j,l,k,m,n;
char sbexpr[50],txt[3];
clrscr();
cout<<"Enter the expression:";
gets(expr);
for(i=0;expr[i]!=NULL;i++)
{
key=0;
for(j=i,k=0;expr[j]!=32 && expr[j]!=NULL;i++,j++,k++)
sbexpr[k]=expr[j];
sbexpr[k]=NULL;
if(key==0) checking(sbexpr,cond);
if(key==0) checking(sbexpr,cont);
if(key==0) checking(sbexpr,branch);
if(key==0)
{
for(m=0;sbexpr[m]!=NULL;m++)
{
key=0;
txt[0]= sbexpr[m];
txt[1] = NULL;
if(key==0) checking(txt,oprt);
if((key==0) ((sbexpr[m]>=97 && sbexpr[m]<=122) (sbexpr[m]>=65 && sbexpr[m]<=90)))
{
cout<<"\n"<"<<"Identifier\n";
key = 1;
}
}
}
if(key == 0)
{
cout<<"\n"<"<<"Address\n";
key = 1;
}
}

getch();
}


void checking (char expr[],char check[][20])
{
for(int i=1;strcmp(check[i],"NULL")!=0;i++)
{
if(strcmp(expr,check[i])==0)
{
cout<"<key = 1;
}
}
}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Token separation source code in C Plus Plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

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.


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

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.


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.


How do you get a wish token out of the wall on webkinz?

this is how to get a wish token! you have to buy a webkinz and then when you put it on you get a free wish token! to get a wish token with out buying an animal you have to be at the code shop yo enter a code the best way is buying a webkinz


Where is my code in Ninja Saga?

Token


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 is 34 code in ninja saga?

code claim saga token-03C20DB76A5B6D588478918574EB963C70


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.


What is the Ontario building code fire separation?

what is fire separation distance