Implementation of Lexical Analyzer

%{

int lc=0;

%}
%%
printf printf("\nPrintf found at line no. %d",lc);

scanf  printf("\nScanf found at line no. %d",lc);

if |
else |
while |
do |
switch |
case |
for |
return printf("\n%s Keyword found at line no. %d ",yytext,lc);

"void main" printf("\n%s Keyword found at line no. %d ",yytext,lc);



\"[^"]*\" printf("\nQuoted string found at line no. %d",lc);

#include |
#include<stdio.h> printf("\nHeader found at line no. %d",lc);

int |
float |
char |
double |
long printf("\n%s Datatype found at line no. %d",yytext,lc);

";" |
"," |
":" |
"{" |
"}" |
"(" |
")" |
"." printf("\n%s Punctuation Symbol found at line no. %d",yytext,lc);

[a-z]+[a-z,0-9]* printf("\n %s Variable found at line no. %d\n",yytext,lc);

[0-9]+ printf("\n%s Number found at line no. %d",yytext,lc);

"=" |
"+" |
"-" |
"/" |
"*" |
"<" |
">" printf("\n%s OPERATOR found at line no. %d",yytext,lc);

\n lc++;

%%

int main(argc,argv)
int argc;
char **argv;
{

if(argc>1)
{
FILE *f;
f = fopen(argv[1],"r");
if(!f)
{
}
yyin=f;
}
yylex();
return 0;
}
yywrap()
{
return 1;
}



























Popular posts from this blog

DDL DML DCL and TCL

Implementation of Calculator using lex and yacc

A Register Allocation algorithm that translates the given code into one with a fixed number of registers.