forked from AyatMostafa/Programming-Language
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lexer.l
61 lines (55 loc) · 2.26 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
55
56
57
58
59
60
61
%{
#include "parser.tab.h"
void yyerror (char *s);
int yylex();
%}
%option yylineno
%%
"int" {yylval.string = strdup(yytext); return INT;}
"float" {yylval.string = strdup(yytext); return FLOAT;}
"char" {yylval.string = strdup(yytext); return CHAR;}
"string" {yylval.string = strdup(yytext); return STRING;}
"void" {yylval.string = strdup(yytext); return VOID;}
"const" {yylval.string = strdup(yytext); return CONST;}
"bool" {yylval.string = strdup(yytext); return BOOL;}
"while" {return While;}
"do" {return Do_While;}
"false" {return FALSE;}
"true" {return TRUE;}
"return" {return RET; }
"if" {return IF;}
"else" {return ELSE;}
"switch" {return SWITCH;}
"case" {return CASE;}
"default" {return DEFAULT;}
"break" {return BREAK;}
"for" {return FOR;}
[0-9]+ {yylval.string = atoi(yytext); return integer_value;}
([0-9]*[.])?[0-9]+ { yylval.float_num = atof(yytext);return Float_value;}
['][a-zA-Z]['] {return Char_value;}
\"[\x23-\x7E =\?!\*()<>+/^%~|&@#;{}.]*\" {yylval.string = strdup(yytext);return String_value;}
[_a-zA-Z][_a-zA-Z0-9]{0,30} {yylval.string = strdup(yytext); return identifier;}
[;] {return SEMICOLON;}
[:] {return COLON;}
[,] {return COMMA;}
[=] {return ASSIGN;}
[(] {return OPENBRACKET;}
[)] {return CLOSEBRACKET;}
">=" {return GE;}
"<=" {return LE;}
">" {return G;}
"<" {return L;}
"==" {return EE;}
"!=" {return NE;}
"&&" {return AndAnd;}
"||" {return OrOr;}
"++" {return INC;}
"--" {return DEC;}
"<<" {return SHL;}
">>" {return SHR;}
! {return NOT;}
[-+*/{}^&|;] {return yytext[0];}
[ \t\n] ;
. {ECHO; yyerror ("unexpected character");}
%%
int yywrap (void) {return 1;}