answersLogoWhite

0


Best Answer

/* 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
This answer is:
User Avatar
More answers
User Avatar

Wiki User

βˆ™ 14y ago

source of token separation in c language

This answer is:
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
Related questions

What are tokens in c language?

in c program the smallest individual unit is called c-token


What is a token in the context of a C program?

smallest individual units of a program


Different parts of c language program?

what are the parts of C language program


What has the author David Spuler written?

David Spuler has written: 'Comprehensive C' -- subject(s): C (Computer program language) 'C++ and C efficiency' -- subject(s): C++ (Computer program language), C (Computer program language)


Program for sin series in c language?

find the program in c-pgms.blogspot.com


C program was introduced in the year?

c program was introduced in the year 1972 by Dennis RitchieNo, it was the C language, not the C program.


What has the author Conor Sexton written?

Conor Sexton has written: 'Newnes C++ pocket book' -- subject(s): C (Computer program language), C++ (Computer program language) 'C pocket book' -- subject(s): C (Computer program language) 'Y2K7'


What do you mean by c taken programming in c?

A C program is a computer program written using the C programming language.


What does implicit in c language means?

Implicit in c means compiler understands what and how to do without any reference of any keyword or token.


What has the author Steve Schustack written?

Steve Schustack has written: 'C for fun and profit' -- subject(s): C (Computer program language) 'Variations in C' -- subject(s): C (Computer program language) 'C for fun and profit' -- subject(s): C (Computer program language) 'Variations In C Edition'


Is c an object oriented programing language?

C language is not a program, and it isn't an object-oriented language either.


How there is security in c language?

The c language is as secure or as insecure as the programmer makes it. Security is not in the language; it is in the design of the program.