Download phc Documentation

Transcript
Chapter 10. Representing PHP
Variable object attributes: $x->$y
Both the target and the variable name are given by (other) variables.
Comments
A number of nodes in the AST are dedicated “commented nodes”. Their corresponding C++ classes
inherit from Commented_node, which introduces a String_list* attribute called comments.
The commented nodes are class members (Member), statements (Statement), interface and class
definitions (Interface_def, Class_def), switch cases (Switch_case) and catches (Catch).
When the parser encounters a comment in the input, it attaches it either to the previous node in the AST,
or to the next, according to a variable attach_to_previous. This variable is set as follows:
•
It is reset to false at the start of each line
•
It is set to true after seeing a semicolon, or either of the keywords class or function
Thus, in
foo();
// Comment
bar();
the comment gets attached to bar(); (to be precise, to the corresponding Eval_expr node; the
function call itself is an expression and phc does not associate comments with expressions), but in
foo(); // Comment
bar();
the comment gets attached to foo(); instead. The same applies to multiple comments:
foo(); /* A */ /* B */
41