-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlexer.ll
95 lines (89 loc) · 2.27 KB
/
lexer.ll
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
%top {
// VeySicK Lexer by katahiromz
// Copyright (C) 2024 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
// License: MIT
#include "processor.h"
#include "parser.h"
}
%option noyywrap
NEWLINE (\r?\n|\r)
STRING \"[^\"\r\n]*\"?
IDENTIFIER [A-Za-z][A-Za-z0-9_\.]*[\$\#\!\%\?]?@?
OCTAL (&O|&o|&)[0-7]+
HEX (&H|&h)[0-9A-Fa-f]+
DIGITS [0-9]+
REAL ([0-9]+\.[0-9]*|\.[0-9]+)
EXPONENT ({DIGITS}|{REAL})[eEdD][\-\+][0-9]+
NUMERIC ({DIGITS}|{HEX}|{OCTAL}|{REAL}|{EXPONENT})[!#%&]?
%%
REM([ \t]|:).* {
// Line comment as REM statement
yylval = std::make_shared<VskAst>(AST_COMMENT, yytext);
return TK_REM;
}
'.* {
// Line comment by apostrophe
yylval = std::make_shared<VskAst>(AST_COMMENT, yytext);
return TK_REM;
}
{NEWLINE} {
// Newline for old computers
return TK_NEWLINE;
}
{STRING} {
// String literal
yylval = std::make_shared<VskAst>(AST_STRING, yytext);
return TK_STRING;
}
{IDENTIFIER} {
// Identifier or keyword
int token = vsk_token_from_text(yytext);
if (token == TK_IDENTIFIER)
yylval = std::make_shared<VskAst>(AST_IDENTIFIER, yytext);
else
yylval = std::make_shared<VskAst>(AST_KEYWORD, yytext);
return token;
}
{DIGITS} {
// Digits only
yylval = std::make_shared<VskAst>(AST_NUMBER, yytext);
return TK_DIGITS;
}
{NUMERIC} {
// Numeric
yylval = std::make_shared<VskAst>(AST_NUMBER, yytext);
return TK_NUMERIC;
}
"[" { return TK_L_BRACKET; }
"]" { return TK_R_BRACKET; }
"{" { return TK_L_BRACE; }
"}" { return TK_R_BRACE; }
"(" { return TK_L_PAREN; }
")" { return TK_R_PAREN; }
"+" { return TK_PLUS; }
"-" { return TK_MINUS; }
"*" { return TK_ASTERISK; }
"/" { return TK_SLASH; }
"^" { return TK_HAT; }
"#" { return TK_SHARP; }
"$" { return TK_DOLLAR; }
"%" { return TK_PERCENT; }
"~" { return TK_TILDA; }
"|" { return TK_VBAR; }
"\\" { return TK_BACKSLASH; }
";" { return TK_SEMICOLON; }
":" { return TK_COLON; }
"," { return TK_COMMA; }
"?" { return TK_QUESTION; }
"_" { return TK_UNDERLINE; }
"=" { return TK_EQUAL; }
"<>" { return TK_NE; }
"><" { return TK_NE; }
"<=" { return TK_LE; }
"=<" { return TK_LE; }
">=" { return TK_GE; }
"=>" { return TK_GE; }
"<" { return TK_LT; }
">" { return TK_GT; }
"." { return TK_PERIOD; }
[ \t] { }