-
Notifications
You must be signed in to change notification settings - Fork 1
/
Compiler.l
63 lines (56 loc) · 1.13 KB
/
Compiler.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
%{
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "Abstract_Tree.h"
#include "compiler.tab.h"
%}
extern int line_counter;
%%
"{" return '{';
"}" return '}';
"(" return '(';
")" return ')';
";" return ';';
"." return '.';
"," return ',';
"=" return '=';
"-" return MINUS;
"+" return PLUS;
"*" return MUL;
"/" return DIV;
"<=" return LE;
">=" return GE;
"<" return LT;
">" return GT;
"==" return EQ;
"!=" return NE;
"++" return PP;
"--" return MM;
int return INT;
float return FLOAT;
const return CONST;
if return IF;
else return ELSE;
do return DO;
while return WHILE;
for return FOR;
return return RETURN;
[0-9]+ {
yylval.intval = atoi(yytext);
return INTNUM;
}
[0-9]+.[0-9]+ {
yylval.floatval = atof(yytext);
return FLOATNUM;
}
[A-Za-z][A-Za-z0-9_]* {
yylval.id = strndup(yytext, yyleng);
return ID;
}
[ \t\c] { break;}
"\n" {printf("%d Parsing\n",line_counter++); break;}
[0-9]+[A-Za-z]+ {printf("WARNING at line %d : you can't start your identifier with a number %s \n",line_counter,yytext);
yylval.id = strndup(yytext, yyleng);
return ID;}
%%