parse While DoWhile stmt

This commit is contained in:
z7zmey 2017-11-28 22:04:30 +02:00
parent bd731b28d5
commit 6a15c6990a
2 changed files with 748 additions and 708 deletions

1438
parser.go

File diff suppressed because it is too large Load Diff

View File

@ -202,6 +202,7 @@ func (n node) attribute(key string, value string) node {
%type <node> if_stmt %type <node> if_stmt
%type <node> alt_if_stmt_without_else %type <node> alt_if_stmt_without_else
%type <node> alt_if_stmt %type <node> alt_if_stmt
%type <node> while_statement
%% %%
@ -273,7 +274,8 @@ statement:
'{' inner_statement_list '}' { $$ = $2; } '{' inner_statement_list '}' { $$ = $2; }
| if_stmt { $$ = $1; } | if_stmt { $$ = $1; }
| alt_if_stmt { $$ = $1; } | alt_if_stmt { $$ = $1; }
| T_DO statement T_WHILE '(' expr ')' ';' { $$ = Node("Do While").append($2).append($5)} | T_WHILE '(' expr ')' while_statement { $$ = Node("While").append(Node("expr").append($3)).append(Node("stmt").append($5)) }
| T_DO statement T_WHILE '(' expr ')' ';' { $$ = Node("DoWhile").append(Node("expr").append($5)).append(Node("stmt").append($2))}
| expr ';' { $$ = $1; } | expr ';' { $$ = $1; }
if_stmt_without_else: if_stmt_without_else:
@ -314,6 +316,12 @@ alt_if_stmt:
} }
; ;
while_statement:
statement { $$ = $1; }
| ':' inner_statement_list T_ENDWHILE ';' { $$ = $2; }
;
class_declaration_statement: class_declaration_statement:
class_modifiers T_CLASS T_STRING '{' '}' { $$ = $1.attribute("name", $3) } class_modifiers T_CLASS T_STRING '{' '}' { $$ = $1.attribute("name", $3) }
| T_CLASS T_STRING '{' '}' { $$ = Node("Class").attribute("name", $2) } | T_CLASS T_STRING '{' '}' { $$ = Node("Class").attribute("name", $2) }
@ -507,13 +515,9 @@ simple_variable:
const src = `<? const src = `<?
if ($a > $b) : do {
$b=$c;
elseif ($a === $b) :
else : } while ($a >= $b || $a < $c);
endif;
` `