if (matches(p, IDENT))
{
char* text = expect_text(p, IDENT);
- Symbol* sym = symbol_get(p, text, SYM_TYPE);
- ret = sym->type;
+ ret = symbol_get(p, text, SYM_TYPE)->type;
}
else if (accept(p, ARRAY))
{
ret->size = length;
ret->base = base;
}
-// else if (accept(p, RECORD))
-// {
-// long offset = 0;
-// item->type = calloc(1, sizeof(Type));
-// item->type->form = FORM_RECORD;
-//
-// while (peek(p)->type != END)
-// {
-// /* parse the field name list */
-// Field* first = NULL;
-// int nfields = 0;
-// do
-// {
-// char* name = expect_text(p, IDENT);
-// bool export = accept(p, '*');
-// Field* f = add_field(p, item->type, name, export);
-// nfields++;
-// if (!first)
-// {
-// first = f;
-// }
-// }
-// while (accept(p, ','));
-//
-// /* now parse the type designation */
-// Item field_type = {0};
-// expect(p, ':');
-// type(p, &field_type);
-//
-// /* apply the type to the newly created symbols */
-// for (int i = 0; i < nfields; i++)
-// {
-// offset = align_item(offset, field_type.type->size);
-// first->type = field_type.type;
-// first->offset = offset;
-// offset += size_of(first->type);
-// first = first->next;
-// }
-// }
-// item->type->size = offset;
-//
-// expect(p, END);
-// }
+ else if (accept(p, RECORD))
+ {
+ long offset = 0;
+ ret = calloc(1, sizeof(Type));
+ ret->form = FORM_RECORD;
+
+ while (peek(p)->type != END)
+ {
+ /* parse the field name list */
+ Field* first = NULL;
+ int nfields = 0;
+ do
+ {
+ char* name = expect_text(p, IDENT);
+ bool export = accept(p, '*');
+ Field* f = add_field(p, ret, name, export);
+ nfields++;
+ if (!first)
+ {
+ first = f;
+ }
+ }
+ while (accept(p, ','));
+
+ /* now parse the type designation */
+ expect(p, ':');
+ Type* field_type = type(p);
+
+ /* apply the type to the newly created symbols */
+ for (int i = 0; i < nfields; i++)
+ {
+ offset = align_item(offset, field_type->size);
+ first->type = field_type;
+ first->offset = offset;
+ offset += size_of(first->type);
+ first = first->next;
+ }
+ }
+ ret->size = offset;
+
+ expect(p, END);
+ }
else
{
error(p, "expected a type");
// EXIT_RULE();
//}
-//RULE(var_decl, Item* item)
-//{
-// ENTER_RULE();
-// (void)item;
-// do
-// {
-// char* name = expect_text(p, IDENT);
-// bool export = accept(p, '*');
-// Symbol* sym = symbol_new(p, 0, name, SYM_VAR, export);
-// Item base_type = {0};
-// expect(p, ':');
-// type(p, &base_type);
-// sym->type = base_type.type;
-// }
-// while (matches(p, IDENT));
-// EXIT_RULE();
-//}
+static void var_decl(Parser* p)
+{
+ ENTER_RULE();
+ do
+ {
+ char* name = expect_text(p, IDENT);
+ bool export = accept(p, '*');
+ Symbol* sym = symbol_new(p, 0, name, SYM_VAR, export);
+ expect(p, ':');
+ sym->type = type(p);
+ }
+ while (matches(p, IDENT));
+ EXIT_RULE();
+}
static void type_decl(Parser* p)
{
type_decl(p);
}
-// if (accept(p, VAR))
-// {
-// var_decl(p);
-// }
+ if (accept(p, VAR))
+ {
+ var_decl(p);
+ }
// while (matches(p, PROCEDURE))
// {