next up previous
Next: Declarations Up: The Abstract Syntax Tree Previous: Identifiers

Expressions

An expression is a combination of operators and operands that yields a value. Operators can be grouped according to the way in which an expression containing them is evaluated, and the constraints that they place upon the operands. Expressions whose operators fall into the same group can be represented by a single context that has the operator as a component. The grouping strategy is a design decision.

Section 6.2.2.1 of the standard defines an lvalue as ``an expression that designates an object''. Except when it is the operand of the sizeof operator, the unary & operator, the ++ operator, the - operator, or the left operand of the . operator or an assignment operator, an lvalue that does not have array type is converted to the value in the designated object. These operators must therefore be distinguished from all others.

The & operator does not use the normal operator identification process because it may require construction of a completely new pointer type.

AST nodes[4]:

RULE: post_lvalue_opr     ::= '++'     END;
RULE: post_lvalue_opr     ::= '-'     END;

RULE: lvalue_operator     ::= '++'     END;
RULE: lvalue_operator     ::= '-'     END;
RULE: lvalue_operator     ::= 'sizeof' END;

RULE: assignment_operator ::= '='      END;
RULE: assignment_operator ::= '*='     END;
RULE: assignment_operator ::= '/='     END;
RULE: assignment_operator ::= '%='     END;
RULE: assignment_operator ::= '+='     END;
RULE: assignment_operator ::= '-='     END;
RULE: assignment_operator ::= '«='    END;
RULE: assignment_operator ::= '»='    END;
RULE: assignment_operator ::= '&='     END;
RULE: assignment_operator ::= '^='     END;
RULE: assignment_operator ::= '|='     END;
This macro is defined in definitions 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, and 18.
This macro is invoked in definition 1.

Separation of this group into three subgroups is based on differing semantics: the value of the expression is taken before the modification with a post_lvalue_op, and only the left operand of an assignment_operator is treated as an lvalue.

Sections 6.3.13 and 6.3.13 of the standard state that the && and || operators guarantee left-to-right evaluation, with a sequence point (a point at which all side effects of previous evaluations are complete - see Section 5.1.2.3 of the standard). For other binary operations, Section 6.3 of the standard says that the order of evaluation of subexpressions and the order in which side effects take place are both unspecified.

AST nodes[5]:

RULE: logical_operator ::= '&&' END;
RULE: logical_operator ::= '||' END;
This macro is defined in definitions 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, and 18.
This macro is invoked in definition 1.

All of the remaining operators have the same lvalue, evaluation order, and side-effect properties. Note that no distinction need be made between unary and binary operators here. That distinction is made by the expression context in which the operator appears. For ease of comparison with the standard, rules have been duplicated for operator indications that are both unary and binary (recall that the unary & is an lvalue_operator, not a normal_operator):

AST nodes[6]:

RULE: normal_operator ::= '*'  END;
RULE: normal_operator ::= '+'  END;
RULE: normal_operator ::= '-'  END;
RULE: normal_operator ::= 'SPMtilde;'  END;
RULE: normal_operator ::= '!'  END;

RULE: normal_operator ::= '*'  END;
RULE: normal_operator ::= '/'  END;
RULE: normal_operator ::= '%'  END;

RULE: normal_operator ::= '+'  END;
RULE: normal_operator ::= '-'  END;

RULE: normal_operator ::= '«' END;
RULE: normal_operator ::= '»' END;

RULE: normal_operator ::= '<'  END;
RULE: normal_operator ::= '>'  END;
RULE: normal_operator ::= '<=' END;
RULE: normal_operator ::= '>=' END;

RULE: normal_operator ::= '==' END;
RULE: normal_operator ::= '!=' END;

RULE: normal_operator ::= '&'  END;

RULE: normal_operator ::= '^'  END;

RULE: normal_operator ::= '|'  END;
This macro is defined in definitions 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, and 18.
This macro is invoked in definition 1.

Given this grouping of operators, the expression contexts are:

AST nodes[7]:

RULE: Expression          ::= IdUse                                     END;
RULE: Expression          ::= character_constant                        END;
RULE: Expression          ::= floating_constant                         END;
RULE: Expression          ::= integer_constant                          END;
RULE: Expression          ::= StringSeq                                 END;

RULE: Expression          ::= Expression '[' Expression ']'             END;
RULE: Expression          ::= Expression '(' Arguments ')'              END;
RULE: Expression          ::= Expression '.' MemberIdUse                END;
RULE: Expression          ::= DerefExpr  '->' MemberIdUse               END;
RULE: Expression          ::= Expression post_lvalue_opr                END;

RULE: Expression          ::= lvalue_operator Expression                END;
RULE: Expression          ::= normal_operator Expression                END;
RULE: Expression          ::= 'sizeof' '(' type_name ')'                END;

RULE: Expression          ::= '(' type_name ')' Expression              END;

RULE: Expression          ::= Expression normal_operator Expression     END;

RULE: Expression          ::= Expression logical_operator Expression    END;

RULE: Expression          ::= Expression '?' Expression ':' Expression  END;

RULE: Expression          ::= Expression assignment_operator RHSExpr    END;

RULE: Expression          ::= Expression ',' Expression                 END;

RULE: constant_expression ::= Expression                                END;
RULE: constant_expression ::=                                           END;

RULE: DerefExpr           ::= Expression                                END;
RULE: RHSExpr             ::= Expression                                END;
This macro is defined in definitions 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, and 18.
This macro is invoked in definition 1.

An argument to a function call has a proper superset of the semantics of an expression. Therefore it is called out as an additional context:

AST nodes[8]:

RULE: Arguments LISTOF Argument   END;
RULE: Argument  ::=    Expression END;
This macro is defined in definitions 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, and 18.
This macro is invoked in definition 1.


next up previous
Next: Declarations Up: The Abstract Syntax Tree Previous: Identifiers
2008-08-30