Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(120)

Side by Side Diff: bison/src/bison/2.4.1/bison-2.4.1-src/examples/calc++/calc++-scanner.ll

Issue 10807020: Add native Windows binary for bison. (Closed) Base URL: svn://chrome-svn/chrome/trunk/deps/third_party/
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 %{ /* -*- C++ -*- */
2 # include <cstdlib>
3 # include <errno.h>
4 # include <limits.h>
5 # include <string>
6 # include "calc++-driver.hh"
7 # include "calc++-parser.hh"
8
9 /* Work around an incompatibility in flex (at least versions
10 2.5.31 through 2.5.33): it generates code that does
11 not conform to C89. See Debian bug 333231
12 <http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=333231>. */
13 # undef yywrap
14 # define yywrap() 1
15
16 /* By default yylex returns int, we use token_type.
17 Unfortunately yyterminate by default returns 0, which is
18 not of token_type. */
19 #define yyterminate() return token::END
20 %}
21
22 %option noyywrap nounput batch debug
23
24 id [a-zA-Z][a-zA-Z_0-9]*
25 int [0-9]+
26 blank [ \t]
27
28 %{
29 # define YY_USER_ACTION yylloc->columns (yyleng);
30 %}
31 %%
32 %{
33 yylloc->step ();
34 %}
35 {blank}+ yylloc->step ();
36 [\n]+ yylloc->lines (yyleng); yylloc->step ();
37
38 %{
39 typedef yy::calcxx_parser::token token;
40 %}
41 /* Convert ints to the actual type of tokens. */
42 [-+*/] return yy::calcxx_parser::token_type (yytext[0]);
43 ":=" return token::ASSIGN;
44 {int} {
45 errno = 0;
46 long n = strtol (yytext, NULL, 10);
47 if (! (INT_MIN <= n && n <= INT_MAX && errno != ERANGE))
48 driver.error (*yylloc, "integer is out of range");
49 yylval->ival = n;
50 return token::NUMBER;
51 }
52 {id} yylval->sval = new std::string (yytext); return token::IDENTIFIER;
53 . driver.error (*yylloc, "invalid character");
54 %%
55
56 void
57 calcxx_driver::scan_begin ()
58 {
59 yy_flex_debug = trace_scanning;
60 if (file == "-")
61 yyin = stdin;
62 else if (!(yyin = fopen (file.c_str (), "r")))
63 {
64 error (std::string ("cannot open ") + file);
65 exit (1);
66 }
67 }
68
69 void
70 calcxx_driver::scan_end ()
71 {
72 fclose (yyin);
73 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698