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