-
Notifications
You must be signed in to change notification settings - Fork 0
/
lexer.l
61 lines (41 loc) · 1.14 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
/* DEFINITONS SECTION */
%{
#ifndef YYSTYPE
#define YYSTYPE double
#endif
#include <stdio.h>
#include "parser.tab.h"
%}
/* substitutions */
DEC_DIGIT [0-9]
HEX_DIGIT [0-9a-fA-F]
FLOAT {DEC_DIGIT}+\.{DEC_DIGIT}*([eE][-+]?{DEC_DIGIT}+)?
/* RULES Section */
%% /*delimiters of the sections*
0[xX]{HEX_DIGIT}+|{DEC_DIGIT}+ {
long int x = strtol(yytext, NULL, 0);
yylval = x;
fprintf(stderr, "read token %d\n", x);
return INTEGER;
}
{FLOAT} {
yylval = strtod(yytext, NULL);
fprintf(stderr, "read token %.10g\n", yylval);
return FLOATING_NUMBER;
}
[-+*/^\n] {
yylval = *yytext; /* one character */
fprintf(stderr, "read token %c\n", *yytext);
return *yytext;
}
[( )\t] {
fprintf(stderr, "read token %c\n", *yytext);
}; /* skip whitespaces */
"exit" {
printf("The developer loves YOU <3, BYE!! ^_^");
return 0;
};
. yyerror("invalid character");
%% /*delimiters of the sections*
/* C-code Section */
int yywrap(void) {return 1;}