g2o
Toggle main menu visibility
Loading...
Searching...
No Matches
g2o
examples
interactive_slam
slam_parser
parser
scanner.l
Go to the documentation of this file.
1
%{ /*** C/C++ Declarations ***/
2
3
#include <vector>
4
#include <string>
5
6
#include "scanner.h"
7
8
/* import the parser's token type into a local typedef */
9
typedef SlamParser::Parser::token token;
10
typedef SlamParser::Parser::token_type token_type;
11
12
/* By default yylex returns int, we use token_type. Unfortunately yyterminate
13
* by default returns 0, which is not of token_type. */
14
#define yyterminate() return token::END
15
16
/* This disables inclusion of unistd.h, which is not available under Visual C++
17
* on Win32. The C++ scanner uses STL streams instead. */
18
#define YY_NO_UNISTD_H
19
20
%}
21
22
/*** Flex Declarations and Options ***/
23
24
/* enable c++ scanner class generation */
25
%option c++
26
27
/* change the name of the scanner class. results in "SlamFlexLexer" */
28
%option prefix="Slam"
29
30
/* the manual says "somewhat more optimized" */
31
%option batch
32
33
/* enable scanner to generate debug output. disable this for release
34
* versions. */
35
/*%option debug*/
36
37
/* no support for include files is planned */
38
%option yywrap nounput
39
40
/* enables the use of start condition stacks */
41
%option stack
42
43
/* The following paragraph suffices to track locations accurately. Each time
44
* yylex is invoked, the begin position is moved onto the end position. */
45
%{
46
#define YY_USER_ACTION yylloc->columns(yyleng);
47
%}
48
49
%% /*** Regular Expressions Part ***/
50
51
/* code to place at the beginning of yylex() */
52
%{
53
// reset location
54
yylloc->step();
55
%}
56
57
/*** BEGIN EXAMPLE - Change the example lexer rules below ***/
58
59
("+"|"-")?[0-9]+ {
60
yylval->integerVal = atoi(
yytext
);
61
return
token::INTEGER
;
yytext
return static_cast< token_type > * yytext
Definition
scanner.l:127
SlamParser::Parser::token::INTEGER
@ INTEGER
Definition
bison_parser.h:236
62
}
63
64
(\+|-)?([0-9]+\.?[0-9]*|\.[0-9]+)([eE](\+|-)?[0-9]+)? {
65
yylval->doubleVal = atof(
yytext
);
66
return
token::DOUBLE
;
SlamParser::Parser::token::DOUBLE
@ DOUBLE
Definition
bison_parser.h:237
67
}
68
69
"ADD" {
70
/*yylval->stringVal = new std::string(yytext, yyleng);*/
71
return
token::ADD
;
SlamParser::Parser::token::ADD
@ ADD
Definition
bison_parser.h:239
72
}
73
74
"VERTEX_XYT" {
75
yylval->stringVal =
new
std::string(
yytext
,
yyleng
);
76
return
token::V_SE2
;
yyleng
int yyleng
SlamParser::Parser::token::V_SE2
@ V_SE2
Definition
bison_parser.h:240
77
}
78
79
"VERTEX_XYZRPY" {
80
yylval->stringVal =
new
std::string(
yytext
,
yyleng
);
81
return
token::V_SE3
;
SlamParser::Parser::token::V_SE3
@ V_SE3
Definition
bison_parser.h:241
82
}
83
84
"EDGE_XYT" {
85
yylval->stringVal =
new
std::string(
yytext
,
yyleng
);
86
return
token::E_SE2
;
SlamParser::Parser::token::E_SE2
@ E_SE2
Definition
bison_parser.h:242
87
}
88
89
"EDGE_XYZRPY" {
90
yylval->stringVal =
new
std::string(
yytext
,
yyleng
);
91
return
token::E_SE3
;
SlamParser::Parser::token::E_SE3
@ E_SE3
Definition
bison_parser.h:243
92
}
93
94
"FIX" {
95
/*yylval->stringVal = new std::string(yytext, yyleng);*/
96
return
token::FIX
;
SlamParser::Parser::token::FIX
@ FIX
Definition
bison_parser.h:244
97
}
98
99
"SOLVE_STATE" {
100
/*yylval->stringVal = new std::string(yytext, yyleng);*/
101
return
token::SOLVE_STATE
;
SlamParser::Parser::token::SOLVE_STATE
@ SOLVE_STATE
Definition
bison_parser.h:245
102
}
103
104
"QUERY_STATE" {
105
/*yylval->stringVal = new std::string(yytext, yyleng);*/
106
return
token::QUERY_STATE
;
SlamParser::Parser::token::QUERY_STATE
@ QUERY_STATE
Definition
bison_parser.h:246
107
}
108
109
[A-Za-z][A-Za-z0-9_,.-]* {
110
yylval->stringVal =
new
std::string(
yytext
,
yyleng
);
111
return
token::STRING
;
SlamParser::Parser::token::STRING
@ STRING
Definition
bison_parser.h:238
112
}
113
114
/* gobble up white-spaces */
115
[ \t\r]+ {
116
yylloc->step();
117
}
118
119
/* gobble up end-of-lines */
120
\n {
121
yylloc->lines(
yyleng
); yylloc->step();
122
return
token::EOL
;
SlamParser::Parser::token::EOL
@ EOL
Definition
bison_parser.h:235
123
}
124
125
/* pass all other characters up to bison */
126
. {
127
return
static_cast<
token_type
>
(*yytext);
token_type
SlamParser::Parser::token_type token_type
Definition
flex_scanner.cpp:429
128
}
129
130
/*** END EXAMPLE - Change the example lexer rules above ***/
131
132
%% /*** Additional Code ***/
133
134
namespace SlamParser {
135
136
Scanner::Scanner(std::istream* in,
137
std::ostream*
out
)
138
: SlamFlexLexer(in,
out
)
out
std::ostream * out
Definition
scanner.l:138
139
{
140
}
141
142
Scanner::~Scanner()
143
{
144
}
145
146
void Scanner::set_debug(bool b)
147
{
148
yy_flex_debug
= b;
yy_flex_debug
std::ostream out yy_flex_debug
Definition
scanner.l:148
149
}
150
151
}
152
153
#ifdef yylex
154
#undef yylex
155
#endif
156
157
int SlamFlexLexer::yylex()
158
{
159
std::cerr <<
"in SlamFlexLexer::yylex() !"
<< std::endl;
160
return
0;
161
}
162
163
/* When the scanner receives an end-of-file indication from YY_INPUT, it then
164
* checks the yywrap() function. If yywrap() returns false (zero), then it is
165
* assumed that the function has gone ahead and set up `yyin' to point to
166
* another input file, and scanning continues. If it returns true (non-zero),
167
* then the scanner terminates, returning 0 to its caller. */
168
169
int SlamFlexLexer::yywrap()
170
{
171
//std::cerr << "in SlamFlexLexer::yywrap() !" << std::endl;
172
return
1;
173
}
Generated on
for g2o by
1.17.0