/* $Id: scanner.ll 28 2007-08-20 10:27:39Z tb $ -*- mode: c++ -*- */
/** \file scanner.ll Define the example Flex lexical scanner */
%{
#include <string>
#include "parser.h"
#include "scanner.h"
typedef example::Parser::token token;
typedef example::Parser::token_type token_type;
<http://bugs.debian.org/cgi-bin/bugreport.cgi
#undef yywrap
#define yywrap() 1
#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 noyywrap 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();
std::string quotedstring;
%}
[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;
}