Ejemplo n.º 1
0
        public Exprs.Expr STToExpr(ST.STTokensReader argReader)
        {
            argReader.CancelToken.ThrowIfCancellationRequested();

            var pToken     = argReader.Token;
            var pTypeToken = pToken?.Token;

            if (!pTypeToken.HasValue)
            {
                return(Exprs.Expr.Null);
            }

            switch (pTypeToken.Value)
            {
            case ST.ESTToken.Number:
                return(Exprs.Expr.Number(argReader.TokenStr.Text));

            case ST.ESTToken.Word:
                var pWord = argReader.TokenStr;

                if (argReader.NextIfNodeNextValue(t => t.Token == ST.ESTToken.Parenthesis))
                {
                    return(STToFunctionExpr(pWord, argReader));
                }

                break;
            }

            throw new ST.STException(string.Format(Properties.Resources.NoExpectTokenException, pToken.ToString()), pToken.Line, pToken.Position);
        }
Ejemplo n.º 2
0
        public Exprs.FunctionExpr STToFunctionExpr(ST.STTokenStr argWord, ST.STTokensReader argReader)
        {
            argReader.CancelToken.ThrowIfCancellationRequested();

            var pArgs = STBlocktoExprs(argReader);

            return(Exprs.Expr.Function(argWord.Text, pArgs.ToArray()));
        }
Ejemplo n.º 3
0
        public Exprs.ExprCollection STBlocktoExprs(ST.STTokensReader argReader)
        {
            var pExprs = new Exprs.ExprCollection();

            if (argReader.Token is ST.STTokenBlock pBlock)
            {
                foreach (var pTokens in pBlock.Tokens)
                {
                    argReader.CancelToken.ThrowIfCancellationRequested();

                    var pReader = new ST.STTokensReader(pTokens, argReader.CancelToken);
                    var pExpr   = STToExpr(pReader);

                    pExprs.Add(pExpr);
                }
            }

            return(pExprs);
        }
Ejemplo n.º 4
0
        public EvalExprInResult EvalPrompt(ST.STTokensTerminate argTokens, CancellationToken argCancelToken)
        {
            var pReader  = new ST.STTokensReader(argTokens, argCancelToken);
            var pIn      = STToExprIn(pReader);
            var pContext = new EvalContext {
                CancelToken = argCancelToken
            };
            var pOut = EvalIn(pContext, pIn);
            var pIOE = mVars.AddInOut(pIn, pOut, out string pNameVarIn, out string pNameVarOut);

            if (argTokens.Terminate == ST.ESTTokenizerTerminate.ShowResult)
            {
                mPost.PrintExprOutPost(GetPromptVar(pNameVarOut), pOut);
            }

            return(new EvalExprInResult {
                Terminate = argTokens.Terminate, InExpr = pIn, OutExpr = pOut, NameVarIn = pNameVarIn, NameVarOut = pNameVarOut
            });
        }
Ejemplo n.º 5
0
        public override string ToString() //=> (Tokens != null) ? string.Join(" ", Tokens) : string.Empty;
        {
            var pStr    = string.Empty;
            var pReader = new STTokensReader(this, CancellationToken.None);

            while (!pReader.EOF)
            {
                if (pReader.IsPrev(2, n => n.Token == ESTToken.Number || n.Token == ESTToken.Word))
                {
                    pStr += " ";
                }
                pStr += pReader.Token.ToString();
                pReader.Next();
            }

            return(pStr);

            /*
             * var pTokens = Tokens.First;
             *
             * while (pTokens != null)
             * {
             *  if (pTokens.Previous != null)
             *      switch (pTokens.Previous.Value.Token)
             *      {
             *          case ESTToken.Number:
             *          case ESTToken.Word:
             *              switch (pTokens.Value.Token)
             *              {
             *                  case ESTToken.Number:
             *                  case ESTToken.Word:
             *                      pStr += " ";
             *                      break;
             *              }
             *              break;
             *      }
             *  pStr += pTokens.Value.ToString();
             *  pTokens = pTokens.Next;
             * }
             *
             * return pStr;
             */
        }
Ejemplo n.º 6
0
 public Exprs.Expr STToExprIn(ST.STTokensReader argReader) => STToExpr(argReader);