Your Ad Here

Tuesday, August 25, 2009

Lexical Analizer

/* TO IMPLEMENT LEXICAL ANALIZER IN C */

#include< conio.h>
#include< string.h>

void main()
{
int i,j,lc;
char *a[9][4]={"PRG","START" ," " ," ",
" " ,"USING" ,"*" ,"15",
" ","L","1","FIVE",
" ","A","1","FOUR",
" ","ST","1","TEMP",
"FOUR ","DC","F","4",
"FIVE","DC","F","5",
"TEMP","DS","1","F",
" " ,"END"," "," ", };
clrscr();
printf("\n \t\t LEXICAL ANALIZER \n");

for(i=0;i< 9;i++)
{ for(j=0;j< 4;j++)
{ if(isalpha(*a[i][j]))
printf("\n STRING : %s",a[i][j]);
if(isdigit(*a[i][j]))
printf("\n DIGIT : %s",a[i][j]);
}
printf("\n");
}

getch();
}
/* OUTPUT:-

LEXICAL ANALIZER

STRING : PRG
STRING : START

STRING : USING
DIGIT : 15

STRING : L
DIGIT : 1
STRING : FIVE

STRING : A
DIGIT : 1
STRING : FOUR

STRING : ST
DIGIT : 1
STRING : TEMP

STRING : FOUR
STRING : DC
STRING : F
DIGIT : 4

STRING : FIVE
STRING : DC
STRING : F
DIGIT : 5

STRING : TEMP
STRING : DS
DIGIT : 1
STRING : F

STRING : END

*/

1 comment:

CPP Programming said...

Thanks for the efforts on gathering useful content and sharing here. You can find more questions and answers related to C, C++ programming and all other programming languages Q&A in the below forum.

C CPP programming and programming languages Q&A

Your Ad Here