예제 #1
0
        //------------------------------------------------------------
        /// <summary>
        /// PostfixExpression:
        ///   PrimaryExpression (PostfixOperator)*
        ///
        /// PostfixOperator:
        ///   "++"
        ///   | "--"
        ///   | IndexExpression
        ///   | FunctionCallExpression
        ///   | "." Identifier # ChildIdentExpression
        /// </summary>
        /// <returns></returns>
        IExpression parsePostfixExpression()
        {
            IExpression firstExpr = parsePrimaryExpression();

            while (firstExpr != null)
            {
                PostfixExpression.OpKind opKind = PostfixExpression.OpKind.Unknown;

                // OpTokenがある式
                Token opToken = currentToken();
                if (currentToken().Value == Token.Kind.OpPlusPlus)
                {// "++"
                    opKind = PostfixExpression.OpKind.Inc;
                    nextToken();
                }
                else if (currentToken().Value == Token.Kind.OpMinusMinus)
                {// "--"
                    opKind = PostfixExpression.OpKind.Dec;
                    nextToken();
                }
                if (opKind != PostfixExpression.OpKind.Unknown)
                {
                    firstExpr = new PostfixExpression(opToken, opKind, firstExpr);
                }

                // OpTokenがない式
                if (currentToken().Value == Token.Kind.OpLBracket)
                {// IndexExpression
                    IndexExpression expr = parseIndexExpression();
                    if (expr == null)
                    {
                        return(null);
                    }
                    return(new PostfixExpression(firstExpr, expr));
                }
                else if (currentToken().Value == Token.Kind.OpLParen)
                {// FunctionCallExpression
                    FunctionCallExpression expr = parseFunctionCallExpression();
                    if (expr == null)
                    {
                        return(null);
                    }
                    return(new PostfixExpression(firstExpr, expr));
                }
                else if (currentToken().Value == Token.Kind.OpDot)
                {// ChildIdentExpression
                    nextToken();
                    if (currentToken().Value != Token.Kind.Identifier)
                    {
                        setErrorKind(ErrorKind.POSTFIX_EXPRESSION_IDENTIFIER_EXPECTED);
                        return(null);
                    }
                    ChildIdentExpression expr = new ChildIdentExpression(new Identifier(currentToken()));
                    nextToken();
                    return(new PostfixExpression(firstExpr, expr));
                }
                else
                {
                    return(firstExpr);
                }
            }

            return(firstExpr);
        }
예제 #2
0
 //------------------------------------------------------------
 // ChildIdentのコンストラクタ。
 public PostfixExpression(IExpression aFirstExpr, ChildIdentExpression aChildIdentExpr)
 {
     mExprKind       = ExprKind.ChildIdentExpr;
     mFirstExpr      = aFirstExpr;
     mChildIdentExpr = aChildIdentExpr;
 }