blob: d8be9403d1e9ac3b1cb9c820358bad41cc3557bc (
plain)
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
%{
#include <string>
#include <map>
#include <iostream>
#include "declarations.h"
#include "language_y.h"
#ifndef YYSTYPE
#define YYSTYPE yy::parser::semantic_type
#endif
#ifndef YYLTYPE
#define YYLTYPE yy::parser::location_type
#endif
using token = yy::parser::token;
#define YY_USER_ACTION yylloc->step(); yylloc->columns(yyleng);
%}
%option debug
%option yylineno
%option noyywrap
%option nounput
%option noinput
%option reentrant
%option bison-bridge
%option bison-locations
identifier [a-zA-Z][_a-zA-Z0-9]*
size_modifier [+*/-][ +*/\-0-9]*
intvalue (0|[1-9][0-9]*)
hexvalue 0[x|X][0-9a-fA-F]+
string_literal \".*\"
%x COMMENT_STATE
%%
/* NOTE:
* Rule ordering is important in order to establist priority. Some
* rules are a superset of other rules and will cause the sub rules to
* never match. Ex. Keywords must always go before identifiers, otherwise
* all keywords will be treated as an identifier.
*/
/* Block Comment */
"/*" { BEGIN(COMMENT_STATE); }
<COMMENT_STATE>"*/" { BEGIN(INITIAL); }
<COMMENT_STATE>[\n]+ { yylloc->lines(yyleng); }
<COMMENT_STATE>. { /* do nothing */ }
/* Line Comment */
"//"[^\r\n]* { /* do nothing */ }
/* Begin reserved keyword definitions */
/* Fields */
"_body_" { return(token::BODY); }
"_payload_" { return(token::PAYLOAD); }
"_size_" { return(token::SIZE); }
"_count_" { return(token::COUNT); }
"_fixed_" { return(token::FIXED); }
"_reserved_" { return(token::RESERVED); }
"_checksum_start_" { return(token::CHECKSUM_START); }
"_padding_" { return(token::PADDING); }
/* Types */
"checksum" { return(token::CHECKSUM); }
"custom_field" { return(token::CUSTOM_FIELD); }
"enum" { return(token::ENUM); }
"group" { return(token::GROUP); }
"packet" { return(token::PACKET); }
"test" { return(token::TEST); }
"struct" { return(token::STRUCT); }
"little_endian_packets" {
yylval->integer = 1;
return token::IS_LITTLE_ENDIAN;
}
"big_endian_packets" {
yylval->integer = 0;
return token::IS_LITTLE_ENDIAN;
}
/* Begin identifier definitions */
{string_literal} {
std::string with_quotes = std::string(yytext);
yylval->string = new std::string(with_quotes.begin() + 1, with_quotes.end() - 1);
return token::STRING;
}
{size_modifier} {
yylval->string = new std::string(yytext);
return token::SIZE_MODIFIER;
}
{identifier} {
yylval->string = new std::string(yytext);
return token::IDENTIFIER;
}
{intvalue} {
yylval->integer = std::stoull(std::string(yytext), nullptr, 10);
return token::INTEGER;
}
{hexvalue} {
yylval->integer = std::stoull(std::string(yytext), nullptr, 16);
return token::INTEGER;
}
/* Begin token definitions */
":" { return(':'); }
"{" { return('{'); }
"}" { return('}'); }
"[" { return('['); }
"]" { return(']'); }
"(" { return('('); }
")" { return(')'); }
"<" { return('<'); }
">" { return('>'); }
"=" { return('='); }
"," { return(','); }
(\n|\r\n)+ { yylloc->lines(yyleng); }
[ \t\f\v]+ { /* Ignore all other whitespace */ }
%%
|