Browse Source

Added array parameter syntax rule to parser

Taddeus Kroes 12 năm trước cách đây
mục cha
commit
ce0f7d6ff0
1 tập tin đã thay đổi với 6 bổ sung3 xóa
  1. 6 3
      parser.mly

+ 6 - 3
parser.mly

@@ -104,16 +104,19 @@ fun_header:
 
 
 param:
 param:
     (* parameter: use location of parameter name *)
     (* parameter: use location of parameter name *)
-    ctype=basic_type; name=ID
+    | ctype=basic_type; name=ID
     { Param (ctype, name, loc $startpos(name) $endpos(name)) }
     { Param (ctype, name, loc $startpos(name) $endpos(name)) }
 
 
+    | ctype=basic_type; LBRACK; dims=separated_list(COMMA, ID); RBRACK; name=ID
+    { Param (ArrayDec (ctype, dims), name, loc $startpos(name) $endpos(name)) }
+
 fun_body:
 fun_body:
-    var_dec* local_fun_dec* statement* loption(return_statement)
+    | var_dec* local_fun_dec* statement* loption(return_statement)
     { $1 @ $2 @ $3 @ $4 }
     { $1 @ $2 @ $3 @ $4 }
 
 
 return_statement:
 return_statement:
     (* return statement: use location of return value *)
     (* return statement: use location of return value *)
-    RETURN; value=expr; SEMICOL
+    | RETURN; value=expr; SEMICOL
     { [Return (value, loc $startpos(value) $endpos(value))] }
     { [Return (value, loc $startpos(value) $endpos(value))] }
 
 
 (* function: use location of function name *)
 (* function: use location of function name *)