/* $Id: scanner.ll 44 2008-10-23 09:03:19Z tb $ -*- mode: c++ -*- */
/** \file scanner.ll Define the example Flex lexical scanner */
%{
#include <string>
#include "scanner.h"
typedef example::Parser::token token;
typedef example::Parser::token_type token_type;
#define yyterminate() return token::END
#define YY_NO_UNISTD_H
%}
/*** Flex Declarations and Options ***/
/* enable c++ scanner class generation */
%option c++
/* change the name of the scanner class. results in "ExampleFlexLexer" */
%option prefix="Example"
/* the manual says "somewhat more optimized" */
%option batch
/* enable scanner to generate debug output. disable this for release
* versions. */
%option debug
/* no support for include files is planned */
%option yywrap nounput
/* enables the use of start condition stacks */
%option stack
/* The following paragraph suffices to track locations accurately. Each time
* yylex is invoked, the begin position is moved onto the end position. */
%{
#define YY_USER_ACTION yylloc->columns(yyleng);
%}
%%
%{
yylloc->step();
%}
[0-9]+ {
yylval->integerVal = atoi(yytext);
return token::INTEGER;
}
[0-9]+"."[0-9]* {
yylval->doubleVal = atof(yytext);
return token::DOUBLE;
}
[A-Za-z][A-Za-z0-9_,.-]* {
yylval->stringVal = new std::string(yytext, yyleng);
return token::STRING;
}
[ \t\r]+ {
yylloc->step();
}
\n {
yylloc->lines(yyleng); yylloc->step();
return token::EOL;
}
. {
return static_cast<token_type>(*yytext);
}
%%
namespace example {
Scanner::Scanner(std::istream* in,
std::ostream* out)
: ExampleFlexLexer(in, out)
{
}
Scanner::~Scanner()
{
}
void Scanner::set_debug(bool b)
{
yy_flex_debug = b;
}
}
#ifdef yylex
#undef yylex
#endif
int ExampleFlexLexer::yylex()
{
std::cerr << "in ExampleFlexLexer::yylex() !" << std::endl;
return 0;
}
int ExampleFlexLexer::yywrap()
{
return 1;
}