2011-04-18 19:02:30 +02:00
|
|
|
%pure_parser
|
|
|
|
%expect 2
|
|
|
|
|
|
|
|
%left T_INCLUDE T_INCLUDE_ONCE T_EVAL T_REQUIRE T_REQUIRE_ONCE
|
|
|
|
%left ','
|
|
|
|
%left T_LOGICAL_OR
|
|
|
|
%left T_LOGICAL_XOR
|
|
|
|
%left T_LOGICAL_AND
|
|
|
|
%right T_PRINT
|
|
|
|
%left '=' T_PLUS_EQUAL T_MINUS_EQUAL T_MUL_EQUAL T_DIV_EQUAL T_CONCAT_EQUAL T_MOD_EQUAL T_AND_EQUAL T_OR_EQUAL T_XOR_EQUAL T_SL_EQUAL T_SR_EQUAL
|
|
|
|
%left '?' ':'
|
|
|
|
%left T_BOOLEAN_OR
|
|
|
|
%left T_BOOLEAN_AND
|
|
|
|
%left '|'
|
|
|
|
%left '^'
|
|
|
|
%left '&'
|
|
|
|
%nonassoc T_IS_EQUAL T_IS_NOT_EQUAL T_IS_IDENTICAL T_IS_NOT_IDENTICAL
|
|
|
|
%nonassoc '<' T_IS_SMALLER_OR_EQUAL '>' T_IS_GREATER_OR_EQUAL
|
|
|
|
%left T_SL T_SR
|
|
|
|
%left '+' '-' '.'
|
|
|
|
%left '*' '/' '%'
|
|
|
|
%right '!'
|
|
|
|
%nonassoc T_INSTANCEOF
|
|
|
|
%right '~' T_INC T_DEC T_INT_CAST T_DOUBLE_CAST T_STRING_CAST T_ARRAY_CAST T_OBJECT_CAST T_BOOL_CAST T_UNSET_CAST '@'
|
|
|
|
%right '['
|
|
|
|
%nonassoc T_NEW T_CLONE
|
|
|
|
%token T_EXIT
|
|
|
|
%token T_IF
|
|
|
|
%left T_ELSEIF
|
|
|
|
%left T_ELSE
|
|
|
|
%left T_ENDIF
|
|
|
|
%token T_LNUMBER
|
|
|
|
%token T_DNUMBER
|
|
|
|
%token T_STRING
|
|
|
|
%token T_STRING_VARNAME
|
|
|
|
%token T_VARIABLE
|
|
|
|
%token T_NUM_STRING
|
|
|
|
%token T_INLINE_HTML
|
|
|
|
%token T_CHARACTER
|
|
|
|
%token T_BAD_CHARACTER
|
|
|
|
%token T_ENCAPSED_AND_WHITESPACE
|
|
|
|
%token T_CONSTANT_ENCAPSED_STRING
|
|
|
|
%token T_ECHO
|
|
|
|
%token T_DO
|
|
|
|
%token T_WHILE
|
|
|
|
%token T_ENDWHILE
|
|
|
|
%token T_FOR
|
|
|
|
%token T_ENDFOR
|
|
|
|
%token T_FOREACH
|
|
|
|
%token T_ENDFOREACH
|
|
|
|
%token T_DECLARE
|
|
|
|
%token T_ENDDECLARE
|
|
|
|
%token T_AS
|
|
|
|
%token T_SWITCH
|
|
|
|
%token T_ENDSWITCH
|
|
|
|
%token T_CASE
|
|
|
|
%token T_DEFAULT
|
|
|
|
%token T_BREAK
|
|
|
|
%token T_CONTINUE
|
|
|
|
%token T_GOTO
|
|
|
|
%token T_FUNCTION
|
|
|
|
%token T_CONST
|
|
|
|
%token T_RETURN
|
|
|
|
%token T_TRY
|
|
|
|
%token T_CATCH
|
|
|
|
%token T_THROW
|
|
|
|
%token T_USE
|
|
|
|
%token T_GLOBAL
|
|
|
|
%right T_STATIC T_ABSTRACT T_FINAL T_PRIVATE T_PROTECTED T_PUBLIC
|
|
|
|
%token T_VAR
|
|
|
|
%token T_UNSET
|
|
|
|
%token T_ISSET
|
|
|
|
%token T_EMPTY
|
|
|
|
%token T_HALT_COMPILER
|
|
|
|
%token T_CLASS
|
|
|
|
%token T_INTERFACE
|
|
|
|
%token T_EXTENDS
|
|
|
|
%token T_IMPLEMENTS
|
|
|
|
%token T_OBJECT_OPERATOR
|
|
|
|
%token T_DOUBLE_ARROW
|
|
|
|
%token T_LIST
|
|
|
|
%token T_ARRAY
|
|
|
|
%token T_CLASS_C
|
|
|
|
%token T_METHOD_C
|
|
|
|
%token T_FUNC_C
|
|
|
|
%token T_LINE
|
|
|
|
%token T_FILE
|
|
|
|
%token T_COMMENT
|
|
|
|
%token T_DOC_COMMENT
|
|
|
|
%token T_OPEN_TAG
|
|
|
|
%token T_OPEN_TAG_WITH_ECHO
|
|
|
|
%token T_CLOSE_TAG
|
|
|
|
%token T_WHITESPACE
|
|
|
|
%token T_START_HEREDOC
|
|
|
|
%token T_END_HEREDOC
|
|
|
|
%token T_DOLLAR_OPEN_CURLY_BRACES
|
|
|
|
%token T_CURLY_OPEN
|
|
|
|
%token T_PAAMAYIM_NEKUDOTAYIM
|
|
|
|
%token T_NAMESPACE
|
|
|
|
%token T_NS_C
|
|
|
|
%token T_DIR
|
|
|
|
%token T_NS_SEPARATOR
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
start:
|
2011-08-04 12:46:48 +02:00
|
|
|
top_statement_list { $$ = Stmt_Namespace::postprocess($1); }
|
2011-04-18 19:02:30 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
top_statement_list:
|
2011-08-04 12:46:48 +02:00
|
|
|
top_statement_list top_statement { pushNormalizing($1, $2); }
|
|
|
|
| /* empty */ { init(); }
|
2011-04-18 19:02:30 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
namespace_name:
|
2011-08-04 12:46:48 +02:00
|
|
|
namespace_name_sub { $$ = Name[parts: $1]; }
|
2011-04-18 19:02:30 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
namespace_name_sub:
|
2011-08-04 12:46:48 +02:00
|
|
|
T_STRING { init($1); }
|
|
|
|
| namespace_name_sub T_NS_SEPARATOR T_STRING { push($1, $3); }
|
2011-04-18 19:02:30 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
top_statement:
|
|
|
|
statement { $$ = $1; }
|
|
|
|
| function_declaration_statement { $$ = $1; }
|
|
|
|
| class_declaration_statement { $$ = $1; }
|
2011-06-12 17:19:12 +02:00
|
|
|
| T_HALT_COMPILER
|
2011-08-04 12:46:48 +02:00
|
|
|
{ $$ = Stmt_HaltCompiler[remaining: $this->lexer->handleHaltCompiler()]; }
|
|
|
|
| T_NAMESPACE namespace_name ';' { $$ = Stmt_Namespace[name: $2, stmts: null]; }
|
|
|
|
| T_NAMESPACE namespace_name '{' top_statement_list '}' { $$ = Stmt_Namespace[name: $2, stmts: $4]; }
|
|
|
|
| T_NAMESPACE '{' top_statement_list '}' { $$ = Stmt_Namespace[name: null, stmts: $3]; }
|
|
|
|
| T_USE use_declarations ';' { $$ = Stmt_Use[uses: $2]; }
|
|
|
|
| constant_declaration ';' { $$ = Stmt_Const[consts: $1]; }
|
2011-04-18 19:02:30 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
use_declarations:
|
2011-08-04 12:46:48 +02:00
|
|
|
use_declarations ',' use_declaration { push($1, $3); }
|
|
|
|
| use_declaration { init($1); }
|
2011-04-18 19:02:30 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
use_declaration:
|
2011-08-04 12:46:48 +02:00
|
|
|
namespace_name { $$ = Stmt_UseUse[name: $1, alias: null]; }
|
|
|
|
| namespace_name T_AS T_STRING { $$ = Stmt_UseUse[name: $1, alias: $3]; }
|
|
|
|
| T_NS_SEPARATOR namespace_name { $$ = Stmt_UseUse[name: $2, alias: null]; }
|
|
|
|
| T_NS_SEPARATOR namespace_name T_AS T_STRING { $$ = Stmt_UseUse[name: $2, alias: $4]; }
|
2011-04-18 19:02:30 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
constant_declaration:
|
2011-08-04 12:46:48 +02:00
|
|
|
constant_declaration ',' T_STRING '=' static_scalar { push($1, Stmt_ConstConst[name: $3, value: $5]); }
|
|
|
|
| T_CONST T_STRING '=' static_scalar { init(Stmt_ConstConst[name: $2, value: $4]); }
|
2011-04-18 19:02:30 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
inner_statement_list:
|
2011-08-04 12:46:48 +02:00
|
|
|
inner_statement_list inner_statement { pushNormalizing($1, $2); }
|
|
|
|
| /* empty */ { init(); }
|
2011-04-18 19:02:30 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
inner_statement:
|
|
|
|
statement { $$ = $1; }
|
|
|
|
| function_declaration_statement { $$ = $1; }
|
|
|
|
| class_declaration_statement { $$ = $1; }
|
2011-08-04 12:46:48 +02:00
|
|
|
| T_HALT_COMPILER { error('__halt_compiler() can only be used from the outermost scope'); }
|
2011-04-18 19:02:30 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
statement:
|
|
|
|
'{' inner_statement_list '}' { $$ = $2; }
|
2011-08-04 12:46:48 +02:00
|
|
|
| T_IF '(' expr ')' statement elseif_list else_single { $$ = Stmt_If[cond: $3, stmts: toArray($5), elseifList: $6, else: $7]; }
|
2011-04-18 19:02:30 +02:00
|
|
|
| T_IF '(' expr ')' ':' inner_statement_list new_elseif_list new_else_single T_ENDIF ';'
|
2011-08-04 12:46:48 +02:00
|
|
|
{ $$ = Stmt_If[cond: $3, stmts: $6, elseifList: $7, else: $8]; }
|
|
|
|
| T_WHILE '(' expr ')' while_statement { $$ = Stmt_While[cond: $3, stmts: toArray($5)]; }
|
|
|
|
| T_DO statement T_WHILE '(' expr ')' ';' { $$ = Stmt_Do[stmts: toArray($2), cond: $5]; }
|
2011-04-18 19:02:30 +02:00
|
|
|
| T_FOR '(' for_expr ';' for_expr ';' for_expr ')' for_statement
|
2011-08-04 12:46:48 +02:00
|
|
|
{ $$ = Stmt_For[init: $3, cond: $5, loop: $7, stmts: toArray($9)]; }
|
|
|
|
| T_SWITCH '(' expr ')' switch_case_list { $$ = Stmt_Switch[cond: $3, caseList: $5]; }
|
|
|
|
| T_BREAK ';' { $$ = Stmt_Break[num: null]; }
|
|
|
|
| T_BREAK expr ';' { $$ = Stmt_Break[num: $2]; }
|
|
|
|
| T_CONTINUE ';' { $$ = Stmt_Continue[num: null]; }
|
|
|
|
| T_CONTINUE expr ';' { $$ = Stmt_Continue[num: $2]; }
|
|
|
|
| T_RETURN ';' { $$ = Stmt_Return[expr: null]; }
|
|
|
|
| T_RETURN expr ';' { $$ = Stmt_Return[expr: $2]; }
|
|
|
|
| T_GLOBAL global_var_list ';' { $$ = Stmt_Global[vars: $2]; }
|
|
|
|
| T_STATIC static_var_list ';' { $$ = Stmt_Static[vars: $2]; }
|
|
|
|
| T_ECHO expr_list ';' { $$ = Stmt_Echo[exprs: $2]; }
|
|
|
|
| T_INLINE_HTML { $$ = Stmt_InlineHTML[value: $1]; }
|
2011-04-18 19:02:30 +02:00
|
|
|
| expr ';' { $$ = $1; }
|
2011-08-04 12:46:48 +02:00
|
|
|
| T_UNSET '(' variables_list ')' ';' { $$ = Stmt_Unset[vars: $3]; }
|
2011-04-18 19:02:30 +02:00
|
|
|
| T_FOREACH '(' expr T_AS variable ')' foreach_statement
|
2011-08-04 12:46:48 +02:00
|
|
|
{ $$ = Stmt_Foreach[expr: $3, keyVar: null, byRef: false, valueVar: $5, stmts: toArray($7)]; }
|
2011-04-18 19:02:30 +02:00
|
|
|
| T_FOREACH '(' expr T_AS '&' variable ')' foreach_statement
|
2011-08-04 12:46:48 +02:00
|
|
|
{ $$ = Stmt_Foreach[expr: $3, keyVar: null, byRef: true, valueVar: $6, stmts: toArray($8)]; }
|
2011-04-18 19:02:30 +02:00
|
|
|
| T_FOREACH '(' expr T_AS variable T_DOUBLE_ARROW optional_ref variable ')' foreach_statement
|
2011-08-04 12:46:48 +02:00
|
|
|
{ $$ = Stmt_Foreach[expr: $3, keyVar: $5, byRef: $7, valueVar: $8, stmts: toArray($10)]; }
|
|
|
|
| T_DECLARE '(' declare_list ')' declare_statement { $$ = Stmt_Declare[declares: $3, stmts: toArray($5)]; }
|
2011-05-30 17:39:20 +02:00
|
|
|
| ';' { $$ = array(); /* means: no statement */ }
|
2011-08-04 12:46:48 +02:00
|
|
|
| T_TRY '{' inner_statement_list '}' catches { $$ = Stmt_TryCatch[stmts: $3, catches: $5]; }
|
|
|
|
| T_THROW expr ';' { $$ = Stmt_Throw[expr: $2]; }
|
|
|
|
| T_GOTO T_STRING ';' { $$ = Stmt_Goto[name: $2]; }
|
|
|
|
| T_STRING ':' { $$ = Stmt_Label[name: $1]; }
|
2011-04-18 19:02:30 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
catches:
|
2011-08-04 12:46:48 +02:00
|
|
|
catch { init($1); }
|
|
|
|
| catches catch { push($1, $2); }
|
2011-04-18 19:02:30 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
catch:
|
|
|
|
T_CATCH '(' name T_VARIABLE ')' '{' inner_statement_list '}'
|
2011-08-04 12:46:48 +02:00
|
|
|
{ $$ = Stmt_Catch[type: $3, var: parseVar($4), stmts: $7]; }
|
2011-04-18 19:02:30 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
variables_list:
|
2011-08-04 12:46:48 +02:00
|
|
|
variable { init($1); }
|
|
|
|
| variables_list ',' variable { push($1, $3); }
|
2011-04-18 19:02:30 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
optional_ref:
|
|
|
|
/* empty */ { $$ = false; }
|
|
|
|
| '&' { $$ = true; }
|
|
|
|
;
|
|
|
|
|
|
|
|
function_declaration_statement:
|
|
|
|
T_FUNCTION optional_ref T_STRING '(' parameter_list ')' '{' inner_statement_list '}'
|
2011-08-04 12:46:48 +02:00
|
|
|
{ $$ = Stmt_Func[byRef: $2, name: $3, params: $5, stmts: $8]; }
|
2011-04-18 19:02:30 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
class_declaration_statement:
|
|
|
|
class_entry_type T_STRING extends_from implements_list '{' class_statement_list '}'
|
2011-08-04 12:46:48 +02:00
|
|
|
{ $$ = Stmt_Class[type: $1, name: $2, extends: $3, implements: $4, stmts: $6]; }
|
2011-04-18 19:02:30 +02:00
|
|
|
| T_INTERFACE T_STRING interface_extends_list '{' class_statement_list '}'
|
2011-08-04 12:46:48 +02:00
|
|
|
{ $$ = Stmt_Interface[name: $2, extends: $3, stmts: $5]; }
|
2011-04-18 19:02:30 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
class_entry_type:
|
|
|
|
T_CLASS { $$ = 0; }
|
2011-08-04 12:46:48 +02:00
|
|
|
| T_ABSTRACT T_CLASS { $$ = Stmt_Class::MODIFIER_ABSTRACT; }
|
|
|
|
| T_FINAL T_CLASS { $$ = Stmt_Class::MODIFIER_FINAL; }
|
2011-04-18 19:02:30 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
extends_from:
|
|
|
|
/* empty */ { $$ = null; }
|
|
|
|
| T_EXTENDS name { $$ = $2; }
|
|
|
|
;
|
|
|
|
|
|
|
|
interface_extends_list:
|
|
|
|
/* empty */ { $$ = array(); }
|
|
|
|
| T_EXTENDS interface_list { $$ = $2; }
|
|
|
|
;
|
|
|
|
|
|
|
|
implements_list:
|
|
|
|
/* empty */ { $$ = array(); }
|
|
|
|
| T_IMPLEMENTS interface_list { $$ = $2; }
|
|
|
|
;
|
|
|
|
|
|
|
|
interface_list:
|
2011-08-04 12:46:48 +02:00
|
|
|
name { init($1); }
|
|
|
|
| interface_list ',' name { push($1, $3); }
|
2011-04-18 19:02:30 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
for_statement:
|
|
|
|
statement { $$ = $1; }
|
|
|
|
| ':' inner_statement_list T_ENDFOR ';' { $$ = $2; }
|
|
|
|
;
|
|
|
|
|
|
|
|
foreach_statement:
|
|
|
|
statement { $$ = $1; }
|
|
|
|
| ':' inner_statement_list T_ENDFOREACH ';' { $$ = $2; }
|
|
|
|
;
|
|
|
|
|
|
|
|
declare_statement:
|
|
|
|
statement { $$ = $1; }
|
|
|
|
| ':' inner_statement_list T_ENDDECLARE ';' { $$ = $2; }
|
|
|
|
;
|
|
|
|
|
|
|
|
declare_list:
|
2011-08-04 12:46:48 +02:00
|
|
|
T_STRING '=' static_scalar { init(Stmt_DeclareDeclare[key: $1, value: $3]); }
|
|
|
|
| declare_list ',' T_STRING '=' static_scalar { push($1, Stmt_DeclareDeclare[key: $3, value: $5]); }
|
2011-04-18 19:02:30 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
switch_case_list:
|
|
|
|
'{' case_list '}' { $$ = $2; }
|
|
|
|
| '{' ';' case_list '}' { $$ = $3; }
|
|
|
|
| ':' case_list T_ENDSWITCH ';' { $$ = $2; }
|
|
|
|
| ':' ';' case_list T_ENDSWITCH ';' { $$ = $3; }
|
|
|
|
;
|
|
|
|
|
|
|
|
case_list:
|
2011-08-04 12:46:48 +02:00
|
|
|
/* empty */ { init(); }
|
2011-04-18 19:02:30 +02:00
|
|
|
| case_list T_CASE expr case_separator inner_statement_list
|
2011-08-04 12:46:48 +02:00
|
|
|
{ push($1, Stmt_Case[cond: $3, stmts: $5]); }
|
2011-04-18 19:02:30 +02:00
|
|
|
| case_list T_DEFAULT case_separator inner_statement_list
|
2011-08-04 12:46:48 +02:00
|
|
|
{ push($1, Stmt_Case[cond: null, stmts: $4]); }
|
2011-04-18 19:02:30 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
case_separator:
|
|
|
|
':'
|
|
|
|
| ';'
|
|
|
|
;
|
|
|
|
|
|
|
|
while_statement:
|
|
|
|
statement { $$ = $1; }
|
|
|
|
| ':' inner_statement_list T_ENDWHILE ';' { $$ = $2; }
|
|
|
|
;
|
|
|
|
|
|
|
|
elseif_list:
|
2011-08-04 12:46:48 +02:00
|
|
|
/* empty */ { init();}
|
|
|
|
| elseif_list T_ELSEIF '(' expr ')' statement { push($1, Stmt_ElseIf[cond: $4, stmts: toArray($6)]); }
|
2011-04-18 19:02:30 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
new_elseif_list:
|
2011-08-04 12:46:48 +02:00
|
|
|
/* empty */ { init(); }
|
2011-04-18 19:02:30 +02:00
|
|
|
| new_elseif_list T_ELSEIF '(' expr ')' ':' inner_statement_list
|
2011-08-04 12:46:48 +02:00
|
|
|
{ push($1, Stmt_ElseIf[cond: $4, stmts: $7]); }
|
2011-04-18 19:02:30 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
else_single:
|
|
|
|
/* empty */ { $$ = null; }
|
2011-08-04 12:46:48 +02:00
|
|
|
| T_ELSE statement { $$ = Stmt_Else[stmts: toArray($2)]; }
|
2011-04-18 19:02:30 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
new_else_single:
|
|
|
|
/* empty */ { $$ = null; }
|
2011-08-04 12:46:48 +02:00
|
|
|
| T_ELSE ':' inner_statement_list { $$ = Stmt_Else[stmts: $3]; }
|
2011-04-18 19:02:30 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
parameter_list:
|
|
|
|
non_empty_parameter_list { $$ = $1; }
|
|
|
|
| /* empty */ { $$ = array(); }
|
|
|
|
;
|
|
|
|
|
|
|
|
non_empty_parameter_list:
|
|
|
|
optional_class_type optional_ref T_VARIABLE
|
2011-08-04 12:46:48 +02:00
|
|
|
{ init(Stmt_FuncParam[type: $1, name: parseVar($3), byRef: $2, default: null]); }
|
2011-04-18 19:02:30 +02:00
|
|
|
| optional_class_type optional_ref T_VARIABLE '=' static_scalar
|
2011-08-04 12:46:48 +02:00
|
|
|
{ init(Stmt_FuncParam[type: $1, name: parseVar($3), byRef: $2, default: $5]); }
|
2011-04-18 19:02:30 +02:00
|
|
|
| non_empty_parameter_list ',' optional_class_type optional_ref T_VARIABLE
|
2011-08-04 12:46:48 +02:00
|
|
|
{ push($1, Stmt_FuncParam[type: $3, name: parseVar($5), byRef: $4, default: null]); }
|
2011-04-18 19:02:30 +02:00
|
|
|
| non_empty_parameter_list ',' optional_class_type optional_ref T_VARIABLE '=' static_scalar
|
2011-08-04 12:46:48 +02:00
|
|
|
{ push($1, Stmt_FuncParam[type: $3, name: parseVar($5), byRef: $4, default: $7]); }
|
2011-04-18 19:02:30 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
optional_class_type:
|
|
|
|
/* empty */ { $$ = null; }
|
|
|
|
| name { $$ = $1; }
|
|
|
|
| T_ARRAY { $$ = 'array'; }
|
|
|
|
;
|
|
|
|
|
2011-05-27 18:20:44 +02:00
|
|
|
function_call_argument_list:
|
|
|
|
non_empty_function_call_argument_list { $$ = $1; }
|
2011-04-18 19:02:30 +02:00
|
|
|
| /* empty */ { $$ = array(); }
|
|
|
|
;
|
|
|
|
|
2011-05-27 18:20:44 +02:00
|
|
|
non_empty_function_call_argument_list:
|
2011-08-04 12:46:48 +02:00
|
|
|
expr { init(Expr_FuncCallArg[value: $1, byRef: false]); }
|
|
|
|
| '&' variable { init(Expr_FuncCallArg[value: $2, byRef: true]); }
|
2011-06-02 17:01:22 +02:00
|
|
|
| non_empty_function_call_argument_list ',' expr
|
2011-08-04 12:46:48 +02:00
|
|
|
{ push($1, Expr_FuncCallArg[value: $3, byRef: false]); }
|
2011-05-27 18:20:44 +02:00
|
|
|
| non_empty_function_call_argument_list ',' '&' variable
|
2011-08-04 12:46:48 +02:00
|
|
|
{ push($1, Expr_FuncCallArg[value: $4, byRef: true]); }
|
2011-04-18 19:02:30 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
global_var_list:
|
2011-08-04 12:46:48 +02:00
|
|
|
global_var_list ',' global_var { push($1, $3); }
|
|
|
|
| global_var { init($1); }
|
2011-04-18 19:02:30 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
global_var:
|
2011-08-04 12:46:48 +02:00
|
|
|
T_VARIABLE { $$ = Variable[name: parseVar($1)]; }
|
|
|
|
| '$' variable { $$ = Variable[name: $2]; }
|
|
|
|
| '$' '{' expr '}' { $$ = Variable[name: $3]; }
|
2011-04-18 19:02:30 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
static_var_list:
|
2011-08-04 12:46:48 +02:00
|
|
|
static_var_list ',' T_VARIABLE { push($1, Stmt_StaticVar[name: parseVar($3), default: null]); }
|
|
|
|
| static_var_list ',' T_VARIABLE '=' static_scalar { push($1, Stmt_StaticVar[name: parseVar($3), default: $5]); }
|
|
|
|
| T_VARIABLE { init(Stmt_StaticVar[name: parseVar($1), default: null]); }
|
|
|
|
| T_VARIABLE '=' static_scalar { init(Stmt_StaticVar[name: parseVar($1), default: $3]); }
|
2011-04-18 19:02:30 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
class_statement_list:
|
2011-08-04 12:46:48 +02:00
|
|
|
class_statement_list class_statement { push($1, $2); }
|
|
|
|
| /* empty */ { init(); }
|
2011-04-18 19:02:30 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
class_statement:
|
2011-08-04 12:46:48 +02:00
|
|
|
variable_modifiers class_variable_declaration ';' { $$ = Stmt_Property[type: $1, props: $2]; }
|
|
|
|
| class_constant_declaration ';' { $$ = Stmt_ClassConst[consts: $1]; }
|
2011-04-18 19:02:30 +02:00
|
|
|
| method_modifiers T_FUNCTION optional_ref T_STRING '(' parameter_list ')' method_body
|
2011-08-04 12:46:48 +02:00
|
|
|
{ $$ = Stmt_ClassMethod[type: $1, byRef: $3, name: $4, params: $6, stmts: $8]; }
|
2011-04-18 19:02:30 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
method_body:
|
|
|
|
';' /* abstract method */ { $$ = null; }
|
|
|
|
| '{' inner_statement_list '}' { $$ = $2; }
|
|
|
|
;
|
|
|
|
|
|
|
|
variable_modifiers:
|
|
|
|
non_empty_member_modifiers { $$ = $1; }
|
2011-08-04 12:46:48 +02:00
|
|
|
| T_VAR { $$ = Stmt_Class::MODIFIER_PUBLIC; }
|
2011-04-18 19:02:30 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
method_modifiers:
|
2011-08-04 12:46:48 +02:00
|
|
|
/* empty */ { $$ = Stmt_Class::MODIFIER_PUBLIC; }
|
2011-04-18 19:02:30 +02:00
|
|
|
| non_empty_member_modifiers { $$ = $1; }
|
|
|
|
;
|
|
|
|
|
|
|
|
non_empty_member_modifiers:
|
|
|
|
member_modifier { $$ = $1; }
|
2011-08-04 12:46:48 +02:00
|
|
|
| non_empty_member_modifiers member_modifier { Stmt_Class::verifyModifier($1, $2); $$ = $1 | $2; }
|
2011-04-18 19:02:30 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
member_modifier:
|
2011-08-04 12:46:48 +02:00
|
|
|
T_PUBLIC { $$ = Stmt_Class::MODIFIER_PUBLIC; }
|
|
|
|
| T_PROTECTED { $$ = Stmt_Class::MODIFIER_PROTECTED; }
|
|
|
|
| T_PRIVATE { $$ = Stmt_Class::MODIFIER_PRIVATE; }
|
|
|
|
| T_STATIC { $$ = Stmt_Class::MODIFIER_STATIC; }
|
|
|
|
| T_ABSTRACT { $$ = Stmt_Class::MODIFIER_ABSTRACT; }
|
|
|
|
| T_FINAL { $$ = Stmt_Class::MODIFIER_FINAL; }
|
2011-04-18 19:02:30 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
class_variable_declaration:
|
|
|
|
class_variable_declaration ',' T_VARIABLE
|
2011-08-04 12:46:48 +02:00
|
|
|
{ push($1, Stmt_PropertyProperty[name: parseVar($3), default: null]); }
|
2011-04-18 19:02:30 +02:00
|
|
|
| class_variable_declaration ',' T_VARIABLE '=' static_scalar
|
2011-08-04 12:46:48 +02:00
|
|
|
{ push($1, Stmt_PropertyProperty[name: parseVar($3), default: $5]); }
|
2011-04-18 19:02:30 +02:00
|
|
|
| T_VARIABLE
|
2011-08-04 12:46:48 +02:00
|
|
|
{ init(Stmt_PropertyProperty[name: parseVar($1), default: null]); }
|
2011-04-18 19:02:30 +02:00
|
|
|
| T_VARIABLE '=' static_scalar
|
2011-08-04 12:46:48 +02:00
|
|
|
{ init(Stmt_PropertyProperty[name: parseVar($1), default: $3]); }
|
2011-04-18 19:02:30 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
class_constant_declaration:
|
|
|
|
class_constant_declaration ',' T_STRING '=' static_scalar
|
2011-08-04 12:46:48 +02:00
|
|
|
{ push($1, Stmt_ClassConstConst[name: $3, value: $5]); }
|
|
|
|
| T_CONST T_STRING '=' static_scalar { init(Stmt_ClassConstConst[name: $2, value: $4]); }
|
2011-04-18 19:02:30 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
expr_list:
|
2011-08-04 12:46:48 +02:00
|
|
|
expr_list ',' expr { push($1, $3); }
|
|
|
|
| expr { init($1); }
|
2011-04-18 19:02:30 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
for_expr:
|
|
|
|
/* empty */ { $$ = array(); }
|
|
|
|
| expr_list { $$ = $1; }
|
|
|
|
;
|
|
|
|
|
2011-06-02 17:01:22 +02:00
|
|
|
expr:
|
|
|
|
variable { $$ = $1; }
|
2011-08-04 12:46:48 +02:00
|
|
|
| T_LIST '(' assignment_list ')' '=' expr { $$ = Expr_List[assignList: $3, expr: $6]; }
|
|
|
|
| variable '=' expr { $$ = Expr_Assign[var: $1, expr: $3]; }
|
|
|
|
| variable '=' '&' variable { $$ = Expr_AssignRef[var: $1, refVar: $4]; }
|
2011-04-18 19:02:30 +02:00
|
|
|
| variable '=' '&' T_NEW class_name_reference ctor_arguments
|
2011-08-04 12:46:48 +02:00
|
|
|
{ $$ = Expr_Assign[var: $1, expr: Expr_New[class: $5, args: $6]]; }
|
2011-04-18 19:02:30 +02:00
|
|
|
/* reference dropped intentially, TODO: Throw error? */
|
2011-08-04 12:46:48 +02:00
|
|
|
| T_NEW class_name_reference ctor_arguments { $$ = Expr_New[class: $2, args: $3]; }
|
|
|
|
| T_CLONE expr { $$ = Expr_Clone[expr: $2]; }
|
|
|
|
| variable T_PLUS_EQUAL expr { $$ = Expr_AssignPlus[var: $1, expr: $3]; }
|
|
|
|
| variable T_MINUS_EQUAL expr { $$ = Expr_AssignMinus[var: $1, expr: $3]; }
|
|
|
|
| variable T_MUL_EQUAL expr { $$ = Expr_AssignMul[var: $1, expr: $3]; }
|
|
|
|
| variable T_DIV_EQUAL expr { $$ = Expr_AssignDiv[var: $1, expr: $3]; }
|
|
|
|
| variable T_CONCAT_EQUAL expr { $$ = Expr_AssignConcat[var: $1, expr: $3]; }
|
|
|
|
| variable T_MOD_EQUAL expr { $$ = Expr_AssignMod[var: $1, expr: $3]; }
|
|
|
|
| variable T_AND_EQUAL expr { $$ = Expr_AssignBinAnd[var: $1, expr: $3]; }
|
|
|
|
| variable T_OR_EQUAL expr { $$ = Expr_AssignBinOr[var: $1, expr: $3]; }
|
|
|
|
| variable T_XOR_EQUAL expr { $$ = Expr_AssignBinXor[var: $1, expr: $3]; }
|
|
|
|
| variable T_SL_EQUAL expr { $$ = Expr_AssignShiftLeft[var: $1, expr: $3]; }
|
|
|
|
| variable T_SR_EQUAL expr { $$ = Expr_AssignShiftRight[var: $1, expr: $3]; }
|
|
|
|
| variable T_INC { $$ = Expr_PostInc[var: $1]; }
|
|
|
|
| T_INC variable { $$ = Expr_PreInc[var: $2]; }
|
|
|
|
| variable T_DEC { $$ = Expr_PostDec[var: $1]; }
|
|
|
|
| T_DEC variable { $$ = Expr_PreDec[var: $2]; }
|
|
|
|
| expr T_BOOLEAN_OR expr { $$ = Expr_BooleanOr[left: $1, right: $3]; }
|
|
|
|
| expr T_BOOLEAN_AND expr { $$ = Expr_BooleanAnd[left: $1, right: $3]; }
|
|
|
|
| expr T_LOGICAL_OR expr { $$ = Expr_LogicalOr[left: $1, right: $3]; }
|
|
|
|
| expr T_LOGICAL_AND expr { $$ = Expr_LogicalAnd[left: $1, right: $3]; }
|
|
|
|
| expr T_LOGICAL_XOR expr { $$ = Expr_LogicalXor[left: $1, right: $3]; }
|
|
|
|
| expr '|' expr { $$ = Expr_BinaryOr[left: $1, right: $3]; }
|
|
|
|
| expr '&' expr { $$ = Expr_BinaryAnd[left: $1, right: $3]; }
|
|
|
|
| expr '^' expr { $$ = Expr_BinaryXor[left: $1, right: $3]; }
|
|
|
|
| expr '.' expr { $$ = Expr_Concat[left: $1, right: $3]; }
|
|
|
|
| expr '+' expr { $$ = Expr_Plus[left: $1, right: $3]; }
|
|
|
|
| expr '-' expr { $$ = Expr_Minus[left: $1, right: $3]; }
|
|
|
|
| expr '*' expr { $$ = Expr_Mul[left: $1, right: $3]; }
|
|
|
|
| expr '/' expr { $$ = Expr_Div[left: $1, right: $3]; }
|
|
|
|
| expr '%' expr { $$ = Expr_Mod[left: $1, right: $3]; }
|
|
|
|
| expr T_SL expr { $$ = Expr_ShiftLeft[left: $1, right: $3]; }
|
|
|
|
| expr T_SR expr { $$ = Expr_ShiftRight[left: $1, right: $3]; }
|
|
|
|
| '+' expr %prec T_INC { $$ = Expr_UnaryPlus[expr: $2]; }
|
|
|
|
| '-' expr %prec T_INC { $$ = Expr_UnaryMinus[expr: $2]; }
|
|
|
|
| '!' expr { $$ = Expr_BooleanNot[expr: $2]; }
|
|
|
|
| '~' expr { $$ = Expr_BinaryNot[expr: $2]; }
|
|
|
|
| expr T_IS_IDENTICAL expr { $$ = Expr_Identical[left: $1, right: $3]; }
|
|
|
|
| expr T_IS_NOT_IDENTICAL expr { $$ = Expr_NotIdentical[left: $1, right: $3]; }
|
|
|
|
| expr T_IS_EQUAL expr { $$ = Expr_Equal[left: $1, right: $3]; }
|
|
|
|
| expr T_IS_NOT_EQUAL expr { $$ = Expr_NotEqual[left: $1, right: $3]; }
|
|
|
|
| expr '<' expr { $$ = Expr_Smaller[left: $1, right: $3]; }
|
|
|
|
| expr T_IS_SMALLER_OR_EQUAL expr { $$ = Expr_SmallerOrEqual[left: $1, right: $3]; }
|
|
|
|
| expr '>' expr { $$ = Expr_Greater[left: $1, right: $3]; }
|
|
|
|
| expr T_IS_GREATER_OR_EQUAL expr { $$ = Expr_GreaterOrEqual[left: $1, right: $3]; }
|
|
|
|
| expr T_INSTANCEOF class_name_reference { $$ = Expr_Instanceof[expr: $1, class: $3]; }
|
2011-04-18 19:02:30 +02:00
|
|
|
| '(' expr ')' { $$ = $2; }
|
2011-08-04 12:46:48 +02:00
|
|
|
| expr '?' expr ':' expr { $$ = Expr_Ternary[cond: $1, if: $3, else: $5]; }
|
|
|
|
| expr '?' ':' expr { $$ = Expr_Ternary[cond: $1, if: null, else: $4]; }
|
|
|
|
| T_ISSET '(' variables_list ')' { $$ = Expr_Isset[vars: $3]; }
|
|
|
|
| T_EMPTY '(' variable ')' { $$ = Expr_Empty[var: $3]; }
|
|
|
|
| T_INCLUDE expr { $$ = Expr_Include[expr: $2, type: Expr_Include::TYPE_INCLUDE]; }
|
|
|
|
| T_INCLUDE_ONCE expr { $$ = Expr_Include[expr: $2, type: Expr_Include::TYPE_INCLUDE_ONCE]; }
|
|
|
|
| T_EVAL '(' expr ')' { $$ = Expr_Eval[expr: $3]; }
|
|
|
|
| T_REQUIRE expr { $$ = Expr_Include[expr: $2, type: Expr_Include::TYPE_REQUIRE]; }
|
|
|
|
| T_REQUIRE_ONCE expr { $$ = Expr_Include[expr: $2, type: Expr_Include::TYPE_REQUIRE_ONCE]; }
|
|
|
|
| T_INT_CAST expr { $$ = Expr_IntCast[expr: $2]; }
|
|
|
|
| T_DOUBLE_CAST expr { $$ = Expr_DoubleCast[expr: $2]; }
|
|
|
|
| T_STRING_CAST expr { $$ = Expr_StringCast[expr: $2]; }
|
|
|
|
| T_ARRAY_CAST expr { $$ = Expr_ArrayCast[expr: $2]; }
|
|
|
|
| T_OBJECT_CAST expr { $$ = Expr_ObjectCast[expr: $2]; }
|
|
|
|
| T_BOOL_CAST expr { $$ = Expr_BoolCast[expr: $2]; }
|
|
|
|
| T_UNSET_CAST expr { $$ = Expr_UnsetCast[expr: $2]; }
|
|
|
|
| T_EXIT exit_expr { $$ = Expr_Exit[expr: $2]; }
|
|
|
|
| '@' expr { $$ = Expr_ErrorSuppress[expr: $2]; }
|
2011-04-18 19:02:30 +02:00
|
|
|
| scalar { $$ = $1; }
|
2011-08-04 12:46:48 +02:00
|
|
|
| T_ARRAY '(' array_pair_list ')' { $$ = Expr_Array[items: $3]; }
|
|
|
|
| '`' backticks_expr '`' { $$ = Expr_ShellExec[parts: $2]; }
|
|
|
|
| T_PRINT expr { $$ = Expr_Print[expr: $2]; }
|
2011-04-18 19:02:30 +02:00
|
|
|
| T_FUNCTION optional_ref '(' parameter_list ')' lexical_vars '{' inner_statement_list '}'
|
2011-08-04 12:46:48 +02:00
|
|
|
{ $$ = Expr_LambdaFunc[byRef: $2, params: $4, useVars: $6, stmts: $8]; }
|
2011-04-18 19:02:30 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
lexical_vars:
|
|
|
|
/* empty */ { $$ = array(); }
|
|
|
|
| T_USE '(' lexical_var_list ')' { $$ = $3; }
|
|
|
|
;
|
|
|
|
|
|
|
|
lexical_var_list:
|
|
|
|
lexical_var_list ',' optional_ref T_VARIABLE
|
2011-08-04 12:46:48 +02:00
|
|
|
{ push($1, Expr_LambdaFuncUse[var: parseVar($4), byRef: $3]); }
|
2011-04-18 19:02:30 +02:00
|
|
|
| optional_ref T_VARIABLE
|
2011-08-04 12:46:48 +02:00
|
|
|
{ init(Expr_LambdaFuncUse[var: parseVar($2), byRef: $1]); }
|
2011-04-18 19:02:30 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
function_call:
|
2011-08-04 12:46:48 +02:00
|
|
|
name '(' function_call_argument_list ')' { $$ = Expr_FuncCall[func: $1, args: $3]; }
|
2011-05-27 18:20:44 +02:00
|
|
|
| class_name T_PAAMAYIM_NEKUDOTAYIM T_STRING '(' function_call_argument_list ')'
|
2011-08-04 12:46:48 +02:00
|
|
|
{ $$ = Expr_StaticCall[class: $1, func: $3, args: $5]; }
|
2011-05-27 18:20:44 +02:00
|
|
|
| reference_variable T_PAAMAYIM_NEKUDOTAYIM T_STRING '(' function_call_argument_list ')'
|
2011-08-04 12:46:48 +02:00
|
|
|
{ $$ = Expr_StaticCall[class: $1, func: $3, args: $5]; }
|
2011-06-02 16:29:28 +02:00
|
|
|
| static_property_with_arrays '(' function_call_argument_list ')' {
|
2011-06-05 18:40:04 +02:00
|
|
|
if ($1 instanceof PHPParser_Node_Expr_StaticPropertyFetch) {
|
2011-08-04 12:46:48 +02:00
|
|
|
$$ = Expr_StaticCall[class: $1->class, func: $1->name, args: $3];
|
2011-06-05 18:40:04 +02:00
|
|
|
} elseif ($1 instanceof PHPParser_Node_Expr_ArrayDimFetch) {
|
2011-08-04 12:46:48 +02:00
|
|
|
$tmp = $1;
|
|
|
|
while ($tmp->var instanceof PHPParser_Node_Expr_ArrayDimFetch) {
|
|
|
|
$tmp = $tmp->var;
|
2011-06-02 16:29:28 +02:00
|
|
|
}
|
|
|
|
|
2011-08-04 12:46:48 +02:00
|
|
|
$$ = Expr_StaticCall[class: $tmp->var->class, func: $1, args: $3];
|
|
|
|
$tmp->var = Variable[name: $tmp->var->name];
|
2011-06-02 16:29:28 +02:00
|
|
|
} else {
|
|
|
|
throw new Exception;
|
|
|
|
}
|
|
|
|
}
|
2011-05-27 18:20:44 +02:00
|
|
|
| variable_without_objects '(' function_call_argument_list ')'
|
2011-08-04 12:46:48 +02:00
|
|
|
{ $$ = Expr_FuncCall[func: $1, args: $3]; }
|
2011-04-18 19:02:30 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
class_name:
|
|
|
|
T_STATIC { $$ = 'static'; }
|
|
|
|
| name { $$ = $1; }
|
|
|
|
;
|
|
|
|
|
|
|
|
name:
|
|
|
|
namespace_name { $$ = $1; }
|
2011-08-04 13:23:35 +02:00
|
|
|
| T_NAMESPACE T_NS_SEPARATOR namespace_name { $3->setResolveType(Name::RELATIVE); $$ = $3; }
|
|
|
|
| T_NS_SEPARATOR namespace_name { $2->setResolveType(Name::FULLY_QUALIFIED); $$ = $2; }
|
2011-04-18 19:02:30 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
class_name_reference:
|
|
|
|
class_name { $$ = $1; }
|
|
|
|
| dynamic_class_name_reference { $$ = $1; }
|
|
|
|
;
|
|
|
|
|
|
|
|
dynamic_class_name_reference:
|
2011-05-27 21:15:38 +02:00
|
|
|
object_access_for_dcnr { $$ = $1; }
|
2011-04-18 19:02:30 +02:00
|
|
|
| base_variable { $$ = $1; }
|
|
|
|
;
|
|
|
|
|
2011-05-27 21:15:38 +02:00
|
|
|
object_access_for_dcnr:
|
|
|
|
| base_variable T_OBJECT_OPERATOR object_property
|
2011-08-04 12:46:48 +02:00
|
|
|
{ $$ = Expr_PropertyFetch[var: $1, name: $3]; }
|
2011-05-27 21:15:38 +02:00
|
|
|
| object_access_for_dcnr T_OBJECT_OPERATOR object_property
|
2011-08-04 12:46:48 +02:00
|
|
|
{ $$ = Expr_PropertyFetch[var: $1, name: $3]; }
|
|
|
|
| object_access_for_dcnr '[' dim_offset ']' { $$ = Expr_ArrayDimFetch[var: $1, dim: $3]; }
|
|
|
|
| object_access_for_dcnr '{' expr '}' { $$ = Expr_ArrayDimFetch[var: $1, dim: $3]; }
|
2011-05-27 21:15:38 +02:00
|
|
|
;
|
|
|
|
|
2011-04-18 19:02:30 +02:00
|
|
|
exit_expr:
|
|
|
|
/* empty */ { $$ = null; }
|
|
|
|
| '(' ')' { $$ = null; }
|
|
|
|
| '(' expr ')' { $$ = $2; }
|
|
|
|
;
|
|
|
|
|
|
|
|
backticks_expr:
|
2011-05-29 19:38:04 +02:00
|
|
|
/* empty */ { $$ = array(); }
|
2011-08-04 12:46:48 +02:00
|
|
|
| T_ENCAPSED_AND_WHITESPACE { $$ = array(Scalar_String::parseEscapeSequences($1)); }
|
2011-04-18 19:02:30 +02:00
|
|
|
| encaps_list { $$ = $1; }
|
|
|
|
;
|
|
|
|
|
|
|
|
ctor_arguments:
|
|
|
|
/* empty */ { $$ = array(); }
|
2011-05-27 18:20:44 +02:00
|
|
|
| '(' function_call_argument_list ')' { $$ = $2; }
|
2011-04-18 19:02:30 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
common_scalar:
|
2011-08-04 12:46:48 +02:00
|
|
|
T_LNUMBER { $$ = Scalar_LNumber[value: parseLNumber($1)]; }
|
|
|
|
| T_DNUMBER { $$ = Scalar_DNumber[value: parseDNumber($1)]; }
|
|
|
|
| T_CONSTANT_ENCAPSED_STRING { $$ = Scalar_String::create($1, $line); }
|
|
|
|
| T_LINE { $$ = Scalar_LineConst[]; }
|
|
|
|
| T_FILE { $$ = Scalar_FileConst[]; }
|
|
|
|
| T_DIR { $$ = Scalar_DirConst[]; }
|
|
|
|
| T_CLASS_C { $$ = Scalar_ClassConst[]; }
|
|
|
|
| T_METHOD_C { $$ = Scalar_MethodConst[]; }
|
|
|
|
| T_FUNC_C { $$ = Scalar_FuncConst[]; }
|
|
|
|
| T_NS_C { $$ = Scalar_NSConst[]; }
|
2011-04-18 19:02:30 +02:00
|
|
|
| T_START_HEREDOC T_ENCAPSED_AND_WHITESPACE T_END_HEREDOC
|
2011-08-04 12:46:48 +02:00
|
|
|
{ $$ = Scalar_String[value: Scalar_String::parseEscapeSequences($2), isBinary: false, type: '\'' === $1[3] ? Scalar_String::SINGLE_QUOTED : Scalar_String::DOUBLE_QUOTED]; }
|
2011-05-29 19:38:04 +02:00
|
|
|
| T_START_HEREDOC T_END_HEREDOC
|
2011-08-04 12:46:48 +02:00
|
|
|
{ $$ = Scalar_String[value: '', isBinary: false, type: Scalar_String::SINGLE_QUOTED]; }
|
2011-04-18 19:02:30 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
static_scalar: /* compile-time evaluated scalars */
|
|
|
|
common_scalar { $$ = $1; }
|
2011-08-04 12:46:48 +02:00
|
|
|
| name { $$ = Expr_ConstFetch[name: $1]; }
|
|
|
|
| '+' static_scalar { $$ = Expr_UnaryPlus[expr: $2]; }
|
|
|
|
| '-' static_scalar { $$ = Expr_UnaryMinus[expr: $2]; }
|
|
|
|
| T_ARRAY '(' static_array_pair_list ')' { $$ = Expr_Array[items: $3]; }
|
|
|
|
| class_name T_PAAMAYIM_NEKUDOTAYIM T_STRING { $$ = Expr_ClassConstFetch[class: $1, name: $3]; }
|
2011-04-18 19:02:30 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
scalar:
|
2011-08-04 12:46:48 +02:00
|
|
|
T_STRING_VARNAME { $$ = Scalar_String[value: $1, isBinary: false, type: Scalar_String::SINGLE_QUOTED]; }
|
2011-04-18 19:02:30 +02:00
|
|
|
| class_constant { $$ = $1; }
|
2011-08-04 12:46:48 +02:00
|
|
|
| name { $$ = Expr_ConstFetch[name: $1]; }
|
2011-04-18 19:02:30 +02:00
|
|
|
| common_scalar { $$ = $1; }
|
2011-08-04 12:46:48 +02:00
|
|
|
| '"' encaps_list '"' { $$ = Scalar_Encapsed[parts: $2]; }
|
|
|
|
| T_START_HEREDOC encaps_list T_END_HEREDOC { $$ = Scalar_Encapsed[parts: $2]; }
|
2011-04-18 19:02:30 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
static_array_pair_list:
|
|
|
|
/* empty */ { $$ = array(); }
|
|
|
|
| non_empty_static_array_pair_list optional_comma { $$ = $1; }
|
|
|
|
;
|
|
|
|
|
|
|
|
optional_comma:
|
|
|
|
/* empty */
|
|
|
|
| ','
|
|
|
|
;
|
|
|
|
|
|
|
|
non_empty_static_array_pair_list:
|
|
|
|
non_empty_static_array_pair_list ',' static_scalar T_DOUBLE_ARROW static_scalar
|
2011-08-04 12:46:48 +02:00
|
|
|
{ push($1, Expr_ArrayItem[key: $3, value: $5, byRef: false]); }
|
|
|
|
| non_empty_static_array_pair_list ',' static_scalar { push($1, Expr_ArrayItem[key: null, value: $3, byRef: false]); }
|
|
|
|
| static_scalar T_DOUBLE_ARROW static_scalar { init(Expr_ArrayItem[key: $1, value: $3, byRef: false]); }
|
|
|
|
| static_scalar { init(Expr_ArrayItem[key: null, value: $1, byRef: false]); }
|
2011-04-18 19:02:30 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
variable:
|
2011-05-27 21:15:38 +02:00
|
|
|
object_access { $$ = $1; }
|
2011-04-18 19:02:30 +02:00
|
|
|
| base_variable { $$ = $1; }
|
|
|
|
| function_call { $$ = $1; }
|
|
|
|
;
|
|
|
|
|
2011-05-27 21:15:38 +02:00
|
|
|
object_access:
|
2011-05-27 21:51:27 +02:00
|
|
|
object_access_arrayable { $$ = $1; }
|
2011-05-27 21:15:38 +02:00
|
|
|
| object_access_arrayable '(' function_call_argument_list ')'
|
2011-08-04 12:46:48 +02:00
|
|
|
{ $$ = Expr_FuncCall[func: $1, args: $3]; }
|
2011-05-27 21:51:27 +02:00
|
|
|
| variable T_OBJECT_OPERATOR object_property '(' function_call_argument_list ')'
|
2011-08-04 12:46:48 +02:00
|
|
|
{ $$ = Expr_MethodCall[var: $1, name: $3, args: $5]; }
|
2011-05-27 21:15:38 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
object_access_arrayable:
|
2011-05-27 21:51:27 +02:00
|
|
|
variable T_OBJECT_OPERATOR object_property
|
2011-08-04 12:46:48 +02:00
|
|
|
{ $$ = Expr_PropertyFetch[var: $1, name: $3]; }
|
|
|
|
| object_access_arrayable '[' dim_offset ']' { $$ = Expr_ArrayDimFetch[var: $1, dim: $3]; }
|
|
|
|
| object_access_arrayable '{' expr '}' { $$ = Expr_ArrayDimFetch[var: $1, dim: $3]; }
|
2011-05-27 21:15:38 +02:00
|
|
|
;
|
|
|
|
|
2011-04-18 19:02:30 +02:00
|
|
|
variable_without_objects:
|
|
|
|
reference_variable { $$ = $1; }
|
2011-08-04 12:46:48 +02:00
|
|
|
| '$' reference_variable { $$ = Variable[name: $2]; }
|
2011-04-18 19:02:30 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
base_variable:
|
|
|
|
variable_without_objects { $$ = $1; }
|
2011-05-27 18:20:44 +02:00
|
|
|
| class_name T_PAAMAYIM_NEKUDOTAYIM '$' reference_variable
|
2011-08-04 12:46:48 +02:00
|
|
|
{ $$ = Expr_StaticPropertyFetch[class: $1, name: $4]; }
|
2011-05-27 18:20:44 +02:00
|
|
|
| reference_variable T_PAAMAYIM_NEKUDOTAYIM '$' reference_variable
|
2011-08-04 12:46:48 +02:00
|
|
|
{ $$ = Expr_StaticPropertyFetch[class: $1, name: $4]; }
|
2011-05-27 18:20:44 +02:00
|
|
|
| static_property_with_arrays { $$ = $1; }
|
|
|
|
;
|
|
|
|
|
|
|
|
static_property_with_arrays:
|
|
|
|
class_name T_PAAMAYIM_NEKUDOTAYIM T_VARIABLE
|
2011-08-04 12:46:48 +02:00
|
|
|
{ $$ = Expr_StaticPropertyFetch[class: $1, name: parseVar($3)]; }
|
2011-05-31 17:24:01 +02:00
|
|
|
| reference_variable T_PAAMAYIM_NEKUDOTAYIM T_VARIABLE
|
2011-08-04 12:46:48 +02:00
|
|
|
{ $$ = Expr_StaticPropertyFetch[class: $1, name: parseVar($3)]; }
|
2011-05-31 17:24:01 +02:00
|
|
|
| class_name T_PAAMAYIM_NEKUDOTAYIM '$' '{' expr '}'
|
2011-08-04 12:46:48 +02:00
|
|
|
{ $$ = Expr_StaticPropertyFetch[class: $1, name: $5]; }
|
2011-05-27 18:20:44 +02:00
|
|
|
| reference_variable T_PAAMAYIM_NEKUDOTAYIM '$' '{' expr '}'
|
2011-08-04 12:46:48 +02:00
|
|
|
{ $$ = Expr_StaticPropertyFetch[class: $1, name: $5]; }
|
|
|
|
| static_property_with_arrays '[' dim_offset ']' { $$ = Expr_ArrayDimFetch[var: $1, dim: $3]; }
|
|
|
|
| static_property_with_arrays '{' expr '}' { $$ = Expr_ArrayDimFetch[var: $1, dim: $3]; }
|
2011-04-18 19:02:30 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
reference_variable:
|
2011-08-04 12:46:48 +02:00
|
|
|
reference_variable '[' dim_offset ']' { $$ = Expr_ArrayDimFetch[var: $1, dim: $3]; }
|
|
|
|
| reference_variable '{' expr '}' { $$ = Expr_ArrayDimFetch[var: $1, dim: $3]; }
|
|
|
|
| T_VARIABLE { $$ = Variable[name: parseVar($1)]; }
|
|
|
|
| '$' '{' expr '}' { $$ = Variable[name: $3]; }
|
2011-04-18 19:02:30 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
dim_offset:
|
|
|
|
/* empty */ { $$ = null; }
|
|
|
|
| expr { $$ = $1; }
|
|
|
|
;
|
|
|
|
|
|
|
|
object_property:
|
2011-05-27 21:15:38 +02:00
|
|
|
T_STRING { $$ = $1; }
|
2011-04-18 19:02:30 +02:00
|
|
|
| '{' expr '}' { $$ = $2; }
|
2011-05-27 21:15:38 +02:00
|
|
|
| variable_without_objects { $$ = $1; }
|
2011-04-18 19:02:30 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
assignment_list:
|
2011-08-04 12:46:48 +02:00
|
|
|
assignment_list ',' assignment_list_element { push($1, $3); }
|
|
|
|
| assignment_list_element { init($1); }
|
2011-04-18 19:02:30 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
assignment_list_element:
|
|
|
|
variable { $$ = $1; }
|
|
|
|
| T_LIST '(' assignment_list ')' { $$ = $3; }
|
|
|
|
| /* empty */ { $$ = null; }
|
|
|
|
;
|
|
|
|
|
|
|
|
array_pair_list:
|
|
|
|
/* empty */ { $$ = array(); }
|
|
|
|
| non_empty_array_pair_list optional_comma { $$ = $1; }
|
|
|
|
;
|
|
|
|
|
|
|
|
non_empty_array_pair_list:
|
|
|
|
non_empty_array_pair_list ',' expr T_DOUBLE_ARROW expr
|
2011-08-04 12:46:48 +02:00
|
|
|
{ push($1, Expr_ArrayItem[key: $3, value: $5, byRef: false]); }
|
|
|
|
| non_empty_array_pair_list ',' expr { push($1, Expr_ArrayItem[key: null, value: $3, byRef: false]); }
|
|
|
|
| expr T_DOUBLE_ARROW expr { init(Expr_ArrayItem[key: $1, value: $3, byRef: false]); }
|
|
|
|
| expr { init(Expr_ArrayItem[key: null, value: $1, byRef: false]); }
|
2011-04-18 19:02:30 +02:00
|
|
|
| non_empty_array_pair_list ',' expr T_DOUBLE_ARROW '&' variable
|
2011-08-04 12:46:48 +02:00
|
|
|
{ push($1, Expr_ArrayItem[key: $3, value: $6, byRef: true]); }
|
|
|
|
| non_empty_array_pair_list ',' '&' variable { push($1, Expr_ArrayItem[key: null, value: $4, byRef: true]); }
|
|
|
|
| expr T_DOUBLE_ARROW '&' variable { init(Expr_ArrayItem[key: $1, value: $4, byRef: true]); }
|
|
|
|
| '&' variable { init(Expr_ArrayItem[key: null, value: $2, byRef: true]); }
|
2011-04-18 19:02:30 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
encaps_list:
|
2011-08-04 12:46:48 +02:00
|
|
|
encaps_list encaps_var { push($1, $2); }
|
|
|
|
| encaps_list T_ENCAPSED_AND_WHITESPACE { push($1, Scalar_String::parseEscapeSequences($2)); }
|
|
|
|
| encaps_var { init($1); }
|
|
|
|
| T_ENCAPSED_AND_WHITESPACE encaps_var { init(Scalar_String::parseEscapeSequences($1), $2); }
|
2011-04-18 19:02:30 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
encaps_var:
|
2011-08-04 12:46:48 +02:00
|
|
|
T_VARIABLE { $$ = Variable[name: parseVar($1)]; }
|
|
|
|
| T_VARIABLE '[' encaps_var_offset ']' { $$ = Expr_ArrayDimFetch[var: Variable[name: parseVar($1)], dim: $3]; }
|
|
|
|
| T_VARIABLE T_OBJECT_OPERATOR T_STRING { $$ = Expr_PropertyFetch[var: Variable[name: parseVar($1)], name: $3]; }
|
|
|
|
| T_DOLLAR_OPEN_CURLY_BRACES expr '}' { $$ = Variable[name: $2]; }
|
2011-04-18 19:02:30 +02:00
|
|
|
| T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '[' expr ']' '}'
|
2011-08-04 12:46:48 +02:00
|
|
|
{ $$ = Expr_ArrayDimFetch[var: Variable[name: $2], dim: $4]; }
|
2011-04-18 19:02:30 +02:00
|
|
|
| T_CURLY_OPEN variable '}' { $$ = $2; }
|
|
|
|
;
|
|
|
|
|
|
|
|
encaps_var_offset:
|
2011-08-04 12:46:48 +02:00
|
|
|
T_STRING { $$ = Scalar_String[value: $1, isBinary: false, type: Scalar_String::SINGLE_QUOTED]; }
|
|
|
|
| T_NUM_STRING { $$ = Scalar_LNumber[value: parseLNumber($1)]; }
|
|
|
|
| T_VARIABLE { $$ = Variable[name: parseVar($1)]; }
|
2011-04-18 19:02:30 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
class_constant:
|
2011-08-04 12:46:48 +02:00
|
|
|
class_name T_PAAMAYIM_NEKUDOTAYIM T_STRING { $$ = Expr_ClassConstFetch[class: $1, name: $3]; }
|
|
|
|
| reference_variable T_PAAMAYIM_NEKUDOTAYIM T_STRING { $$ = Expr_ClassConstFetch[class: $1, name: $3]; }
|
2011-04-18 19:02:30 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
%%
|