java - Math Parser - token structure -


i'm implementing own math parser - , have few questions on how proceed.

so far parser converting input string tokens:

public class token  {        final public string expression;     final public int value;      public token(string expression, int value)     {           this.expression = expression;         this.value = value;     } } 

each string, expression, valid entry - number, operator or function. integer type passed enum identify token.

when input string separated tokens expression parsed shunting-yard algorithm.

my question: want tokens create objects of type. 1 way of doing might be:

    public abstract class mathcommand      {      final static hashtable<character, operator> operatortable = new hashtable<character, operator>()     {{                    put('+',    new addition());             put('-',    new subtraction());             put('/',    new division());             put('*',    new multiplication());      }};      public abstract object getmathcommand();      } 

and similar hashtable functions.

now, class token extends mathcommand - , token can return either function or operator of type. downside token returns object, , not operator or function. difference between methods in operator , function not big.

an operator has method:

getvalue(string number1, string number2); 

and function has method:

getvalue(string number); 

can somehow implement interface , override method getvalue 1 of above?

they have common interface:

interface callable {     int getnumberofarguments();     string getvalue(string[] args); } 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -