-
Notifications
You must be signed in to change notification settings - Fork 12
/
yascm_flex.l
72 lines (61 loc) · 1.65 KB
/
yascm_flex.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
65
66
67
68
69
70
71
72
/*
* "yascm_flex.l" yascm lexer.
* Copyright (C) 2015 Hmgle <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
%{
#include "yascm_bison.tab.h"
%}
%option noyywrap
%option always-interactive
DIG [0-9]+
EOL \n|\r\n|\n\r|\r
WS {EOL}|[[:blank:]]
IDENT [!$%&*+\-./:<=>?@^_~[:alnum:]]
CHAR_VAL (newline|space|[^{WS}]|x[0-9A-F]+)
%x EXPECT_CHAR
%x EXPECT_STRING
%%
"(" {return LP;}
")" {return RP;}
"." {return DOT;}
"'" {return QUOTE;}
"#f" {return FALSE_T;}
"#t" {return TRUE_T;}
{WS}* /* do nothing with white space */
;.*$ /* Scheme comment */
<<EOF>> {return END_OF_FILE;}
[-]?{DIG} {
yylval.n = strtoll(yytext, NULL, 10);
return FIXNUM_T;
}
[-]?{DIG}?"."{DIG} {
yylval.d = strtod(yytext, NULL);
return FLOATNUM_T;
}
#\\ {BEGIN(EXPECT_CHAR);}
<EXPECT_CHAR>{CHAR_VAL} {
BEGIN(INITIAL);
yylval.c = *yytext;
return CHAR_T;
}
\" {BEGIN(EXPECT_STRING); return DOUBLE_QUOTE;}
<EXPECT_STRING>([^\\\"]|\\.)* {
yylval.s = yytext;
return STRING_T;
}
<EXPECT_STRING>\" {BEGIN(INITIAL); return DOUBLE_QUOTE;}
{IDENT}+ {yylval.s = yytext; return SYMBOL_T;}
%%