-
Notifications
You must be signed in to change notification settings - Fork 300
Expand file tree
/
Copy pathscanner.l
More file actions
executable file
·106 lines (85 loc) · 2.81 KB
/
Copy pathscanner.l
File metadata and controls
executable file
·106 lines (85 loc) · 2.81 KB
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
96
97
98
99
100
101
102
103
104
105
106
%option nounput
%option noinput
%option nounistd
%option never-interactive
%option noyywrap
%option reentrant
%option extra-type="assembler_parsert *"
%{
#if defined _MSC_VER
// signed/unsigned mismatch
#pragma warning(disable:4365)
// macro re-definition: flex conditonally defines INT32_MAX et al. and thus
// they are set before library headers get to define them
#pragma warning(disable:4005)
#endif
#define PARSER (*yyextra)
#define YYSTYPE unsigned
#undef ECHO
#define ECHO
#include "assembler_parser.h"
#include <util/pragma_wsign_compare.def> // IWYU pragma: keep
#include <util/pragma_wnull_conversion.def> // IWYU pragma: keep
#include <util/pragma_wdeprecated_register.def> // IWYU pragma: keep
/*** macros for easier rule definition **********************************/
%}
delimiter [ \t\b\r]
newline [\n\f\v]|"\\\n"
whitespace {delimiter}+
ws {delimiter}*
ws_or_newline ({delimiter}|{newline})*
ucletter [A-Z]
lcletter [a-z]
letter ({ucletter}|{lcletter})
digit [0-9]
bindigit [01]
octdigit [0-7]
hexdigit [0-9a-fA-F]
identifier (({letter}|"_"|"$"|".")({letter}|{digit}|"_"|"$"|".")*)
integer {digit}+
binary {bindigit}+
bininteger "0"[bB]{bindigit}+{int_suffix}
decinteger [1-9]{digit}*{int_suffix}
octinteger "0"{octdigit}*{int_suffix}
hexinteger "0"[xX]{hexdigit}+{int_suffix}
integer_s {decinteger}|{bininteger}|{octinteger}|{hexinteger}
octchar "\\"{octdigit}{1,3}
hexchar "\\x"{hexdigit}+
escape_sequence [\\][^\n]
c_char [^'\\\n]|{escape_sequence}
s_char [^"\\\n]|{escape_sequence}
char_lit ("L"|"u"|"U")?[']{c_char}+[']
string_lit ("L"|"u"|"U"|"u8")?["]{s_char}*["]
%x GRAMMAR
%x LINE_COMMENT
%%
<INITIAL>.|\n { BEGIN(GRAMMAR);
yyless(0); /* start again with this character */
}
<GRAMMAR>"#" { PARSER.new_instruction(); BEGIN(LINE_COMMENT); } /* begin comment state */
<LINE_COMMENT>{
\n { BEGIN(GRAMMAR); } /* end comment state, back GRAMMAR */
.* { } /* all characters within comments are ignored */
}
<GRAMMAR>{newline} { PARSER.new_instruction(); }
<GRAMMAR>";" { PARSER.new_instruction(); }
<GRAMMAR>{whitespace} { } /* skipped */
/*** keywords ***/
<GRAMMAR>{
".data" { }
}
/*** rest ***/
<GRAMMAR>{
{ws} { /* ignore */ }
{identifier} { irept identifier(ID_symbol);
identifier.set(ID_identifier, yytext);
PARSER.add_token(identifier);
}
">>" { PARSER.add_token(irept(ID_shr)); }
"<<" { PARSER.add_token(irept(ID_shl)); }
. { std::string s;
s+=yytext[0];
PARSER.add_token(irept(s));
}
}
<<EOF>> { yyterminate(); /* done! */ }