Exemplo n.º 1
0
        //------------------------------------------------------------
        /// <summary>
        /// PrimaryExpression:
        ///   Identifier # ScopeRootIdentExpression
        ///   | "." Identifier # NamespaceRootIdentExpression
        ///   | ConstantLiteral
        ///   | "(" Expression ")"
        /// </summary>
        /// <returns></returns>
        IExpression parsePrimaryExpression()
        {
            IExpression expr = null;

            if (currentToken().Value == Token.Kind.Identifier)
            {
                expr = new RootIdentExpression(new Identifier(currentToken()), false);
                nextToken();
            }
            else if (currentToken().Value == Token.Kind.OpDot)
            {
                if (currentToken().Value != Token.Kind.Identifier)
                {
                    setErrorKind(ErrorKind.PRIMARY_EXPRESSION_IDENTIFIER_EXPECTED);
                    return(null);
                }
                expr = new RootIdentExpression(new Identifier(currentToken()), true);
                nextToken();
            }
            else if (isConstantLiteral(currentToken()))
            {
                expr = new ConstantLiteralExpression(currentToken());
                nextToken();
            }
            else
            {
                // "("
                if (!expectToken(Token.Kind.OpLParen, ErrorKind.PRIMARY_EXPRESSION_LPAREN_EXPECTED))
                {
                    return(null);
                }

                // Expression
                expr = parseExpression();

                // ")"
                if (!expectToken(Token.Kind.OpRParen, ErrorKind.PRIMARY_EXPRESSION_RPAREN_EXPECTED))
                {
                    return(null);
                }
            }

            return(expr);
        }
Exemplo n.º 2
0
 //------------------------------------------------------------
 // コンストラクタ。
 public EvaluateNode(RootIdentExpression aExpr)
 {
     mExpr = aExpr;
 }