2
* This program is free software; you can redistribute it and/or modify
3
* it under the terms of the GNU General Public License as published by
4
* the Free Software Foundation; either version 2 of the License, or
5
* (at your option) any later version.
7
* This program is distributed in the hope that it will be useful,
8
* but WITHOUT ANY WARRANTY; without even the implied warranty of
9
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
* GNU General Public License for more details.
12
* You should have received a copy of the GNU General Public License
13
* along with this program; if not, write to the Free Software
14
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
* Copyright (C) 2008 University of Waikato, Hamilton, New Zealand
22
package weka.core.mathematicalexpression;
24
import weka.core.parser.java_cup.runtime.SymbolFactory;
28
* A scanner for mathematical expressions.
30
* @author FracPete (fracpete at waikato dot ac dot nz)
31
* @version $Revision: 1.2 $
38
// Author: FracPete (fracpete at waikato dot ac dot nz)
39
// Version: $Revision: 1.2 $
40
protected SymbolFactory sf;
42
public Scanner(InputStream r, SymbolFactory sf){
48
return sf.newSymbol("EOF",sym.EOF);
53
"-" { return sf.newSymbol("Minus", sym.MINUS); }
54
"+" { return sf.newSymbol("Plus", sym.PLUS); }
55
"*" { return sf.newSymbol("Times", sym.TIMES); }
56
"/" { return sf.newSymbol("Division", sym.DIVISION); }
59
"<" { return sf.newSymbol("Less than", sym.LT); }
60
"<=" { return sf.newSymbol("Less or equal than", sym.LE); }
61
">" { return sf.newSymbol("Greater than", sym.GT); }
62
">=" { return sf.newSymbol("Greater or equal than", sym.GE); }
63
"=" { return sf.newSymbol("Equals", sym.EQ); }
64
"!" { return sf.newSymbol("Not", sym.NOT); }
65
"&" { return sf.newSymbol("And", sym.AND); }
66
"|" { return sf.newSymbol("Or", sym.OR); }
67
"true" { return sf.newSymbol("True", sym.TRUE); }
68
"false" { return sf.newSymbol("False", sym.FALSE); }
71
"abs" { return sf.newSymbol("Abs", sym.ABS); }
72
"sqrt" { return sf.newSymbol("Sqrt", sym.SQRT); }
73
"log" { return sf.newSymbol("Log", sym.LOG); }
74
"exp" { return sf.newSymbol("Exp", sym.EXP); }
75
"sin" { return sf.newSymbol("Sin", sym.SIN); }
76
"cos" { return sf.newSymbol("Cos", sym.COS); }
77
"tan" { return sf.newSymbol("Tan", sym.TAN); }
78
"rint" { return sf.newSymbol("Rint", sym.RINT); }
79
"floor" { return sf.newSymbol("Floor", sym.FLOOR); }
80
"pow" { return sf.newSymbol("Pow", sym.POW); }
81
"ceil" { return sf.newSymbol("Ceil", sym.CEIL); }
82
"ifelse" { return sf.newSymbol("IfElse", sym.IFELSE); }
84
// numbers and variables
85
[0-9][0-9]*\.?[0-9]* { return sf.newSymbol("Number", sym.NUMBER, new Double(yytext())); }
86
-[0-9][0-9]*\.?[0-9]* { return sf.newSymbol("Number", sym.NUMBER, new Double(yytext())); }
87
[A-Z]+ { return sf.newSymbol("Variable", sym.VARIABLE, new String(yytext())); }
90
[ \r\n\t\f] { /* ignore white space. */ }
93
"," { return sf.newSymbol("Comma", sym.COMMA); }
94
"(" { return sf.newSymbol("Left Bracket", sym.LPAREN); }
95
")" { return sf.newSymbol("Right Bracket", sym.RPAREN); }
98
. { System.err.println("Illegal character: "+yytext()); }