answersLogoWhite

0

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

/* Token Separation */

#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

14y ago

Still curious? Ask our experts.

Chat with our AI personalities

FranFran
I've made my fair share of mistakes, and if I can help you avoid a few, I'd sure like to try.
Chat with Fran
ViviVivi
Your ride-or-die bestie who's seen you through every high and low.
Chat with Vivi
JudyJudy
Simplicity is my specialty.
Chat with Judy
More answers

source of token separation in c language

User Avatar

Wiki User

14y ago
User Avatar

Add your answer:

Earn +20 pts
Q: Program for token separation in c language?
Write your answer...
Submit
Still have questions?
magnify glass
imp