%{
#include <stdio.h>
int no=1;
%}
lite [0-9][0-9]*
inv [0-9][a-zA-Z0-9]*
ident [a-zA-Z][a-zA-Z0-9]*
lite2 \"[a-zA-Z][a-zA-Z0-9]*\"
rel <=|<|>=|>
key int|void|char|if|main|printf
%%
{lite} {printf("%s\t%i\tInteger\n",yytext,no);}
{lite2} { char aa[10],bb[10];
strcpy(aa,yytext);
for(int i=1;i<strlen(aa)-1;i++){
bb[i-1]=aa[i];
}
printf("%s\t%i\tLiteral\n",bb,no);
}
{inv} {printf("Invalid:\t%s\n",yytext);}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
{rel} {
printf("%s\t%i\tRelational Operator, \t",yytext,no);
if(strcmp(yytext,"<=")==0){printf("LE");}
if(strcmp(yytext,"<")==0){printf("LT");}
if(strcmp(yytext,">=")==0){printf("LE");}
if(strcmp(yytext,">")==0){printf("LT");}
printf("\n");
}
"+"|"-"|"*"|"/" {printf("%s\t%i\tArithmetic opeator, ",yytext,no);
if(strcmp(yytext,"+")==0){printf("ADD");}
if(strcmp(yytext,"-")==0){printf("SUB");}
if(strcmp(yytext,"/")==0){printf("DIV");}
if(strcmp(yytext,"*")==0){printf("MUL");}
printf("\n");
}
"=" {printf("%s\t%i\tAssignment operator, EQ\n",yytext,no);}
{key} {printf("%s\t%i\tkeyword\n",yytext,no);}
{ident} { printf("%s\t%i\tIdentifier\n",yytext,no);}
"\n" {no++;}
. {}
%%
int main()
{
yyin=fopen("input.txt","r");
printf("Lexeme\tLine\tToken\n");
yylex();
}
JXsKI2luY2x1ZGUgPHN0ZGlvLmg+CmludCBubz0xOwolfQpsaXRlIFswLTldWzAtOV0qCmludiBbMC05XVthLXpBLVowLTldKgppZGVudCBbYS16QS1aXVthLXpBLVowLTldKgpsaXRlMiBcIlthLXpBLVpdW2EtekEtWjAtOV0qXCIKcmVsIDw9fDx8Pj18PgprZXkgaW50fHZvaWR8Y2hhcnxpZnxtYWlufHByaW50ZgolJQp7bG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