Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
9Activity
0 of .
Results for:
No results containing your search query
P. 1
Program on Lexical Analysis

Program on Lexical Analysis

Ratings:

3.0

(1)
|Views: 1,869 |Likes:
Published by sriharidino

More info:

Categories:Types, Research
Published by: sriharidino on May 17, 2009
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOC or read online from Scribd
See more
See less

12/14/2012

 
/* Program on lexical analysis */#include<stdio.h>#include<conio.h>#define MAX 30void main(){char str[MAX];int state=0;int i=0, j, startid=0, endid, startcon, endcon;clrscr();for(j=0; j<MAX; j++)str[j]=NULL; //Initialise NULLprintf("*** Program on Lexical Analysis ***");printf("Enter the string: ");gets(str); //Accept input stringstr[strlen(str)]=' ';printf("Analysis:");while(str[i]!=NULL){while(str[i]==' ') //To eliminate spacesi++;switch(state){case 0: if(str[i]=='i') state=1; //if else if(str[i]=='w') state=3; //whileelse if(str[i]=='d') state=8; //doelse if(str[i]=='e') state=10; //elseelse if(str[i]=='f') state=14; //for else if(isalpha(str[i]) || str[i]=='_'){state=17;startid=i;} //identifiers else if(str[i]=='<') state=19;//relational '<' or '<=' else if(str[i]=='>') state=21;//relational '>' or '>='
 
 else if(str[i]=='=') state=23;//relational '==' or assignment '=' else if(isdigit(str[i])){state=25; startcon=i;}//constant else if(str[i]=='(') state=26;//special characters '(' else if(str[i]==')') state=27;//special characters ')' else if(str[i]==';') state=28;//special characters ';' else if(str[i]=='+') state=29;//operator '+' else if(str[i]=='-') state=30;//operator '-'  break;//States for 'if'case 1: if(str[i]=='f') state=2;else { state=17; startid=i-1; i--; }break;case 2: if(str[i]=='(' || str[i]==NULL){printf("if : Keyword");state=0;i--;}else { state=17; startid=i-2; i--; }break;//States for 'while'case 3: if(str[i]=='h') state=4;else { state=17; startid=i-1; i--; }break;case 4: if(str[i]=='i') state=5;else { state=17; startid=i-2; i--; }
 
break;case 5: if(str[i]=='l') state=6;else { state=17; startid=i-3; i--; }break;case 6: if(str[i]=='e') state=7;else { state=17; startid=i-4; i--; }break;case 7: if(str[i]=='(' || str[i]==NULL){printf("while : Keyword");state=0;i--;}else { state=17; startid=i-5; i--; }break;//States for 'do'case 8: if(str[i]=='o') state=9;else { state=17; startid=i-1; i--; }break;case 9: if(str[i]=='{' || str[i]==' ' || str[i]==NULL || str[i]=='('){printf("do : Keyword");state=0;i--;}break;//States for 'else'case 10: if(str[i]=='l') state=11;else { state=17; startid=i-1; i--; }break;case 11: if(str[i]=='s') state=12;else { state=17; startid=i-2; i--; }break;case 12: if(str[i]=='e') state=13;else { state=17; startid=i-3; i--; }break;case 13: if(str[i]=='{' || str[i]==NULL){printf("else : Keyword");state=0;i--;}else { state=17; startid=i-4; i--; }break;

Activity (9)

You've already reviewed this. Edit your review.
1 hundred reads
1 thousand reads
HunTeckuit liked this
Pablo Bastidas liked this
Vikas Jadhav liked this
Usha Sadhani liked this

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->