1 /* $Id: ObScanner.ll 44 2008-10-23 09:03:19Z tb $ -*- mode: c++ -*- */
2 /** \file ObScanner.ll Define the objectbuilder Flex lexical scanner */
4 %{ /*** C/C++ Declarations ***/
9 /* import the parser's token type into a local typedef */
10 typedef objectbuilder::ObParser::token token;
11 typedef objectbuilder::ObParser::token_type token_type;
13 /* By default yylex returns int, we use token_type. Unfortunately yyterminate
14 * by default returns 0, which is not of token_type. */
15 #define yyterminate() return token::END
17 /* This disables inclusion of unistd.h, which is not available under Visual C++
18 * on Win32. The C++ scanner uses STL streams instead. */
19 #define YY_NO_UNISTD_H
23 /*** Flex Declarations and Options ***/
25 /* enable c++ scanner class generation */
28 /* change the name of the scanner class. results in "ObScanner" */
31 /* the manual says "somewhat more optimized" */
34 /* enable scanner to generate debug output. disable this for release
38 /* no support for include files is planned */
39 %option yywrap nounput
41 /* enables the use of start condition stacks */
44 /* The following paragraph suffices to track locations accurately. Each time
45 * yylex is invoked, the begin position is moved onto the end position. */
47 #define YY_USER_ACTION yylloc->columns(yyleng);
50 %% /*** Regular Expressions Part ***/
52 /* code to place at the beginning of yylex() */
58 /*** BEGIN EXAMPLE - Change the objectbuilder lexer rules below ***/
61 yylval->integerVal = atoi(yytext);
62 return token::INTEGER;
66 yylval->doubleVal = atof(yytext);
70 [A-Za-z][A-Za-z0-9_,.-]* {
71 yylval->stringVal = new std::string(yytext, yyleng);
75 /* gobble up white-spaces */
80 /* gobble up end-of-lines */
82 yylloc->lines(yyleng); yylloc->step();
86 /* pass all other characters up to bison */
88 return static_cast<token_type>(*yytext);
91 /*** END EXAMPLE - Change the objectbuilder lexer rules above ***/
93 %% /*** Additional Code ***/
95 namespace objectbuilder {
97 ObScanner::ObScanner(std::istream* in, std::ostream* out)
98 : ObFlexLexer(in, out)
102 ObScanner::~ObScanner()
106 void ObScanner::set_debug(bool b)
113 /* This implementation of ObScanner::yylex() is required to fill the
114 * vtable of the class ObScanner. We define the scanner's main yylex
115 * function via YY_DECL to reside in the ObScanner class instead. */
121 int ObFlexLexer::yylex()
123 std::cerr << "in ObScanner::yylex() !" << std::endl;
127 /* When the scanner receives an end-of-file indication from YY_INPUT, it then
128 * checks the yywrap() function. If yywrap() returns false (zero), then it is
129 * assumed that the function has gone ahead and set up `yyin' to point to
130 * another input file, and scanning continues. If it returns true (non-zero),
131 * then the scanner terminates, returning 0 to its caller. */
133 int ObFlexLexer::yywrap()