private async Task <ParseTermResult> ParseTerm() { await ReadToken(); Tokenizer.EType pType; string pValue; string pToken; lock (mTokenizer) { pType = mTokenizer.TypeToken; pValue = mTokenizer.Value; pToken = mTokenizer.Token; } switch (pType) { case Tokenizer.EType.Number: return(new ParseTermResult { TypeTerm = ParseTermResult.EType.Expression, Expr = NodeExpr.Number(mAlg.ParseNumber(pValue)) }); case Tokenizer.EType.Sign: return(new ParseTermResult { TypeTerm = ParseTermResult.EType.UnaryOperation, TypeUnary = MathExpr.StrToUnary[pToken] }); case Tokenizer.EType.Operation: return(new ParseTermResult { TypeTerm = ParseTermResult.EType.Operation, TypeBinary = MathExpr.StrToBinaries[pToken] }); case Tokenizer.EType.EOF: return(new ParseTermResult { TypeTerm = ParseTermResult.EType.EOF }); default: return(new ParseTermResult { TypeTerm = ParseTermResult.EType.Token }); } }
public override Task <NodeExpr> Visit(NodeExprBinary e, CancellationToken t) { return(Task.Run ( () => { var lt = Visit(e.Left, t); var rt = Visit(e.Right, t); Task.WaitAll(new[] { lt, rt }, t); t.ThrowIfCancellationRequested(); var l = lt.Result; var r = rt.Result; return ((l is NodeExprNumber <N> ln) && (r is NodeExprNumber <N> rn)) ? (NodeExpr)NodeExpr.Number(mAlg.EvalBinaryOperator(e.TypeBinary, ln.Value, rn.Value)) : NodeExpr.Binary(e.TypeBinary, l, r); } )); }