/*primary-expression-p: | '.' identifier primary-expression-p | optional-funct-or-array-call primary-expression-p | increment-decrement primary-expression-p | EPSILON */ private void primary_expression_p(ref InlineExpressionNode inline) { printIfDebug("primary_expression_p"); if (pass(TokenType.PUNT_ACCESOR)) { consumeToken(); if (!pass(TokenType.ID)) { throwError("identifier expected"); } var identifier = new IdNode(token.lexeme, token); consumeToken(); // var nextExpression = new AccessorNode(identifier,identifier.token); var inline_p = new InlineExpressionNode(identifier, identifier.token); if (inline_p.primary is FunctionCallExpressionNode || inline_p.primary is ArrayAccessExpressionNode) { is_function_or_array(ref inline, ref inline_p); primary_expression_p(ref inline); } else { primary_expression_p(ref inline_p); inline.nextExpression = inline_p; } } else if (pass(TokenType.PUNT_PAREN_OPEN, TokenType.PUNT_SQUARE_BRACKET_OPEN)) { var accessOrCall = optional_funct_or_array_call(); var inline_p = new InlineExpressionNode(accessOrCall, accessOrCall.token); if (accessOrCall is FunctionCallExpressionNode || accessOrCall is ArrayAccessExpressionNode) { is_function_or_array(ref inline, ref inline_p); primary_expression_p(ref inline); } else { primary_expression_p(ref inline_p); inline.nextExpression = inline_p; } } else if (pass(TokenType.OP_PLUS_PLUS, TokenType.OP_MINUS_MINUS)) { var operatorToken = token; consumeToken(); var postOp = new PostAdditiveExpressionNode(operatorToken.type, operatorToken); var inline_p = new InlineExpressionNode(postOp, operatorToken); if (inline_p.primary is PostAdditiveExpressionNode) { is_function_or_array(ref inline, ref inline_p); primary_expression_p(ref inline); } else { primary_expression_p(ref inline_p); inline.nextExpression = inline_p; } // inline.nextExpression = inline_p; } else { // return null; } }
private List <ExpressionNode> PrimaryExpressionPrime() { printDebug("Primary Expression Prime"); if (Match(TokenType.OP_MEMBER_ACCESS)) { var tokens = MatchExactly(new TokenType[] { TokenType.OP_MEMBER_ACCESS, TokenType.ID }); var left = new AccessMemoryExpressionNode(new IdentifierExpressionNode(tokens[1])) as ExpressionNode; var right = PrimaryExpressionPrime(); var ret = new List <ExpressionNode>(); if (right.Count > 0 && (right[0] is FunctionCallExpressionNode || right[0] is ArrayAccessExpressionNode || (right[0] is PostAdditiveExpressionNode))) { if (right[0] is FunctionCallExpressionNode) { ((FunctionCallExpressionNode)right[0]).identifier = new IdentifierExpressionNode(tokens[1]); } else if (right[0] is ArrayAccessExpressionNode) { ((ArrayAccessExpressionNode)right[0]).identifier = new IdentifierExpressionNode(tokens[1]); } else { ((PostAdditiveExpressionNode)right[0]).indentifier = left; } } else { ret.Add(left); } ret.AddRange(right); return(ret); } else if (Match(TokenType.PAREN_OPEN) || Match(TokenType.BRACKET_OPEN)) { var left = FuncOrArrayCall(); var right = PrimaryExpressionPrime(); var ret = new List <ExpressionNode>(); ret.Add(left); ret.AddRange(right); return(ret); } else if (MatchAny(this.increment_decrement_operators)) { var token = ConsumeToken(); var left = new PostAdditiveExpressionNode(token) as ExpressionNode; var right = PrimaryExpressionPrime(); var ret = new List <ExpressionNode>(); ret.Add(left); ret.AddRange(right); return(ret); } else { return(new List <ExpressionNode>()); } }