###### Grammar
$*cond_statement
- CondStatement -> ForPart OptNL WhilePart CondSuffix ${
- $0 = $<4;
- $0->forpart = $<1;
- $0->condpart = $3.condpart; $3.condpart = NULL;
- $0->dopart = $3.dopart; $3.dopart = NULL;
+ CondStatement -> ForThen WhilePart CondSuffix ${
+ $0 = $<3;
+ $0->forpart = $1.forpart; $1.forpart = NULL;
+ $0->thenpart = $1.thenpart; $1.thenpart = NULL;
+ $0->condpart = $2.condpart; $2.condpart = NULL;
+ $0->dopart = $2.dopart; $2.dopart = NULL;
}$
| WhilePart CondSuffix ${
$0 = $<2;
$0->condpart = $1.condpart; $1.condpart = NULL;
$0->thenpart = $1.thenpart; $1.thenpart = NULL;
}$
+
CondSuffix -> IfSuffix ${ $0 = $<1; }$
| Newlines case Expression Block CondSuffix ${ {
struct casepart *cp = calloc(1, sizeof(*cp));
$0 = $<2;
}$
+ ThenPart -> then SimpleStatements ${
+ $0 = reorder_bilist($<2);
+ }$
+ | then Block ${
+ $0 = $<2;
+ }$
+
+ ThenPartNL -> ThenPart OptNL ${
+ $0 = $<1;
+ }$
+
WhileHead -> while Block ${
$0 = $<2;
}$
$cond_statement
+ ForThen -> ForPart OptNL ThenPartNL ${
+ $0.forpart = $<1;
+ $0.thenpart = $<3;
+ }$
+ | ForPart OptNL ${
+ $0.forpart = $<1;
+ }$
+
WhilePart -> while Expression Block ${
$0.type = Xcond_statement;
$0.condpart = $<2;
do_indent(indent, "for");
if (bracket) printf(" {\n"); else printf(":\n");
print_exec(cs->forpart, indent+1, bracket);
+ if (cs->thenpart) {
+ if (bracket)
+ do_indent(indent, "} then {\n");
+ else
+ do_indent(indent, "then:\n");
+ print_exec(cs->thenpart, indent+1, bracket);
+ }
if (bracket) do_indent(indent, "}\n");
}
if (cs->dopart) {
else
do_indent(indent, "while:\n");
print_exec(cs->condpart, indent+1, bracket);
- if (cs->thenpart) {
- if (bracket)
- do_indent(indent, "} then {\n");
- else
- do_indent(indent, "then:\n");
- print_exec(cs->thenpart, indent+1, bracket);
- if (bracket)
- do_indent(indent, "}\n");
- }
if (bracket)
do_indent(indent, "} do {\n");
else