Example #1
0
        private void ParseBinaryOp()
        {
            Token token = this.PeekToken();

            this.CheckStartableToken(token);
            BinaryOp expr = BinaryOp.CreateOp(this._current.token);

            this._tree.AddOperator(expr);
        }
Example #2
0
        public Tree Parse(string text)
        {
            this._scanner = new Scanner(text);
            this._tree    = new Tree();
            Token token = this.NextToken();

            if (token != Token.EndOfFile)
            {
                this.CheckStartableToken(token);
                while (token != Token.EndOfFile)
                {
                    MemberOp expression;
                    if (IsConstTocken(token))
                    {
                        this.ParseConst();
                        goto Label_022A;
                    }
                    if (this._tree._isStart && ((token == Token.Subtract) || (token == Token.Add)))
                    {
                        Constant expr = new Constant(0);
                        this._tree.AddOperand(expr);
                        BinaryOp op = BinaryOp.CreateOp(token);
                        this._tree.AddOperator(op);
                        goto Label_022A;
                    }
                    if (IsBinaryOp(token))
                    {
                        this.ParseBinaryOp();
                        goto Label_022A;
                    }
                    if (IsUnaryOp(token))
                    {
                        this.ParseUnaryOp();
                        goto Label_022A;
                    }
                    switch (token)
                    {
                    case Token.LeftIndexer:
                        this.ParseIndexer();
                        goto Label_022A;

                    case Token.RightIndexer:
                        this._tree.Pop('[');
                        goto Label_022A;

                    case Token.ConditionalIf:
                        this.ParseConditional();
                        goto Label_022A;

                    case Token.ConditionalSemicolon:
                        this.ParseConditionalSemicolon();
                        goto Label_022A;

                    case Token.Member:
                        this.ParseMember();
                        goto Label_022A;

                    case Token.LeftParen:
                        if (this._tree._top.Expression is MemberOp)
                        {
                            expression = (MemberOp)this._tree._top.Expression;
                            if (expression.IsFunction)
                            {
                                throw new ParserException("()()not allowed");
                            }
                            break;
                        }
                        goto Label_01E3;

                    case Token.RightParen:
                        this._tree.Pop('(');
                        goto Label_022A;

                    case Token.Comma:
                        this._tree.Pop(',');
                        this._tree.Push(',');
                        goto Label_022A;

                    case Token.Identifier:
                        this.ParseIdentifier();
                        goto Label_022A;

                    default:
                        throw this.BuildException(Error.InternalError);
                    }
                    expression.IsFunction = true;
Label_01E3:
                    this._tree.Push('(');
Label_022A:
                    token = this.NextToken();
                }
                this._tree.Complete();
            }
            return(this._tree);
        }