C program for Lexical Analyzer
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<ctype.h>
struct pgm
{
char line[20];
} s[100];
void check(char s[])
{
cout<<"\n";
if(!strcmpi(s,"If"))
{
cout<<"keyword:If";
return;
}
if(!strcmpi(s,"Then"))
{
cout<<"keyword:Then";
return;
}
if(!strcmpi(s,"Else"))
{
cout<<"keyword:else";
return;
}
if(!strcmpi(s,"[END]"))
{
return;
}
cout<<"expression:"<<s;
}
void main()
{
char t[20];
int i=0,j=0,k=0;
clrscr();
cout<<"\n\n enter the program code:(to stop input type End)\n";
do
{
gets(s[i].line);
}
while(strcmpi(s[i++].line,"END"));
k = k-1;
do
{
k++;
for(i=0;s[k].line[i]!='\0';i++,j++)
{
if(s[k].line[i]==' ')
{
t[j]='\0';
j=-1;
check(t);
}
else
t[j]=s[k].line[i];
}
t[j]='\0';
j=0;
check(t);
}
while(strcmpi(s[k].line,"END"));
getch();
} |
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<ctype.h>
struct pgm
{
char line[20];
} s[100];
void check(char s[])
{
cout<<"\n";
if(!strcmpi(s,"If"))
{
cout<<"keyword:If";
return;
}
if(!strcmpi(s,"Then"))
{
cout<<"keyword:Then";
return;
}
if(!strcmpi(s,"Else"))
{
cout<<"keyword:else";
return;
}
if(!strcmpi(s,"[END]"))
{
return;
}
cout<<"expression:"<<s;
}
void main()
{
char t[20];
int i=0,j=0,k=0;
clrscr();
cout<<"\n\n enter the program code:(to stop input type End)\n";
do
{
gets(s[i].line);
}
while(strcmpi(s[i++].line,"END"));
k = k-1;
do
{
k++;
for(i=0;s[k].line[i]!='\0';i++,j++)
{
if(s[k].line[i]==' ')
{
t[j]='\0';
j=-1;
check(t);
}
else
t[j]=s[k].line[i];
}
t[j]='\0';
j=0;
check(t);
}
while(strcmpi(s[k].line,"END"));
getch();
}
Editorial Team
We are a group of young techies trying to provide the best study material for all Electronic and Computer science students. We are publishing Microcontroller projects, Basic Electronics, Digital Electronics, Computer projects and also c/c++, java programs.
send me output plz………….!
how to implement this program….can you provide me a brief way to execute this program…
ni ho rha bhai….kya tum bhi asa program rkhte ho….
tume bhi ata he ki ase hi…
please send its output