Esempio n. 1
0
        private Syntax.Expression ParsePostfixExpr(Syntax.Expression expr_node = null)
        {
            Syntax.Expression node = expr_node == null?this.ParsePrimaryExpr() : expr_node, res = null;

            while (true)
            {
                switch (scan.Peek().type)
                {
                case Token.Type.OP_INC:
                case Token.Type.OP_DEC:
                    res = new Syntax.UnaryOperator(scan.Read(), false);
                    ((Syntax.UnaryOperator)res).SetOperand(node);
                    break;

                case Token.Type.OP_DOT:
                case Token.Type.OP_REF:
                    res = new Syntax.Refference(scan.Read());
                    ((Syntax.Refference)res).SetExpression(node);
                    CheckToken(scan.Peek(), Token.Type.IDENTIFICATOR);
                    ((Syntax.Refference)res).SetRefference(new Syntax.Identifier(scan.Read()));
                    break;

                case Token.Type.LPAREN:
                    res = new Syntax.Call(scan.Read());
                    ((Syntax.Call)res).SetOperand(node);
                    try
                    {
                        if (scan.Peek().type == Token.Type.RPAREN)
                        {
                            ((Syntax.Call)res).SetArgumentList(new List <Syntax.Expression>());
                            scan.Read();
                            break;
                        }
                        ((Syntax.Call)res).SetArgumentList(this.ParseArgExpressionList());
                    }
                    catch (Symbols.Exception e)
                    {
                        this.logger.Add(e);
                    }

                    CheckToken(scan.Peek(), Token.Type.RPAREN, true);
                    break;

                case Token.Type.LBRACKET:
                    res = new Syntax.Refference(scan.Read());
                    ((Syntax.Refference)res).SetExpression(node);
                    ((Syntax.Refference)res).SetRefference(this.ParseExpression());
                    CheckToken(scan.Peek(), Token.Type.RBRACKET, true);
                    break;

                default:
                    return(res == null? node: res);
                }

                if (res != null)
                {
                    node = res;
                }
            }
        }
Esempio n. 2
0
        private Syntax.Expression ParsePostfixExpr(Syntax.Expression expr_node = null)
        {
            Syntax.Expression node = expr_node == null? this.ParsePrimaryExpr(): expr_node, res = null;

            while(true){
                switch (scan.Peek().type)
                {
                    case Token.Type.OP_INC:
                    case Token.Type.OP_DEC:
                        res = new Syntax.UnaryOperator(scan.Read(), false);
                        ((Syntax.UnaryOperator)res).SetOperand(node);
                        break;

                    case Token.Type.OP_DOT:
                    case Token.Type.OP_REF:
                        res = new Syntax.Refference(scan.Read());
                        ((Syntax.Refference)res).SetExpression(node);
                        CheckToken(scan.Peek(), Token.Type.IDENTIFICATOR);
                        ((Syntax.Refference)res).SetRefference(new Syntax.Identifier(scan.Read()));
                        break;

                    case Token.Type.LPAREN:
                        res = new Syntax.Call(scan.Read());
                        ((Syntax.Call)res).SetOperand(node);
                        try
                        {
                            if (scan.Peek().type == Token.Type.RPAREN)
                            {
                                ((Syntax.Call)res).SetArgumentList(new List<Syntax.Expression>());
                                scan.Read();
                                break;
                            }
                            ((Syntax.Call)res).SetArgumentList(this.ParseArgExpressionList());
                        }
                        catch (Symbols.Exception e)
                        {
                            this.logger.Add(e);
                        }

                        CheckToken(scan.Peek(), Token.Type.RPAREN, true);
                        break;

                    case Token.Type.LBRACKET:
                        res = new Syntax.Refference(scan.Read());
                        ((Syntax.Refference)res).SetExpression(node);
                        ((Syntax.Refference)res).SetRefference(this.ParseExpression());
                        CheckToken(scan.Peek(), Token.Type.RBRACKET, true);
                        break;

                    default:
                        return res == null? node: res;
                }

                if (res != null)
                {
                    node = res;
                }
            }
        }
