mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-27 21:23:03 +00:00
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.
This commit is contained in:
45
examples/calc++/calc++-scanner.ll
Normal file
45
examples/calc++/calc++-scanner.ll
Normal file
@@ -0,0 +1,45 @@
|
||||
%{ /* -*- 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);
|
||||
}
|
||||
Reference in New Issue
Block a user