Combine declaration sub-rules
authorSiraaj Khandkar <siraaj@khandkar.net>
Mon, 28 May 2018 18:26:33 +0000 (14:26 -0400)
committerSiraaj Khandkar <siraaj@khandkar.net>
Mon, 28 May 2018 18:26:33 +0000 (14:26 -0400)
tiger/src/lib/tiger/tiger_parser.mly

index 2cd530d..a415ae7 100644 (file)
@@ -188,36 +188,32 @@ decs:
     }
 
 dec:
-  | tydec  {$1}
-  | vardec {$1}
-  | fundec {$1}
-
-fundec:
-  | FUNCTION ID LPAREN RPAREN EQ exp
+  /* Tydec */
+  | TYPE ID EQ ID
     {
-      let id       = $2 in
-      let exp      = $6 in
-      sprintf "fundec[%s, arguments[], exp[%s]]" id exp
+      let type_id_new = $2 in
+      let type_id_orig = $4 in
+      sprintf "tydec_alias[from[%s], to[%s]]" type_id_new type_id_orig
     }
-  | FUNCTION ID LPAREN tyfields RPAREN EQ exp
+  | TYPE ID EQ LBRACE RBRACE
     {
-      let id       = $2 in
-      let tyfields = $4 in
-      let exp      = $7 in
-      sprintf "fundec[%s, arguments[%s], exp[%s]]" id tyfields exp
+      let type_id = $2 in
+      sprintf "tydec_empty_record[%s]" type_id
     }
-  | FUNCTION ID LPAREN tyfields RPAREN COLON ID EQ exp
+  | TYPE ID EQ LBRACE tyfields RBRACE
     {
-      let id       = $2 in
-      let tyfields = $4 in
-      let type_id  = $7 in
-      let exp      = $9 in
-      sprintf
-        "fundec[%s, tyfields[%s], type_id[%s], exp[%s]]"
-        id tyfields type_id exp
+      let type_id = $2 in
+      let tyfields = $5 in
+      sprintf "tydec_record[%s, fields[%s]]" type_id tyfields
+    }
+  | TYPE ID EQ ARRAY OF ID
+    {
+      let type_id = $2 in
+      let element_type_id = $6 in
+      sprintf "tydec_array[%s, elements_of_type[%s]]" type_id element_type_id
     }
 
-vardec:
+  /* Vardec */
   | VAR ID ASSIGN exp
     {
       let id = $2 in
@@ -232,29 +228,29 @@ vardec:
       sprintf "vardec[%s, type_id[%s], exp[%s]]" id type_id exp
     }
 
-tydec:
-  | TYPE ID EQ ID
-    {
-      let type_id_new = $2 in
-      let type_id_orig = $4 in
-      sprintf "tydec_alias[from[%s], to[%s]]" type_id_new type_id_orig
-    }
-  | TYPE ID EQ LBRACE RBRACE
+  /* Fundec */
+  | FUNCTION ID LPAREN RPAREN EQ exp
     {
-      let type_id = $2 in
-      sprintf "tydec_empty_record[%s]" type_id
+      let id       = $2 in
+      let exp      = $6 in
+      sprintf "fundec[%s, arguments[], exp[%s]]" id exp
     }
-  | TYPE ID EQ LBRACE tyfields RBRACE
+  | FUNCTION ID LPAREN tyfields RPAREN EQ exp
     {
-      let type_id = $2 in
-      let tyfields = $5 in
-      sprintf "tydec_record[%s, fields[%s]]" type_id tyfields
+      let id       = $2 in
+      let tyfields = $4 in
+      let exp      = $7 in
+      sprintf "fundec[%s, arguments[%s], exp[%s]]" id tyfields exp
     }
-  | TYPE ID EQ ARRAY OF ID
+  | FUNCTION ID LPAREN tyfields RPAREN COLON ID EQ exp
     {
-      let type_id = $2 in
-      let element_type_id = $6 in
-      sprintf "tydec_array[%s, elements_of_type[%s]]" type_id element_type_id
+      let id       = $2 in
+      let tyfields = $4 in
+      let type_id  = $7 in
+      let exp      = $9 in
+      sprintf
+        "fundec[%s, tyfields[%s], type_id[%s], exp[%s]]"
+        id tyfields type_id exp
     }
 
 tyfields:
This page took 0.021637 seconds and 4 git commands to generate.