Back to index

wims  3.65+svn20090927
LinearParserEvent.java
Go to the documentation of this file.
00001 /*
00002 $Id: LinearParserEvent.java,v 1.3 2003/02/18 11:48:46 sander Exp $
00003 */
00004 
00005 
00006 /*
00007 Copyright (C) 2001-2002 Mainline Project (I3S - ESSI - CNRS -UNSA)
00008 
00009 This library is free software; you can redistribute it and/or
00010 modify it under the terms of the GNU Lesser General Public
00011 License as published by the Free Software Foundation; either
00012 version 2.1 of the License, or (at your option) any later version.
00013 
00014 This library is distributed in the hope that it will be useful,
00015 but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 Lesser General Public License for more details.
00018 
00019 You should have received a copy of the GNU Lesser General Public
00020 License along with this library; if not, write to the Free Software
00021 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 
00023 For further information on the GNU Lesser General Public License,
00024 see: http://www.gnu.org/copyleft/lesser.html
00025 For further information on this library, contact: mainline@essi.fr
00026 */
00027 
00028 
00029 package fr.ove.openmath.jome.ctrl.linear.events;
00030 
00031 import java.util.EventObject;
00032 
00080 public class LinearParserEvent extends EventObject {
00084     private int identifier;
00085 
00089     private String value;
00090 
00095     public LinearParserEvent(Object src) {
00096         super(src);
00097     }
00098 
00104     public void setToken(int identifier, String value) {
00105         this.identifier = identifier;
00106         this.value = value;
00107     }
00108 
00112     public int getIdentifier() {
00113         return identifier;
00114     }
00115 
00119     public String getIdentifierAsString() {
00120         String str = "";
00121 
00122         switch (identifier) {
00123             case SPACE : str += "SPACE"; break;
00124             case VARIABLE : str += "VARIABLE"; break;
00125             case INTEGER  : str += "INTEGER"; break;
00126             case FLOAT    : str += "FLOAT"; break;
00127             case ADDITION : str += "ADDITION"; break;
00128             case SUBSTRACTION : str += "SUBSTRACTION"; break;
00129             case MULTIPLICATION: str += "MULTIPLICATION"; break;
00130             case DIVISION : str += "DIVISION"; break;
00131             case POWER    : str += "POWER"; break;
00132             case EQUAL    : str += "EQUAL"; break;
00133             case UNEQUAL  : str += "UNEQUAL"; break;
00134             case LESS     : str += "LESS"; break;
00135             case LESSEQUAL  : str += "LESSEQUAL"; break;
00136             case GREATER  : str += "GREATER"; break;
00137             case GREATEREQUAL : str += "GREATEREQUAL"; break;
00138             case FUNCTION : str += "FUNCTION"; break;
00139             case SEPARATOR : str += "SEPARATOR"; break;
00140             case OPEN_PAREN : str += "OPEN_PAREN"; break;
00141             case CLOSE_PAREN : str += "CLOSE_PAREN"; break;
00142             case OPEN_BRACKET : str += "OPEN_BRACKET"; break;
00143             case CLOSE_BRACKET : str += "CLOSE_BRACKET"; break;
00144             case OPEN_CURLY : str += "OPEN_CURLY"; break;
00145             case CLOSE_CURLY : str += "CLOSE_CURLY"; break;
00146             case UNDERSCRIPT : str += "UNDERSCRIPT"; break;
00147             case RESERVED : str += "RESERVED"; break;
00148             case SPECIALIZED : str += "SPECIALIZED"; break;
00149             case START_EXPRESSION : str += "START_EXPRESSION"; break;
00150             case END_EXPRESSION : str += "END_EXPRESSION"; break;
00151         }
00152 
00153         return str;
00154     }
00155     
00159     public static int getStringIdentifierAsInt(String identifier) {
00160         int value = 0;
00161 
00162         if (identifier.equals("SPACE")) 
00163             value = 0;
00164         if (identifier.equals("VARIABLE")) 
00165             value = 1;
00166         else if (identifier.equals("INTEGER"))
00167             value = 2;
00168         else if (identifier.equals("FLOAT"))
00169             value = 3;
00170         else if (identifier.equals("ADDITION"))
00171             value = 4;
00172         else if (identifier.equals("SUBSTRACTION"))
00173             value = 5;
00174         else if (identifier.equals("MULTIPLICATION"))
00175             value = 6;
00176         else if (identifier.equals("DIVISION"))
00177             value = 7;
00178         else if (identifier.equals("POWER"))
00179             value = 8;
00180         else if (identifier.equals("EQUAL"))
00181             value = 9;
00182         else if (identifier.equals("UNEQUAL"))
00183             value = 10;
00184         else if (identifier.equals("LESS"))
00185             value = 11;
00186         else if (identifier.equals("LESSEQUAL"))
00187             value = 12;
00188         else if (identifier.equals("GREATER"))
00189             value = 13;
00190         else if (identifier.equals("GREATEREQUAL"))
00191             value = 14;
00192         else if (identifier.equals("FUNCTION"))
00193             value = 15;
00194         else if (identifier.equals("SEPARATOR"))
00195             value = 16;
00196         else if (identifier.equals("OPEN_PAREN"))
00197             value = 17;
00198         else if (identifier.equals("CLOSE_PAREN"))
00199             value = 18;
00200         else if (identifier.equals("OPEN_BRACKET"))
00201             value = 19;
00202         else if (identifier.equals("CLOSE_BRACKET"))
00203             value = 20;
00204         else if (identifier.equals("OPEN_CURLY"))
00205             value = 21;
00206         else if (identifier.equals("CLOSE_CURLY"))
00207             value = 22;
00208         else if (identifier.equals("RESERVED"))
00209             value = 23;
00210         else if (identifier.equals("UNDERSCRIPT"))
00211             value = 24;
00212         else if (identifier.equals("SPECIALIZED"))
00213             value = 25;
00214         else if (identifier.equals("START_EXPRESSION"))
00215             value = 26;
00216         else if (identifier.equals("END_EXPRESSION"))
00217             value = 27;
00218 
00219         return value;
00220     }
00221     
00225     public String getValue() {
00226         return value;
00227     }
00228     
00233     public String toString() {
00234         return getIdentifierAsString() + "\t" + value;
00235     }
00236 
00241     // The basic elements of a formula
00242     public static final int SPACE               = 0;
00243     public static final int VARIABLE            = 1;
00244     public static final int INTEGER             = 2;
00245     public static final int FLOAT               = 3;
00246 
00247     // The basic operators
00248     public static final int ADDITION            = 4;
00249     public static final int SUBSTRACTION        = 5;
00250     public static final int MULTIPLICATION      = 6;
00251     public static final int DIVISION            = 7;
00252     public static final int POWER               = 8;
00253 
00254     // The relational operators
00255     public static final int EQUAL               = 9;
00256     public static final int UNEQUAL             = 10;
00257     public static final int LESS                = 11;
00258     public static final int LESSEQUAL           = 12;
00259     public static final int GREATER             = 13;
00260     public static final int GREATEREQUAL        = 14;
00261 
00262     // Special operators
00263     public static final int FUNCTION            = 15;
00264     public static final int SEPARATOR           = 16;
00265 
00266     // The different kinds of bracket
00267     public static final int OPEN_PAREN          = 17;
00268     public static final int CLOSE_PAREN         = 18;
00269     public static final int OPEN_BRACKET        = 19;
00270     public static final int CLOSE_BRACKET       = 20;
00271     public static final int OPEN_CURLY          = 21;
00272     public static final int CLOSE_CURLY         = 22;
00273 
00274     // Special terminals
00275     public static final int RESERVED            = 23;
00276 
00277     // Special operators
00278     public static final int UNDERSCRIPT         = 24;
00279     public static final int SPECIALIZED         = 25;
00280 
00281     // Parsing event
00282     public static final int START_EXPRESSION    = 26;
00283     public static final int END_EXPRESSION      = 27;
00284 }