-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path19_tokens.l
34 lines (34 loc) · 874 Bytes
/
19_tokens.l
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
%{
#include<stdio.h>
%}
letter [a-zA-Z_]
digit [0-9]
key (void|main|int|return|printf|float|include)
id {letter}({letter}|{digit})*
num {digit}+
deci {digit}+(.{digit}+)?(E[+|-]?{digit}+)?
lit \".*\"
op "+"|"-"|"*"|"/"|"="
sep "{"|"}"|"("|")"|","
sym "#"|"<"|">"|";"|"."
%%
{key} {fprintf(yyout,"\n %s is a keyword",yytext);}
{id} {fprintf(yyout,"\n %s is an identifier",yytext);}
{deci} {fprintf(yyout,"\n %s is a decimal number",yytext);}
{num} {fprintf(yyout,"\n %s is an integer constant",yytext);}
{op} {fprintf(yyout,"\n %s is an operator",yytext);}
{sep} {fprintf(yyout,"\n %s is a seperator",yytext);}
{lit} {fprintf(yyout,"\n %s is a string literal",yytext);}
{sym} {fprintf(yyout,"\n %s is a special symbol",yytext);}
%%
void main()
{
extern FILE *yyin,*yyout;
yyin=fopen("input.txt","r");
yyout=fopen("output.txt","w");
yylex();
}
int yywrap()
{
return 1;
}