Exemplo n.º 1
0
        private ExpressionNode ParsePrimaryExpression()
        {
            ExpressionNode node       = null;
            TokenId        startToken = _curtok.TokenId;

            switch (_curtok.TokenId)
            {
            case TokenId.Null:
            {
                node = new NullPrimitive(_curtok);
                Advance();
                break;
            }

            case TokenId.True:
            {
                node = new BooleanPrimitive(true, _curtok);
                Advance();
                break;
            }

            case TokenId.False:
            {
                node = new BooleanPrimitive(false, _curtok);
                Advance();
                break;
            }

            case TokenId.Int:
            {
                node = new IntegralPrimitive(_curtok);
                Advance();
                break;
            }

            case TokenId.Double:
            {
                node = new DoublePrimitive(_curtok);
                Advance();
                break;
            }

            case TokenId.String:
            {
                node = new StringPrimitive(_curtok);
                Advance();
                break;
            }

            case TokenId.Quote:
            {
                node = new QuotePrimitive(_curtok);
                Advance();
                break;
            }

            case TokenId.Ident:
            {
                node = new IdentifierExpression(_curtok);
                Advance();
                break;
            }

            case TokenId.LParen:
            {
                Advance();
                node = new ParenthesizedExpression(ParseExpression());
                AssertAndAdvance(TokenId.RParen);
                break;
            }

            case TokenId.LBracket:
            {
                node = ParseArrayCreation();
                AssertAndAdvance(TokenId.RBracket);
                break;
            }

            case TokenId.LCurly:
            {
                node = ParseDictionaryCreation();
                AssertAndAdvance(TokenId.RCurly);
                break;
            }

            default:
            {
                throw new ParseException("Unhandled case in ParseExpression " + _curtok.TokenId);
            }
            }

            return(node);
        }
Exemplo n.º 2
0
        private ExpressionNode ParsePrimaryExpression()
        {
            ExpressionNode node = null;
            TokenId startToken = _curtok.TokenId;

            switch (_curtok.TokenId)
            {
                case TokenId.Null:
                    {
                        node = new NullPrimitive(_curtok);
                        Advance();
                        break;
                    }
                case TokenId.True:
                    {
                        node = new BooleanPrimitive(true, _curtok);
                        Advance();
                        break;
                    }
                case TokenId.False:
                    {
                        node = new BooleanPrimitive(false, _curtok);
                        Advance();
                        break;
                    }
                case TokenId.Int:
                    {
                        node = new IntegralPrimitive(_curtok);
                        Advance();
                        break;
                    }
                case TokenId.Double:
                    {
                        node = new DoublePrimitive(_curtok);
                        Advance();
                        break;
                    }
                case TokenId.String:
                    {
                        node = new StringPrimitive(_curtok);
                        Advance();
                        break;
                    }
                case TokenId.Quote:
                    {
                        node = new QuotePrimitive(_curtok);
                        Advance();
                        break;
                    }
                case TokenId.Ident:
                    {
                        node = new IdentifierExpression(_curtok);
                        Advance();
                        break;
                    }
                case TokenId.LParen:
                    {
                        Advance();
                        node = new ParenthesizedExpression(ParseExpression());
                        AssertAndAdvance(TokenId.RParen);
                        break;
                    }
                case TokenId.LBracket:
                    {
                        node = ParseArrayCreation();
                        AssertAndAdvance(TokenId.RBracket);
                        break;
                    }
                case TokenId.LCurly:
                    {
                        node = ParseDictionaryCreation();
                        AssertAndAdvance(TokenId.RCurly);
                        break;
                    }
                default:
                    {
                        throw new ParseException("Unhandled case in ParseExpression " + _curtok.TokenId);
                    }
            }

            return node;
        }