]> git.saurik.com Git - bison.git/blob - examples/calc++/calc++-scanner.ll
750e6ca7db310670472f9115035bd088cf59bce0
[bison.git] / examples / calc++ / calc++-scanner.ll
1 %{ /* -*- C++ -*- */
2 # include <string>
3 # include "calc++-driver.hh"
4 # include "calc++-parser.hh"
5 %}
6
7 %option noyywrap nounput batch debug
8
9 id [a-zA-Z][a-zA-Z_0-9]*
10 int [0-9]+
11 blank [ \t]
12
13 %{
14 # define YY_USER_ACTION yylloc->columns (yyleng);
15 %}
16 %%
17 %{
18 yylloc->step ();
19 %}
20 {blank}+ yylloc->step ();
21 [\n]+ yylloc->lines (yyleng); yylloc->step ();
22
23 [-+*/] return yytext[0];
24 ":=" return TOKEN_ASSIGN;
25 {int} yylval->ival = atoi (yytext); return TOKEN_NUMBER;
26 {id} yylval->sval = new std::string (yytext); return TOKEN_IDENTIFIER;
27 . driver.error (*yylloc, "invalid character");
28 %%
29
30 void
31 calcxx_driver::scan_begin ()
32 {
33 yy_flex_debug = trace_scanning;
34 if (!(yyin = fopen (file.c_str (), "r")))
35 error (std::string ("cannot open ") + file);
36 }
37
38 void
39 calcxx_driver::scan_end ()
40 {
41 fclose (yyin);
42 }