/* 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;
}
}
}
Chat with our AI personalities
in c program the smallest individual unit is called c-token
c program was introduced in the year 1972 by Dennis RitchieNo, it was the C language, not the C program.
A C program is a computer program written using the C programming language.
Implicit in c means compiler understands what and how to do without any reference of any keyword or token.
C language is not a program, and it isn't an object-oriented language either.