Files
bison/examples/calc++/calc++-scanner.ll
Akim Demaille 0ffd4fd1a2 Start a set of simple examples.
* examples/calc++/Makefile, examples/calc++/calc++-driver.cc,
* examples/calc++/calc++-driver.hh,
* examples/calc++/calc++-parser.yy,
* examples/calc++/calc++-scanner.ll, examples/calc++/calc++.cc,
* examples/calc++/compile, examples/calc++/test: New.
2005-06-22 15:32:10 +00:00

46 lines
915 B
LLVM

%{ /* -*- C++ -*- */
# include <string>
# include <cerrno>
# include "calc++-driver.hh"
# include "calc++-parser.hh"
%}
%option noyywrap nounput debug batch
id [a-zA-Z][a-zA-Z_0-9]*
int [0-9]+
blank [ \t]
%%
%{
# define YY_USER_ACTION yylloc->columns (yyleng);
yylloc->step ();
%}
{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);
}