예제 #1
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
 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)
     });
예제 #5
0
 protected override IDataFlowGraphExpressionNode Visit(ErrorExpression err)
 {
     throw new NotImplementedException();
 }
예제 #6
0
 protected override bool Visit(ErrorExpression err) => false;
예제 #7
0
 public override void PostWalk(ErrorExpression node)
 {
 }
예제 #8
0
 // ErrorExpression
 public override bool Walk(ErrorExpression node) { return false; }
예제 #9
0
 // ErrorExpression
 public virtual bool Walk(ErrorExpression node)
 {
     return(true);
 }
예제 #10
0
 // ErrorExpression
 public override bool Walk(ErrorExpression node)
 {
     return(Location >= node.StartIndex && Location <= node.EndIndex);
 }
예제 #11
0
 protected override IEnumerable <BaseStatement> Visit(ErrorExpression err)
 {
     yield return(new ErrorStatement());
 }
예제 #12
0
파일: visit.cs 프로젝트: KAW0/Alter-Native
		public virtual object Visit (ErrorExpression errorExpression)
		{
			return null;
		}
예제 #13
0
 // ErrorExpression
 public override bool Walk(ErrorExpression node) { return Location >= node.StartIndex && Location <= node.EndIndex; }
예제 #14
0
 public override void VisitErrorExpression(ErrorExpression node)
 => Error($"Expected expression, found '{node.Text}'", node);
예제 #15
0
 public override bool Walk(ErrorExpression node)
 {
     writer.WriteLine("Error");
     return(base.Walk(node));
 }
예제 #16
0
 private List <Inferred> InferErrorExpression(ErrorExpression node, Scope scope)
 {
     return(null);
 }
예제 #17
0
 [NotNull] protected virtual BaseExpression Visit([NotNull] ErrorExpression err)
 {
     return(err);
 }
예제 #18
0
 // ErrorExpression
 public bool Walk(ErrorExpression node)
 {
     return(Process(node));
 }
 // ErrorExpression
 public override bool Walk(ErrorExpression node)
 {
     return(ShouldWalkWorker(node));
 }
예제 #20
0
 public void PostWalk(ErrorExpression node)
 {
     PostProcess(node);
 }
 public override void PostWalk(ErrorExpression node)
 {
     PostWalkWorker(node);
 }
예제 #22
0
 public override bool Walk(ErrorExpression node)
 {
     HasSideEffects = true;
     return(false);
 }
예제 #23
0
 [NotNull] protected abstract TResult Visit([NotNull] ErrorExpression err);
예제 #24
0
 public virtual void PostWalk(ErrorExpression node)
 {
 }
예제 #25
0
 // ErrorExpression
 public virtual bool Walk(ErrorExpression node) { return true; }
예제 #26
0
 // ErrorExpression
 public override bool Walk(ErrorExpression node)
 {
     return(false);
 }
예제 #27
0
 protected override bool Visit(ErrorExpression err) => throw new NotSupportedException();
예제 #28
0
 public virtual object Visit(ErrorExpression errorExpression)
 {
     return(null);
 }
예제 #29
0
 public override bool Walk(ErrorExpression node) => Save(node, base.Walk(node), _options.Errors);
예제 #30
0
 public override void PostWalk(ErrorExpression node) { }
예제 #31
0
        //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);
        }
예제 #32
0
 public virtual void PostWalk(ErrorExpression node) { }
예제 #33
0
 protected override Type Visit(ErrorExpression err)
 {
     return(Type.Error);
 }