RULE(var_decl)
{
(void)item;
- while (1)
+ do
{
int nsyms = 0;
Symbol* sym = NULL;
char* name = NULL;
bool export = false;
- while (1)
+ do
{
name = expect_text(p, IDENT);
export = accept(p, '*');
sym = symbol_new(p, name, SYM_VAR, export);
sym->global = 1;
nsyms++;
-
- if (!accept(p, ','))
- {
- break;
- }
}
+ while (accept(p, ','));
expect(p, ':');
name = expect_text(p, IDENT);
codegen_global(p, sym->name, sym->type);
sym = sym->next;
}
-
- if (!matches(p, IDENT))
- {
- break;
- }
}
+ while (matches(p, IDENT));
}
RULE(type_decl)
bool export = false;
Symbol* sym = NULL;
- while (1)
+ do
{
name = expect_text(p, IDENT);
export = accept(p, '*');
sym = symbol_new(p, name, SYM_TYPE, export);
expect(p, '=');
type(p, item);
-// expression(p, item);
-// sym->imm = item->imm;
-// sym->type = item->type;
-
- if (!matches(p, IDENT))
- {
- break;
- }
+ sym->type = item->type;
}
+ while (matches(p, IDENT));
}
RULE(const_decl)
bool export = false;
Symbol* sym = NULL;
- while (1)
+ do
{
name = expect_text(p, IDENT);
export = accept(p, '*');
expression(p, item);
sym->imm = item->imm;
sym->type = item->type;
-
- if (!matches(p, IDENT))
- {
- break;
- }
}
+ while (matches(p, IDENT));
}
RULE(statement_seq)
{
- while (1)
+ do
{
if (matches(p, IDENT))
{
expect(p, IF);
expression(p, item);
check_bool(p, item);
+ // CFJump(item)
expect(p, THEN);
statement_seq(p, &(Item){0});
+ // L = 0
while (accept(p, ELSIF))
{
+ // FJump(L)
+ // FixLink(item->imm.i)
expression(p, item);
check_bool(p, item);
+ // CFJump(item)
expect(p, THEN);
statement_seq(p, &(Item){0});
}
if (accept(p, ELSE))
{
+ // FJump(L)
+ // FixLink(item->imm.i)
statement_seq(p, &(Item){0});
}
+ else
+ {
+ // FixLink(item->imm.i)
+ }
expect(p, END);
}
else
{
error(p, "expected a statement");
}
-
- if (matches(p, END) || matches(p, ELSE) || matches(p, ELSIF))
- {
- break;
- }
}
+ while (!matches(p, END) && !matches(p, ELSE) && !matches(p, ELSIF));
}
RULE(import_list)
{
(void)item;
expect(p, IMPORT);
- while (1)
+ do
{
Module* m = calloc(1, sizeof(Module));
m->name = expect_text(p, IDENT);
m->next = p->imports;
p->imports = m;
}
-
- if (!matches(p, IDENT))
- {
- break;
- }
}
+ while (matches(p, IDENT));
/* reverse the list so when we init it happens in the right order */
Module* imports = p->imports;