]> git.mdlowis.com Git - proto/obnc.git/commitdiff
added grammar rule for record fields. adding fields doesnt work yet though
authormike lowis <mike@mdlowis.com>
Wed, 12 May 2021 02:03:58 +0000 (22:03 -0400)
committermike lowis <mike@mdlowis.com>
Wed, 12 May 2021 02:03:58 +0000 (22:03 -0400)
cerise/src/grammar.c
cerise/tests/Module.m

index 2bbdf9b4bad5e6a06c6a1d78c95bd9c28ccc2b38..f303994b309f3ea5376ce984a26a0894e8c98732 100644 (file)
@@ -70,16 +70,22 @@ static Symbol RealSym = {
  *****************************************************************************/
 static void init_item(Item* item, Symbol* sym)
 {
+    item->type = sym->type;
     if (SYM_VAR == sym->class)
     {
         item->mode = (sym->global ? ITEM_MVAR : ITEM_VAR);
+        item->imm.s = sym->name;
+    }
+    else if (SYM_PROC == sym->class)
+    {
+        item->mode = ITEM_MVAR;
+        item->imm.s = sym->name;
     }
     else
     {
         item->mode = ITEM_CONST;
+        item->imm  = sym->imm;
     }
-    item->imm  = sym->imm;
-    item->type = sym->type;
 }
 
 /* Grammar Definition
@@ -91,10 +97,6 @@ RULE(qualident)
     char* name = expect_text(p, IDENT);
     Symbol* sym = symbol_get(p, -1, name);
     init_item(item, sym);
-    if (sym->class == SYM_VAR || sym->class == SYM_PROC)
-    {
-        item->imm.s = sym->name;
-    }
 
 //    if (accept(p, '.'))
 //    {
@@ -122,7 +124,6 @@ RULE(designator)
                 if (item->type->form == FORM_ARRAY)
                 {
                     codegen_index(p, item, &index);
-//                    item->type = item->type->base;
                 }
                 else
                 {
@@ -345,6 +346,72 @@ RULE(type)
     }
     else if (accept(p, RECORD))
     {
+
+
+//    do
+//    {
+//        int nsyms = 0;
+//        Symbol* first = NULL;
+//        Symbol* sym = NULL;
+////        Symbol* type = NULL;
+//        char* name = NULL;
+//        bool export = false;
+//
+//        do
+//        {
+//            name = expect_text(p, IDENT);
+//            export = accept(p, '*');
+//            sym = symbol_new(p, name, SYM_VAR, export);
+//            first = (nsyms == 0 ? sym : first);
+//            sym->global = (p->level <= 1 ? 1 : 0);
+//            nsyms++;
+//        }
+//        while (accept(p, ','));
+//
+//        Item base_type = {0};
+//        expect(p, ':');
+//        type(p, &base_type);
+//
+////        name = expect_text(p, IDENT);
+////        type = symbol_get(p, SYM_TYPE, name);
+//
+//        /* apply the type to the newly created symbols */
+//        for (int i = 0; i < nsyms; i++)
+//        {
+//            first->type = base_type.type;
+//            codegen_var(p, first);
+//            sym = first->next;
+//        }
+//    }
+//    while (matches(p, IDENT));
+
+        while (peek(p)->type != END)
+        {
+            int nsyms = 0;
+            Symbol head = {0};
+            Symbol **prev = &(head.next);
+            do
+            {
+                char* name = expect_text(p, IDENT);
+                bool export = accept(p, '*');
+                *prev = symbol_new(p, name, SYM_VAR, export);
+                nsyms++;
+            }
+            while (accept(p, ','));
+
+            Item base_type = {0};
+            expect(p, ':');
+            type(p, &base_type);
+
+//            /* apply the type to the newly created symbols */
+//            for (int i = 0; i < nsyms; i++)
+//            {
+//                first->type = base_type.type;
+//                codegen_var(p, first);
+//                sym = first->next;
+//            }
+        }
+
         expect(p, END);
     }
     else
index 7e69119cc31291030fcfc9c5b196de63ad7c9f49..f0c7e9a091969454e3c504dcde97d92720074f01 100644 (file)
@@ -13,7 +13,8 @@ type
   TypeB = array 5 of Int
   TypeC = array 5 of array 10 of Int
   TypeD = record
-
+    x,y : Int
+    label : array 10 of Real
   end
 
 var
@@ -29,11 +30,6 @@ procedure Foo*(e : Int, z : Int) : Int
   var
     z : Int
     q : array 5 of array 10 of Int
-
-#  procedure Bar() : Int
-#  begin
-#  end
-
 begin
   c = 1;
   z = 2;
@@ -103,7 +99,7 @@ begin
 #    c = 3;
 #  end
 #
-  # Function calls
+#  # Function calls
 #  c = Foo(1,2);
 #  e[0] = 1;
 #  Foo(1,2);
@@ -112,5 +108,3 @@ begin
     e[1][2] = 1;
     c = e[1][c];
 end
-
-# _T5 _T10
\ No newline at end of file