-
Notifications
You must be signed in to change notification settings - Fork 0
/
lexer.lex
50 lines (35 loc) · 1 KB
/
lexer.lex
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
%option noyywrap noinput nounput
%{
#include <string.h>
#include "parser.h"
#include "util.h"
extern YYLTYPE yylloc;
int fileno(FILE *stream);
void update_yylloc() {
size_t i;
yylloc.first_line = yylloc.last_line;
yylloc.first_column = yylloc.last_column;
for (i = 0; i < yyleng; ++i) {
switch (yytext[i]) {
case '\n':
++yylloc.last_line;
yylloc.last_column = 1;
break;
default:
++yylloc.last_column;
}
}
}
%}
S [ \b\n\t\f\r]
W [a-zA-Z_]
D [0-9]
I {W}({W}|{D})*
%%
{S} update_yylloc();
#.*$ update_yylloc();
{I} update_yylloc(); yylval.token = strdup(yytext); return T_IDENTIFIER;
{D}+ update_yylloc(); yylval.token = strdup(yytext); return T_INTEGER;
{D}*\.{D}+ update_yylloc(); yylval.token = strdup(yytext); return T_FLOATING;
\"(\\.|[^"\\])*\" update_yylloc(); yylval.token = strdup(yytext); return T_STRING;
. update_yylloc(); return yytext[0];