Remove stand-alone ty grammar rule
[tiger.ml.git] / tiger / src / lib / tiger / tiger_parser.mly
index bbf89f7..2cd530d 100644 (file)
@@ -109,9 +109,16 @@ exp:
     {
       sprintf "string[%S]" $1
     }
-  | fun_call
+  | ID LPAREN RPAREN
     {
-      $1
+      let id = $1 in
+      sprintf "fun_call[%s, []]" id
+    }
+  | ID LPAREN fun_args RPAREN
+    {
+      let id = $1 in
+      let fun_args = $3 in
+      sprintf "fun_call[%s, %s]" id fun_args
     }
   | exp op exp
     {
@@ -144,27 +151,28 @@ exp:
     {
       "break[]"
     }
-  | LPAREN seq RPAREN
+  | LPAREN exps RPAREN
     {
-      sprintf "seq[%s]" $2
+      sprintf "exps[%s]" $2
     }
-  | LET decs IN seq END
+  | LET decs IN exps END
     {
       let decs = $2 in
-      let seq = $4 in
-      sprintf "let[decs[%s], in[seq[%s]]]" decs seq
+      let exps = $4 in
+      sprintf "let[decs[%s], in[exps[%s]]]" decs exps
     }
-  | unit
+  | LPAREN RPAREN
     {
-      $1
+      (* Perhaps "void"? *)
+      "unit[]"
     }
 
-seq:
+exps:
   | exp
     {
       sprintf "%s" $1
     }
-  | exp SEMICOLON seq
+  | exp SEMICOLON exps
     {
       sprintf "%s; %s" $1 $3
     }
@@ -185,18 +193,18 @@ dec:
   | fundec {$1}
 
 fundec:
-  | FUNCTION ID unit EQ exp
+  | FUNCTION ID LPAREN RPAREN EQ exp
     {
       let id       = $2 in
-      let exp      = $5 in
-      sprintf "fundec[%s, exp[%s]]" id exp
+      let exp      = $6 in
+      sprintf "fundec[%s, arguments[], exp[%s]]" id exp
     }
   | FUNCTION ID LPAREN tyfields RPAREN EQ exp
     {
       let id       = $2 in
       let tyfields = $4 in
       let exp      = $7 in
-      sprintf "fundec[%s, tyfields[%s], exp[%s]]" id tyfields exp
+      sprintf "fundec[%s, arguments[%s], exp[%s]]" id tyfields exp
     }
   | FUNCTION ID LPAREN tyfields RPAREN COLON ID EQ exp
     {
@@ -225,32 +233,28 @@ vardec:
     }
 
 tydec:
-  | TYPE ID EQ ty
+  | TYPE ID EQ ID
     {
-      let type_id = $2 in
-      let ty = $4 in
-      sprintf "tydec[%s, %s]" type_id ty
+      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
     }
-
-ty:
-  | ID
+  | TYPE ID EQ LBRACE RBRACE
     {
-      let type_id = $1 in
-      sprintf "type[type_id[%S]]" type_id
-    }
-  | LBRACE RBRACE
-    {
-      "record[]"
+      let type_id = $2 in
+      sprintf "tydec_empty_record[%s]" type_id
     }
-  | LBRACE tyfields RBRACE
+  | TYPE ID EQ LBRACE tyfields RBRACE
     {
-      let tyfields = $2 in
-      sprintf "record[%s]" tyfields
+      let type_id = $2 in
+      let tyfields = $5 in
+      sprintf "tydec_record[%s, fields[%s]]" type_id tyfields
     }
-  | ARRAY OF ID
+  | TYPE ID EQ ARRAY OF ID
     {
-      let type_id = $3 in
-      sprintf "array_of_type[%s]" type_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
     }
 
 tyfields:
@@ -272,13 +276,6 @@ tyfield:
       sprintf "tyfield[%s, %s]" id type_id
     }
 
-/* Perhaps "void"? */
-unit:
-  | LPAREN RPAREN
-    {
-      "unit[]"
-    }
-
 rec_field_assignments:
   | ID EQ exp
     {
@@ -294,19 +291,6 @@ rec_field_assignments:
       sprintf "%S = %s, %s" id exp rec_field_assignments
     }
 
-fun_call:
-  | ID unit
-    {
-      let id = $1 in
-      sprintf "fun_call[%s, []]" id
-    }
-  | ID LPAREN fun_args RPAREN
-    {
-      let id = $1 in
-      let fun_args = $3 in
-      sprintf "fun_call[%s, %s]" id fun_args
-    }
-
 fun_args:
   | exp
     {
This page took 0.029746 seconds and 4 git commands to generate.