diff --git a/parser.go b/parser.go index fbe78c4..0e5baa4 100644 --- a/parser.go +++ b/parser.go @@ -365,17 +365,12 @@ const yyEofCode = 1 const yyErrCode = 2 const yyInitialStackSize = 16 -//line parser.y:574 +//line parser.y:611 const src = ` switch_case_list %type case_list %type optional_expr +%type global_var_list +%type global_var +%type static_var_list +%type static_var +%type echo_expr_list +%type echo_expr %% @@ -294,6 +300,9 @@ statement: | T_BREAK optional_expr ';' { $$ = Node("Break").append($2) } | T_CONTINUE optional_expr ';' { $$ = Node("Continue").append($2) } | T_RETURN optional_expr ';' { $$ = Node("Return").append($2) } + | T_GLOBAL global_var_list ';' { $$ = $2; } + | T_STATIC static_var_list ';' { $$ = $2; } + | T_ECHO echo_expr_list ';' { $$ = $2; } | expr ';' { $$ = $1; } if_stmt_without_else: @@ -377,6 +386,34 @@ for_statement: | ':' inner_statement_list T_ENDFOR ';' { $$ = $2; } ; +global_var_list: + global_var_list ',' global_var { $$ = $1.append($3); } + | global_var { $$ = Node("GlobalVarList").append($1); } +; + +global_var: + simple_variable { $$ = $1 } +; + +static_var_list: + static_var_list ',' static_var { $$ = $1.append($3); } + | static_var { $$ = Node("StaticVarList").append($1); } +; + +static_var: + T_VARIABLE { $$ = Node("StaticVariable").attribute("Name", $1); } + | T_VARIABLE '=' expr { $$ = Node("StaticVariable").attribute("Name", $1).append(Node("expr").append($3)); } +; + +echo_expr_list: + echo_expr_list ',' echo_expr { $$ = $1.append($3) } + | echo_expr { $$ = Node("EchoList").append($1) } +; + +echo_expr: + expr { $$ = Node("Echo").append($1) } +; + class_declaration_statement: class_modifiers T_CLASS T_STRING '{' '}' { $$ = $1.attribute("name", $3) } | T_CLASS T_STRING '{' '}' { $$ = Node("Class").attribute("name", $2) } @@ -575,14 +612,9 @@ simple_variable: const src = `