-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlexer.l
65 lines (56 loc) · 1.92 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
63
64
%{
/* Lexical analyzer for gpmlang defining some patterns and corresponding
actions*/
#include "y.tab.h"
/* keep track of line number */
int line_number = 1;
//extern char* yytext;
%}
/* definitions */
/* create scanner for line number */
%option yylineno
alpha [a-zA-Z]
digit [0-9]
unary "++"|"--"
%%
"printf" { return PRINTFF; }
"scanf" { return SCANFF; }
"int" { return INT; }
"float" { return FLOAT; }
"char" { return CHAR; }
"void" { return VOID; }
"return" { return RETURN; }
"for" { return FOR; }
"if" { return IF; }
"else" { return ELSE; }
^"#include"[ ]*<.+\.h> { return INCLUDE; }
"true" { return TRUE; }
"false" { return FALSE; }
[-]?{digit}+ { return NUMBER; }
[-]?{digit}+\.{digit}{1,6} { return FLOAT_NUM; }
{alpha}({alpha}|{digit})* { return ID; }
{unary} { return UNARY; }
"<=" { return LE; }
">=" { return GE; }
"==" { return EQ; }
"!=" { return NE; }
">" { return GT; }
"<" { return LT; }
"&&" { return AND; }
"||" { return OR; }
"+" { return ADD; }
"-" { return SUBTRACT; }
"/" { return DIVIDE; }
"*" { return MULTIPLY; }
\/\/.* { ; }
\/\*(.*\n)*.*\*\/ { ; }
[ \t]* { ; }
[\n] { line_number++; }
. { return *yytext; }
["].*["] { return STR; }
['].['] { return CHARACTER; }
%%
/* subroutine */
int yywrap() {
return 1;
}