Beispiel #1
0
        /// <summary>
        /// Method called by the interpreter to analyse the set of tokens gathered by the lexer.
        /// </summary>
        /// <param name="tokens"></param>
        /// <returns> the value of the given expression.</returns>
        public double AnalyseTokens(List <Token> tokens)
        {
            //check if there are any function definitions present.
            for (int i = 0; i < tokens.Count; i++)
            {
                //plot func has the following syntax:
                //plot(Y=X,Xmin,Xmax,inc)
                //So need to gather the algebraic function, Xmin, Xmax and the increment
                //And pass it into a PlotFunction object for processing.
                if (tokens[i].GetType() == Globals.SUPPORTED_TOKENS.PLOT)
                {
                    //the plot function must be the first token.
                    if (i != 0)
                    {
                        throw new ItemsBeforePlotFunctionException("Plot function found in unexpected token position " + i);
                    }

                    PlotFunction plot = PlotFunction.plotFunctionHandle(tokens, i);

                    if (plot.curIndex != (tokens.Count - 1))
                    {
                        throw new ItemsAfterPlotFunctionException("Nothing can follow after the plot function definition.");
                    }
                    plot.getValues();

                    /////////////////////////////////////////////////////////////////
                    //Draw onto the canvas.
                    this.g = new GraphDrawer(plot, l.window);
                    if (Globals.SHOW_GRAPH_CANVAS)
                    {
                        g.Draw();
                    }
                    /////////////////////////////////////////////////////////////////

                    //Draw it also onto LiveCharts.
                    l.dataPoints    = g.plotFunc.dataPoints;
                    l.canvasXLabels = g.Xlabels;
                    l.Xname         = g.plotFunc.X;
                    l.Yname         = g.plotFunc.Y;
                    if (Globals.SHOW_LIVE_CHARTS)
                    {
                        l.Draw();
                    }

                    status = STATUSES.PLOT_FUNCTION_CALLED;
                    return(double.NaN);
                }
                else if (tokens[i].GetType() == Globals.SUPPORTED_TOKENS.SIN)
                {
                    //create the sin function and find a value.
                    SinFunction s = new SinFunction(tokens, i, false);
                    tokens = s.getNewEquation();
                }
                else if (tokens[i].GetType() == Globals.SUPPORTED_TOKENS.COS)
                {
                    CosFunction c = new CosFunction(tokens, i, false);
                    tokens = c.getNewEquation();
                }
                else if (tokens[i].GetType() == Globals.SUPPORTED_TOKENS.TAN)
                {
                    TanFunction t = new TanFunction(tokens, i, false);
                    tokens = t.getNewEquation();
                }
                else if (tokens[i].GetType() == Globals.SUPPORTED_TOKENS.LOG)
                {
                    LogFunction l = new LogFunction(tokens, i, true);
                    tokens = l.getNewEquation();
                }
                else if (tokens[i].GetType() == Globals.SUPPORTED_TOKENS.LN)
                {
                    LnFunction l = new LnFunction(tokens, i, false);
                    tokens = l.getNewEquation();
                }
                else if (tokens[i].GetType() == Globals.SUPPORTED_TOKENS.SQRT)
                {
                    SqrtFunction s = new SqrtFunction(tokens, i, false);
                    tokens = s.getNewEquation();
                }
                else if (tokens[i].GetType() == Globals.SUPPORTED_TOKENS.ROOT)
                {
                    RootFunction r = new RootFunction(tokens, i, true);
                    tokens = r.getNewEquation();
                }
                else if (tokens[i].GetType() == Globals.SUPPORTED_TOKENS.ABS)
                {
                    AbsFunction a = new AbsFunction(tokens, i, false);
                    tokens = a.getNewEquation();
                }
            }
            return(processTokens(tokens));
        }
 public List<Service> ListServices(STATUSES? status)
 {
     return _repository.ListServices(status);
 }
 public Status GetStatus(STATUSES status)
 {
     return _repository.GetStatus(status);
 }