forked from AnjaneyaTripathi/c-compiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlexer.l
54 lines (49 loc) · 2.81 KB
/
lexer.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
%{
#include "y.tab.h"
int countn=0;
%}
%option yylineno
alpha [a-zA-Z]
digit [0-9]
unary "++"|"--"
%%
"printf" { strcpy(yylval.nd_obj.name,(yytext)); return PRINTFF; }
"scanf" { strcpy(yylval.nd_obj.name,(yytext)); return SCANFF; }
"int" { strcpy(yylval.nd_obj.name,(yytext)); return INT; }
"float" { strcpy(yylval.nd_obj.name,(yytext)); return FLOAT; }
"char" { strcpy(yylval.nd_obj.name,(yytext)); return CHAR; }
"void" { strcpy(yylval.nd_obj.name,(yytext)); return VOID; }
"return" { strcpy(yylval.nd_obj.name,(yytext)); return RETURN; }
"for" { strcpy(yylval.nd_obj.name,(yytext)); return FOR; }
"if" { strcpy(yylval.nd_obj.name,(yytext)); return IF; }
"else" { strcpy(yylval.nd_obj.name,(yytext)); return ELSE; }
^"#include"[ ]*<.+\.h> { strcpy(yylval.nd_obj.name,(yytext)); return INCLUDE; }
"true" { strcpy(yylval.nd_obj.name,(yytext)); return TRUE; }
"false" { strcpy(yylval.nd_obj.name,(yytext)); return FALSE; }
[-]?{digit}+ { strcpy(yylval.nd_obj.name,(yytext)); return NUMBER; }
[-]?{digit}+\.{digit}{1,6} { strcpy(yylval.nd_obj.name,(yytext)); return FLOAT_NUM; }
{alpha}({alpha}|{digit})* { strcpy(yylval.nd_obj.name,(yytext)); return ID; }
{unary} { strcpy(yylval.nd_obj.name,(yytext)); return UNARY; }
"<=" { strcpy(yylval.nd_obj.name,(yytext)); return LE; }
">=" { strcpy(yylval.nd_obj.name,(yytext)); return GE; }
"==" { strcpy(yylval.nd_obj.name,(yytext)); return EQ; }
"!=" { strcpy(yylval.nd_obj.name,(yytext)); return NE; }
">" { strcpy(yylval.nd_obj.name,(yytext)); return GT; }
"<" { strcpy(yylval.nd_obj.name,(yytext)); return LT; }
"&&" { strcpy(yylval.nd_obj.name,(yytext)); return AND; }
"||" { strcpy(yylval.nd_obj.name,(yytext)); return OR; }
"+" { strcpy(yylval.nd_obj.name,(yytext)); return ADD; }
"-" { strcpy(yylval.nd_obj.name,(yytext)); return SUBTRACT; }
"/" { strcpy(yylval.nd_obj.name,(yytext)); return DIVIDE; }
"*" { strcpy(yylval.nd_obj.name,(yytext)); return MULTIPLY; }
\/\/.* { ; }
\/\*(.*\n)*.*\*\/ { ; }
[ \t]* { ; }
[\n] { countn++; }
. { return *yytext; }
["].*["] { strcpy(yylval.nd_obj.name,(yytext)); return STR; }
['].['] { strcpy(yylval.nd_obj.name,(yytext)); return CHARACTER; }
%%
int yywrap() {
return 1;
}