Files
bison/examples/calc++/calc++-scanner.ll
Akim Demaille 1c59e0a121 Extract calc++ from the documentation.
* doc/bison.texinfo (Calc++): Add the extraction marks.
* examples/extexi: New, from the aborted GNU Programming 2E.
Separate the different paragraph of a file with empty lines.
* examples/Makefile: Use it to extract the whole calc++ example.
2005-07-05 07:21:30 +00:00

41 lines
876 B
LLVM

%{ /* -*- C++ -*- */
# include <string>
# include "calc++-driver.hh"
# include "calc++-parser.hh"
%}
%option noyywrap nounput batch debug
id [a-zA-Z][a-zA-Z_0-9]*
int [0-9]+
blank [ \t]
%%
%{
yylloc->step ();
# define YY_USER_ACTION yylloc->columns (yyleng);
%}
{blank}+ yylloc->step ();
[\n]+ yylloc->lines (yyleng); yylloc->step ();
[-+*/] return yytext[0];
":=" return TOKEN_ASSIGN;
{int} yylval->ival = atoi (yytext); return TOKEN_NUMBER;
{id} yylval->sval = new std::string (yytext); return TOKEN_IDENTIFIER;
. driver.error (*yylloc, "invalid character");
%%
void
calcxx_driver::scan_begin ()
{
yy_flex_debug = trace_scanning;
if (!(yyin = fopen (file.c_str (), "r")))
error (std::string ("cannot open ") + file);
}
void
calcxx_driver::scan_end ()
{
fclose (yyin);
}