فهرست منبع

Fixed node locations form Dim nodes

Taddeus Kroes 12 سال پیش
والد
کامیت
e0be3d4de6
1فایلهای تغییر یافته به همراه18 افزوده شده و 15 حذف شده
  1. 18 15
      parser.mly

+ 18 - 15
parser.mly

@@ -53,11 +53,10 @@
 
 %%
 
-(* Right-recursive list (less efficient then left-recursive list(x), only use
- * when followed by left-recursive list to resolve conflicts) *)
-rlist(x):
-    |            { [] }
-    | rlist(x) x { $1 @ [$2] }
+(* Left-recursive list (use List.rev to obtain original list)  *)
+lreclist(x):
+    |               { [] }
+    | lreclist(x) x { $2 :: $1 }
 
 (* Shorthand for comma-separated list *)
 %inline clist(x):
@@ -87,10 +86,9 @@ decl:
     | EXTERN ctype=basic_type name=ID SEMICOL
     { GlobalDec (ctype, name, loc $startpos $endpos) }
 
-    | EXTERN ctype=basic_type LBRACK dims=clist(ID) RBRACK name=ID SEMICOL
-    { let dimloc = loc $startpos(dims) $endpos(dims) in
-      let loc = loc $startpos(name) $endpos(name) in
-      GlobalDec (ArrayDims (ctype, make_dims dimloc dims), name, loc) }
+    | EXTERN ctype=basic_type LBRACK dims=dimlist RBRACK name=ID SEMICOL
+    { let loc = loc $startpos(name) $endpos(name) in
+      GlobalDec (ArrayDims (ctype, List.rev dims), name, loc) }
 
     | export=boption(EXPORT) ctype=basic_type name=ID SEMICOL
     { let loc = loc $startpos(name) $endpos(name) in
@@ -118,14 +116,19 @@ param:
     | ctype=basic_type name=ID
     { Param (ctype, name, loc $startpos(name) $endpos(name)) }
 
-    | ctype=basic_type LBRACK dims=clist(ID) RBRACK name=ID
-    { let dimloc = loc $startpos(dims) $endpos(dims) in
-      let loc = loc $startpos(name) $endpos(name) in
-      Param (ArrayDims (ctype, make_dims dimloc dims), name, loc) }
+    | ctype=basic_type LBRACK dims=dimlist RBRACK name=ID
+    { let loc = loc $startpos(name) $endpos(name) in
+      Param (ArrayDims (ctype, List.rev dims), name, loc) }
+
+dimlist:
+    | name=ID
+    { [Dim (name, loc $startpos(name) $endpos(name))] }
+    | head=dimlist COMMA name=ID
+    { Dim (name, loc $startpos(name) $endpos(name)) :: head }
 
 fun_body:
-    | rlist(var_dec) local_fun_dec* statement* loption(return_statement)
-    { VarDecs $1 :: (LocalFuns $2) :: $3 @ $4 }
+    | lreclist(var_dec) local_fun_dec* statement* loption(return_statement)
+    { VarDecs (List.rev $1) :: (LocalFuns $2) :: $3 @ $4 }
 
 return_statement:
     (* return statement: use location of return value *)