-
Notifications
You must be signed in to change notification settings - Fork 0
/
analyser.flex
49 lines (41 loc) · 2.44 KB
/
analyser.flex
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
%{
#include "parser.tab.h"
extern int line_number;
void yyerror (char const *s) {
fprintf (stderr, "%s\n", s);
}
%}
%option noyywrap
%%
"else" {return ELSE;}
"if" {return IF;}
"int" {return INT;}
"return" {return RETURN;}
"void" {return VOID;}
"while" {return WHILE;}
"+" {return ADD;}
"-" {return SUBTRACT;}
"*" {return MULTIPLY;}
"/" {return DIVIDE;}
"<" {return LESS_THAN;}
"<=" {return LESS_THAN_OR_EQUAL;}
">" {return GREATER_THAN;}
">=" {return GREATER_THAN_OR_EQUAL;}
"==" {return EQUAL;}
"!=" {return NOT_EQUAL;}
"=" {return ASSIGNMENT;}
";" {return EOL;}
"," {return COMMA;}
"{" {return LEFT_BRACE;}
"}" {return RIGHT_BRACE;}
"(" {return LEFT_PARANTHESE;}
")" {return RIGHT_PARANTHESE;}
"[" {return LEFT_BRACKET;}
"]" {return RIGHT_BRACKET;}
[ \t\r]+ {;}
[\n] {;}
[/][*]([^*]|\*+[^*/])*\*+"/" {;}
[a-zA-Z][a-zA-Z]* {return ID;}
[0-9][0-9]* {return NUM;}
. {return yytext[0];}
%%