g2o
Loading...
Searching...
No Matches
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 */
9typedef SlamParser::Parser::token token;
10typedef 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;
return static_cast< token_type > * yytext
Definition scanner.l:127
62}
63
64(\+|-)?([0-9]+\.?[0-9]*|\.[0-9]+)([eE](\+|-)?[0-9]+)? {
65 yylval->doubleVal = atof(yytext);
66 return token::DOUBLE;
67}
68
69"ADD" {
70 /*yylval->stringVal = new std::string(yytext, yyleng);*/
71 return token::ADD;
72}
73
74"VERTEX_XYT" {
75 yylval->stringVal = new std::string(yytext, yyleng);
76 return token::V_SE2;
int yyleng
77}
78
79"VERTEX_XYZRPY" {
80 yylval->stringVal = new std::string(yytext, yyleng);
81 return token::V_SE3;
82}
83
84"EDGE_XYT" {
85 yylval->stringVal = new std::string(yytext, yyleng);
86 return token::E_SE2;
87}
88
89"EDGE_XYZRPY" {
90 yylval->stringVal = new std::string(yytext, yyleng);
91 return token::E_SE3;
92}
93
94"FIX" {
95 /*yylval->stringVal = new std::string(yytext, yyleng);*/
96 return token::FIX;
97}
98
99"SOLVE_STATE" {
100 /*yylval->stringVal = new std::string(yytext, yyleng);*/
101 return token::SOLVE_STATE;
102}
103
104"QUERY_STATE" {
105 /*yylval->stringVal = new std::string(yytext, yyleng);*/
106 return token::QUERY_STATE;
107}
108
109[A-Za-z][A-Za-z0-9_,.-]* {
110 yylval->stringVal = new std::string(yytext, yyleng);
111 return token::STRING;
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;
123}
124
125 /* pass all other characters up to bison */
126. {
127 return static_cast<token_type>(*yytext);
128}
129
130 /*** END EXAMPLE - Change the example lexer rules above ***/
131
132%% /*** Additional Code ***/
133
134namespace SlamParser {
135
136Scanner::Scanner(std::istream* in,
137 std::ostream* out)
138 : SlamFlexLexer(in, out)
std::ostream * out
Definition scanner.l:138
139{
140}
141
142Scanner::~Scanner()
143{
144}
145
146void Scanner::set_debug(bool b)
147{
std::ostream out yy_flex_debug
Definition scanner.l:148
149}
150
151}
152
153#ifdef yylex
154#undef yylex
155#endif
156
157int 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
169int SlamFlexLexer::yywrap()
170{
171 //std::cerr << "in SlamFlexLexer::yywrap() !" << std::endl;
172 return 1;
173}