1 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
---|
2 | * Copyright (C) 2000 Gerwin Klein <[email protected]> *
|
---|
3 | * All rights reserved. *
|
---|
4 | * *
|
---|
5 | * Thanks to Larry Bell and Bob Jamison for suggestions and comments. *
|
---|
6 | * *
|
---|
7 | * This program is free software; you can redistribute it and/or modify *
|
---|
8 | * it under the terms of the GNU General Public License. See the file *
|
---|
9 | * COPYRIGHT for more information. *
|
---|
10 | * *
|
---|
11 | * This program is distributed in the hope that it will be useful, *
|
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
---|
14 | * GNU General Public License for more details. *
|
---|
15 | * *
|
---|
16 | * You should have received a copy of the GNU General Public License along *
|
---|
17 | * with this program; if not, write to the Free Software Foundation, Inc., *
|
---|
18 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
|
---|
19 | * *
|
---|
20 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
---|
21 |
|
---|
22 | %%
|
---|
23 |
|
---|
24 | %byaccj
|
---|
25 |
|
---|
26 | %{
|
---|
27 | private Parser yyparser;
|
---|
28 |
|
---|
29 | public Yylex(java.io.Reader r, Parser yyparser) {
|
---|
30 | this(r);
|
---|
31 | this.yyparser = yyparser;
|
---|
32 | }
|
---|
33 | %}
|
---|
34 |
|
---|
35 | NUM = [0-9]+ ("." [0-9]+)?
|
---|
36 | NL = \n | \r | \r\n
|
---|
37 |
|
---|
38 | %%
|
---|
39 |
|
---|
40 | /* operators */
|
---|
41 | "+" |
|
---|
42 | "-" |
|
---|
43 | "*" |
|
---|
44 | "/" |
|
---|
45 | "^" |
|
---|
46 | "(" |
|
---|
47 | ")" { return (int) yycharat(0); }
|
---|
48 |
|
---|
49 | /* newline */
|
---|
50 | {NL} { return Parser.NL; }
|
---|
51 |
|
---|
52 | /* float */
|
---|
53 | {NUM} { yyparser.yylval = new ParserVal(Double.parseDouble(yytext()));
|
---|
54 | return Parser.NUM; }
|
---|
55 |
|
---|
56 | /* whitespace */
|
---|
57 | [ \t]+ { }
|
---|
58 |
|
---|
59 | \b { System.err.println("Sorry, backspace doesn't work"); }
|
---|
60 |
|
---|
61 | /* error fallback */
|
---|
62 | [^] { System.err.println("Error: unexpected character '"+yytext()+"'"); return -1; }
|
---|