-
Notifications
You must be signed in to change notification settings - Fork 2
/
lexer.l
executable file
·62 lines (48 loc) · 1.07 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
62
/*
Chemical Compiler -> Lexical Analyzer File
Author - Shalin Shah
Mentor - Manish K Gupta
Last Modified - 31st March
Date Created - 15th March
*/
%{
#include <stdlib.h>
#include "symbolTable.h"
#include "y.tab.h"
void yyerror(char *);
%}
%option yylineno
IDENTIFIER [a-z][a-z0-9]*
WHITESPACE [ \t]+
%%
0 {
yylval.iValue = atoi(yytext);
return INTEGER;
}
[1-9][0-9]* {
yylval.iValue = atoi(yytext);
return INTEGER;
}
[-()<>=+*/;{}.] {
return *yytext;
}
">=" return GE;
"<=" return LE;
"==" return EQ;
"!=" return NE;
"while" return WHILE;
"if" return IF;
"else" return ELSE;
"print" return PRINT;
{IDENTIFIER} {
yylval.id = (char *) strdup(yytext);
return VARIABLE;
}
{WHITESPACE} ; /* ignore whitespace */
[\n]* {
}
. yyerror("Unknown character");
%%
int yywrap(void) {
return 1;
}