Esempio n. 3
0
        private Syntax.Expression ParseUnaryExpr()
        {
            Syntax.UnaryOperator node = null;

            switch (scan.Peek().type)
            {
                case Token.Type.OP_INC:
                case Token.Type.OP_DEC:
                case Token.Type.OP_BIT_AND:
                case Token.Type.OP_STAR:
                case Token.Type.OP_PLUS:
                case Token.Type.OP_SUB:
                case Token.Type.OP_TILDE:
                case Token.Type.OP_NOT:
                    node = new Syntax.UnaryOperator(scan.Read());
                    node.SetOperand(this.ParseUnaryExpr());
                    return node;

                case Token.Type.LPAREN:
                    Syntax.Expression res = null;
                    Token t = scan.Read();

                    if (IsType(scan.Peek()))
                    {
                        res = new Syntax.Cast(t);
                        Symbols.ParamVar var = ParseParameterDeclaration(); //this is hack
                        ((Syntax.Cast)res).SetTypeCast(var.GetType());
                        CheckToken(scan.Peek(), Token.Type.RPAREN, true);
                        ((Syntax.Cast)res).SetOperand(ParseUnaryExpr());
                        return res;
                    }

                    res = ParseExpression();
                    CheckToken(scan.Peek(), Token.Type.RPAREN, true);
                    return ParsePostfixExpr(res);

                case Token.Type.KW_SIZEOF:
                    node = new Syntax.UnaryOperator(scan.Read());

                    if (scan.Peek().type != Token.Type.LPAREN)
                    {
                        node.SetOperand(ParseUnaryExpr());
                        return node;
                    }

                    scan.Read();
                    if (IsType(scan.Peek()))
                    {
                        ((Syntax.UnaryOperator)node).SetOperand(new Syntax.Identifier(scan.Read()));
                    }
                    else
                    {
                        node.SetOperand(ParseExpression());
                    }

                    CheckToken(scan.Peek(), Token.Type.RPAREN, true);
                    return node;

                default:
                    return ParsePostfixExpr();
            }
        }
Esempio n. 4
0
        private Syntax.Expression ParseUnaryExpr()
        {
            Syntax.UnaryOperator node = null;

            switch (scan.Peek().type)
            {
            case Token.Type.OP_INC:
            case Token.Type.OP_DEC:
            case Token.Type.OP_BIT_AND:
            case Token.Type.OP_STAR:
            case Token.Type.OP_PLUS:
            case Token.Type.OP_SUB:
            case Token.Type.OP_TILDE:
            case Token.Type.OP_NOT:
                node = new Syntax.UnaryOperator(scan.Read());
                node.SetOperand(this.ParseUnaryExpr());
                return(node);

            case Token.Type.LPAREN:
                Syntax.Expression res = null;
                Token             t   = scan.Read();

                if (IsType(scan.Peek()))
                {
                    res = new Syntax.Cast(t);
                    Symbols.ParamVar var = ParseParameterDeclaration();                             //this is hack
                    ((Syntax.Cast)res).SetTypeCast(var.GetType());
                    CheckToken(scan.Peek(), Token.Type.RPAREN, true);
                    ((Syntax.Cast)res).SetOperand(ParseUnaryExpr());
                    return(res);
                }

                res = ParseExpression();
                CheckToken(scan.Peek(), Token.Type.RPAREN, true);
                return(ParsePostfixExpr(res));

            case Token.Type.KW_SIZEOF:
                node = new Syntax.UnaryOperator(scan.Read());

                if (scan.Peek().type != Token.Type.LPAREN)
                {
                    node.SetOperand(ParseUnaryExpr());
                    return(node);
                }

                scan.Read();
                if (IsType(scan.Peek()))
                {
                    ((Syntax.UnaryOperator)node).SetOperand(new Syntax.Identifier(scan.Read()));
                }
                else
                {
                    node.SetOperand(ParseExpression());
                }

                CheckToken(scan.Peek(), Token.Type.RPAREN, true);
                return(node);

            default:
                return(ParsePostfixExpr());
            }
        }