]> git.saurik.com Git - bison.git/blob - examples/calc++/calc++-scanner.ll
7b1e4ef790eef8081cb40735a8a3ffdd6285d2eb
[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 %{
15 yylloc->step ();
16 # define YY_USER_ACTION yylloc->columns (yyleng);
17 %}
18 {blank}+ yylloc->step ();
19 [\n]+ yylloc->lines (yyleng); yylloc->step ();
20
21 [-+*/] return yytext[0];
22 ":=" return TOKEN_ASSIGN;
23 {int} yylval->ival = atoi (yytext); return TOKEN_NUMBER;
24 {id} yylval->sval = new std::string (yytext); return TOKEN_IDENTIFIER;
25 . driver.error (*yylloc, "invalid character");
26 %%
27
28 void
29 calcxx_driver::scan_begin ()
30 {
31 yy_flex_debug = trace_scanning;
32 if (!(yyin = fopen (file.c_str (), "r")))
33 error (std::string ("cannot open ") + file);
34 }
35
36 void
37 calcxx_driver::scan_end ()
38 {
39 fclose (yyin);
40 }