~ubuntu-branches/ubuntu/oneiric/weka/oneiric

« back to all changes in this revision

Viewing changes to .pc/java_cup.patch/src/main/java/weka/core/mathematicalexpression/Scanner.jflex

  • Committer: Bazaar Package Importer
  • Author(s): Soeren Sonnenburg
  • Date: 2010-04-23 22:33:11 UTC
  • Revision ID: james.westby@ubuntu.com-20100423223311-ctmj7n1pqeppqy2a
Tags: 3.6.0-3
* Bump Standards-Version to 3.8.4 (no changes required).
* Switch to dpkg-source 3.0 (quilt) format.
* Track only stable releases in watch file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
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.
 
6
 *
 
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.
 
11
 *
 
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.
 
15
 */
 
16
 
 
17
/*
 
18
 * Scanner.java
 
19
 * Copyright (C) 2008 University of Waikato, Hamilton, New Zealand
 
20
 */
 
21
 
 
22
package weka.core.mathematicalexpression;
 
23
 
 
24
import weka.core.parser.java_cup.runtime.SymbolFactory;
 
25
import java.io.*;
 
26
 
 
27
/**
 
28
 * A scanner for mathematical expressions.
 
29
 *
 
30
 * @author FracPete (fracpete at waikato dot ac dot nz)
 
31
 * @version $Revision: 1.2 $
 
32
 */
 
33
%%
 
34
%cup
 
35
%public
 
36
%class Scanner
 
37
%{
 
38
  // Author: FracPete (fracpete at waikato dot ac dot nz)
 
39
  // Version: $Revision: 1.2 $
 
40
  protected SymbolFactory sf;
 
41
 
 
42
  public Scanner(InputStream r, SymbolFactory sf){
 
43
    this(r);
 
44
    this.sf = sf;
 
45
  }
 
46
%}
 
47
%eofval{
 
48
    return sf.newSymbol("EOF",sym.EOF);
 
49
%eofval}
 
50
 
 
51
%%
 
52
// operands
 
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); }
 
57
 
 
58
// boolean stuff
 
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); }
 
69
 
 
70
// functions
 
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); }
 
83
 
 
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())); }
 
88
 
 
89
// whitespaces
 
90
[ \r\n\t\f] { /* ignore white space. */ }
 
91
 
 
92
// various
 
93
"," { return sf.newSymbol("Comma", sym.COMMA); }
 
94
"(" { return sf.newSymbol("Left Bracket", sym.LPAREN); }
 
95
")" { return sf.newSymbol("Right Bracket", sym.RPAREN); }
 
96
 
 
97
// catch all
 
98
. { System.err.println("Illegal character: "+yytext()); }