private IExpression ParseUnary() { while (true) { IExpression res = new ErrorExpression(); switch (_tokenizer.GetNextToken()) { case Token.Number: res = new Number(_tokenizer.GetValue()); _tokenizer.GetNextToken(); break; case Token.Negate: res = new Negate(ParseUnary()); break; case Token.OpenParenthesis: res = ParseAddSubtract(); if (_tokenizer.GetCurToken() != Token.CloseParenthesis) { _tokenizer.AddException(new MissingCloseParenthesisException( _tokenizer.GetExpression(), _tokenizer.GetInd())); } _tokenizer.GetNextToken(); break; case Token.Error: continue; } return(res); } }
private static TreeViewItem AsTreeViewItem(ErrorExpression expression) { var result = new TreeViewItem(); result.Header = expression.Description; return(result); }
private ErrorExpression Error(int startPos, string verbatimImage = null, Expression preceding = null) { verbatimImage = verbatimImage ?? (_fString.Substring(startPos, _position - startPos)); var expr = new ErrorExpression(verbatimImage, preceding); expr.SetLoc(StartIndex + startPos, StartIndex + _position); return(expr); }
public virtual TResult Visit(BaseExpression expression) { return(expression switch { Phi a => Visit(a), Increment a => Visit(a), Decrement a => Visit(a), ErrorExpression a => Visit(a), Bracketed a => Visit(a), Abs a => Visit(a), Sqrt a => Visit(a), Sine a => Visit(a), Cosine a => Visit(a), Tangent a => Visit(a), ArcSine a => Visit(a), ArcCos a => Visit(a), ArcTan a => Visit(a), PostIncrement a => Visit(a), PreIncrement a => Visit(a), PostDecrement a => Visit(a), PreDecrement a => Visit(a), Add a => Visit(a), Subtract a => Visit(a), Multiply a => Visit(a), Divide a => Visit(a), Modulo a => Visit(a), Negate a => Visit(a), Exponent a => Visit(a), Or a => Visit(a), And a => Visit(a), Not a => Visit(a), Factorial a => Visit(a), Variable a => Visit(a), ConstantNumber a => Visit(a), ConstantString a => Visit(a), EqualTo a => Visit(a), NotEqualTo a => Visit(a), GreaterThan a => Visit(a), GreaterThanEqualTo a => Visit(a), LessThan a => Visit(a), LessThanEqualTo a => Visit(a), _ => VisitUnknown(expression) });
protected override IDataFlowGraphExpressionNode Visit(ErrorExpression err) { throw new NotImplementedException(); }
protected override bool Visit(ErrorExpression err) => false;
public override void PostWalk(ErrorExpression node) { }
// ErrorExpression public override bool Walk(ErrorExpression node) { return false; }
// ErrorExpression public virtual bool Walk(ErrorExpression node) { return(true); }
// ErrorExpression public override bool Walk(ErrorExpression node) { return(Location >= node.StartIndex && Location <= node.EndIndex); }
protected override IEnumerable <BaseStatement> Visit(ErrorExpression err) { yield return(new ErrorStatement()); }
public virtual object Visit (ErrorExpression errorExpression) { return null; }
// ErrorExpression public override bool Walk(ErrorExpression node) { return Location >= node.StartIndex && Location <= node.EndIndex; }
public override void VisitErrorExpression(ErrorExpression node) => Error($"Expected expression, found '{node.Text}'", node);
public override bool Walk(ErrorExpression node) { writer.WriteLine("Error"); return(base.Walk(node)); }
private List <Inferred> InferErrorExpression(ErrorExpression node, Scope scope) { return(null); }
[NotNull] protected virtual BaseExpression Visit([NotNull] ErrorExpression err) { return(err); }
// ErrorExpression public bool Walk(ErrorExpression node) { return(Process(node)); }
// ErrorExpression public override bool Walk(ErrorExpression node) { return(ShouldWalkWorker(node)); }
public void PostWalk(ErrorExpression node) { PostProcess(node); }
public override void PostWalk(ErrorExpression node) { PostWalkWorker(node); }
public override bool Walk(ErrorExpression node) { HasSideEffects = true; return(false); }
[NotNull] protected abstract TResult Visit([NotNull] ErrorExpression err);
public virtual void PostWalk(ErrorExpression node) { }
// ErrorExpression public virtual bool Walk(ErrorExpression node) { return true; }
// ErrorExpression public override bool Walk(ErrorExpression node) { return(false); }
protected override bool Visit(ErrorExpression err) => throw new NotSupportedException();
public virtual object Visit(ErrorExpression errorExpression) { return(null); }
public override bool Walk(ErrorExpression node) => Save(node, base.Walk(node), _options.Errors);
//constant: // Integer // Float // String // Boolean //symbol: // ReplacementSymbol // Symbol //value: // constant // symbol // operation // scope //operation: value Operator value //list-expression: value-source , value-source //scope: StartScope value-source EndScope //value-source: // value // scope // function // operation //function: symbol StartScope list-expression EndScope | symbol StartScope value-source EndScope public static Expression Parse(List <Token> tokens) { if (tokens == null || tokens.None()) { return(new NullExpression()); } var remainder = tokens.ToList(); Expression program = null; while (remainder.Any()) { Production parsed = null; var current = remainder.First(); switch (current.TokenClass) { case TokenClass.StartScope: parsed = new ScopedExpression().Parse(remainder); if (parsed.Expression != null) { break; } parsed = new SeparatedExpression().Parse(remainder); if (parsed.Expression != null) { break; } parsed = new ErrorExpression().Parse(program, remainder); break; case TokenClass.Whitespace: parsed = new WhitespaceExpression().Parse(remainder); break; case TokenClass.Symbol: parsed = new OperationExpression().Parse(remainder); if (parsed.Expression != null) { break; } parsed = new FunctionExpression().Parse(remainder); if (parsed.Expression != null) { break; } parsed = new SymbolExpression().Parse(remainder); if (parsed.Expression != null) { break; } parsed = new ErrorExpression().Parse(program, remainder); break; case TokenClass.ReplacementSymbol: parsed = new OperationExpression().Parse(remainder); if (parsed.Expression != null) { break; } parsed = new ReplacementSymbolExpression().Parse(remainder); break; case TokenClass.Float: case TokenClass.Integer: parsed = new OperationExpression().Parse(remainder); if (parsed.Expression != null) { break; } parsed = NumericExpression.TryParseNumeric(remainder); break; case TokenClass.String: parsed = new OperationExpression().Parse(remainder); if (parsed.Expression != null) { break; } parsed = new StringExpression().Parse(remainder); break; case TokenClass.Boolean: parsed = new OperationExpression().Parse(remainder); if (parsed.Expression != null) { break; } parsed = new BooleanExpression().Parse(remainder); break; case TokenClass.Operator: parsed = NumericExpression.TryParseNumeric(remainder); if (parsed.Expression != null) { break; } parsed = new OperationExpression().Parse(program, remainder); if (parsed.Expression != null) { break; } parsed = new ErrorExpression().Parse(program, remainder); break; case TokenClass.Error: throw new Exception("Unexpected sequence: " + remainder.First().Lexeme); default: throw new ArgumentOutOfRangeException(); } if (parsed.Expression != null && !(parsed.Expression is WhitespaceExpression)) { program = parsed.Expression; } remainder = parsed.RemainingTokens; } if (program == null || remainder.Any()) { throw new ParserException(remainder.Select(c => c.Lexeme).StringConcat()); } return(program); }
protected override Type Visit(ErrorExpression err) { return(Type.Error); }