@@ -89,24 +89,6 @@ type gram = {
89
89
90
90
let sprintf = Printf. sprintf
91
91
92
- let map_and_concat f ?(delim =" " ) l =
93
- String. concat delim (List. map f l)
94
-
95
- let rec db_output_prodn = function
96
- | Sterm s -> sprintf " (Sterm %s) " s
97
- | Snterm s -> sprintf " (Snterm %s) " s
98
- | Slist1 sym -> sprintf " (Slist1 %s) " (db_output_prodn sym)
99
- | Slist1sep (sym , sep ) -> sprintf " (Slist1sep %s %s) " (db_output_prodn sep) (db_output_prodn sym)
100
- | Slist0 sym -> sprintf " (Slist0 %s) " (db_output_prodn sym)
101
- | Slist0sep (sym , sep ) -> sprintf " (Slist0sep %s %s) " (db_output_prodn sep) (db_output_prodn sym)
102
- | Sopt sym -> sprintf " (Sopt %s) " (db_output_prodn sym)
103
- | Sparen prod -> sprintf " (Sparen %s) " (db_out_list prod)
104
- | Sprod prods -> sprintf " (Sprod %s) " (db_out_prods prods)
105
- | Sedit s -> sprintf " (Sedit %s) " s
106
- | Sedit2 (s , s2 ) -> sprintf " (Sedit2 %s %s) " s s2
107
- and db_out_list prod = sprintf " (%s)" (map_and_concat db_output_prodn prod)
108
- and db_out_prods prods = sprintf " ( %s )" (map_and_concat ~delim: " | " db_out_list prods)
109
-
110
92
(* identify special chars that don't get a trailing space in output *)
111
93
let omit_space s = List. mem s [" ?" ; " ." ; " #" ]
112
94
@@ -378,8 +360,6 @@ let pr_prods nt prods = (* duplicative *)
378
360
prods;
379
361
Printf. printf " ]\n\n "
380
362
381
- type fmt = [`MLG | `PRODLIST | `PRODN ]
382
-
383
363
(* print a subset of the grammar with nts in the specified order *)
384
364
let print_in_order out g fmt nt_order hide =
385
365
List. iter (fun nt ->
@@ -994,41 +974,6 @@ let map_name s =
994
974
in
995
975
good_name s
996
976
997
- let rec gen_nt_name sym =
998
- let name_from_prod prod =
999
- let rec aux name sterm_name prod =
1000
- if name <> " " then name else
1001
- match prod with
1002
- | [] -> sterm_name
1003
- | Sterm s :: tl
1004
- | Snterm s :: tl ->
1005
- if good_name s <> " " then
1006
- aux (map_name s) sterm_name tl
1007
- else
1008
- aux name (map_name s) tl;
1009
- | sym :: tl ->
1010
- aux (gen_nt_name sym) sterm_name tl
1011
- in
1012
- aux " " " " prod
1013
- in
1014
-
1015
- let name = match sym with
1016
- | Sterm s -> map_name s
1017
- | Snterm s -> s
1018
- | Slist1 sym
1019
- | Slist1sep (sym, _)
1020
- | Slist0 sym
1021
- | Slist0sep (sym, _)
1022
- | Sopt sym ->
1023
- gen_nt_name sym
1024
- | Sparen slist ->
1025
- name_from_prod slist
1026
- | Sprod slistlist ->
1027
- name_from_prod (List. hd slistlist)
1028
- | _ -> " "
1029
- in
1030
- good_name name
1031
-
1032
977
(* create a new nt for LIST* or OPT with the specified name *)
1033
978
let maybe_add_nt g insert_after name sym queue =
1034
979
let empty = [Snterm " empty" ] in
@@ -1104,17 +1049,6 @@ let maybe_add_nt g insert_after name sym queue =
1104
1049
end ;
1105
1050
new_nt
1106
1051
1107
- let apply_merge g edit_map =
1108
- List. iter (fun b ->
1109
- let (from_nt, to_nt) = b in
1110
- let from_prods = NTMap. find from_nt ! g.map in
1111
- List. iter (fun prod ->
1112
- try
1113
- ignore( get_first prod (NTMap. find to_nt ! g.map));
1114
- with Not_found -> g_add_prod_after g None to_nt prod)
1115
- from_prods)
1116
- (NTMap. bindings edit_map)
1117
-
1118
1052
let apply_rename_delete g edit_map =
1119
1053
List. iter (fun b -> let (nt, _) = b in
1120
1054
let prods = try NTMap. find nt ! g.map with Not_found -> [] in
@@ -1358,11 +1292,6 @@ let nt_closure g start stops =
1358
1292
in
1359
1293
List. rev (nt_closure_r [] [start])
1360
1294
1361
- let header = " --------------------------------------------"
1362
- let nt_subset_in_orig_order g nts =
1363
- let subset = StringSet. of_list nts in
1364
- List. filter (fun nt -> StringSet. mem nt subset) ! g.order
1365
-
1366
1295
let index_of str list =
1367
1296
let rec index_of_r str list index =
1368
1297
match list with
@@ -1373,61 +1302,9 @@ let index_of str list =
1373
1302
in
1374
1303
index_of_r str list 0
1375
1304
1376
- exception IsNone
1377
-
1378
1305
(* todo: raise exception for bad n? *)
1379
1306
let rec nthcdr n list = if n < = 0 then list else nthcdr (n-1 ) (List. tl list )
1380
1307
1381
- let pfx n list =
1382
- let rec pfx_r n res = function
1383
- | item :: tl -> if n < 0 then res else pfx_r (n-1 ) (item :: res) tl
1384
- | [] -> res
1385
- in
1386
- List. rev (pfx_r n [] list )
1387
-
1388
- (* todo: adjust Makefile to include Option.ml/mli *)
1389
- let get_opt = function
1390
- | Some y -> y
1391
- | _ -> raise IsNone
1392
-
1393
- let get_range g start end_ =
1394
- let starti, endi = get_opt (index_of start ! g.order), get_opt (index_of end_ ! g.order) in
1395
- pfx (endi - starti) (nthcdr starti ! g.order)
1396
-
1397
- let get_rangeset g start end_ = StringSet. of_list (get_range g start end_)
1398
-
1399
- let check_range_consistency g start end_ =
1400
- let defined_list = get_range g start end_ in
1401
- let defined = StringSet. of_list defined_list in
1402
- let referenced = List. fold_left (fun set nt ->
1403
- let prods = NTMap. find nt ! g.map in
1404
- let refs = List. concat (List. map nts_in_prod prods) in
1405
- StringSet. union set (StringSet. of_list refs))
1406
- StringSet. empty defined_list
1407
- in
1408
- let undef = StringSet. diff referenced defined in
1409
- let unused = StringSet. diff defined referenced in
1410
- if StringSet. cardinal unused > 0 || (StringSet. cardinal undef > 0 ) then begin
1411
- Printf. printf " \n For range '%s' to '%s':\n External reference:" start end_;
1412
- StringSet. iter (fun nt -> Printf. printf " %s" nt) undef;
1413
- Printf. printf " \n " ;
1414
- if StringSet. cardinal unused > 0 then begin
1415
- Printf. printf " Unreferenced:" ;
1416
- StringSet. iter (fun nt -> Printf. printf " %s" nt) unused;
1417
- Printf. printf " \n "
1418
- end
1419
- end
1420
-
1421
- (* print info on symbols with a single production of a single nonterminal *)
1422
- let check_singletons g =
1423
- NTMap. iter (fun nt prods ->
1424
- if List. length prods = 1 && ! show_warn then
1425
- if List. length (remove_Sedit2 (List. hd prods)) = 1 then
1426
- warn " Singleton non-terminal, maybe SPLICE?: %s\n " nt
1427
- else
1428
- (* warn "Single production, maybe SPLICE?: %s\n" nt*) () )
1429
- ! g.map
1430
-
1431
1308
let report_bad_nts g file =
1432
1309
let all_nts_ref, all_nts_def = get_refdef_nts g in
1433
1310
let undef = StringSet. diff all_nts_ref all_nts_def in
@@ -1443,51 +1320,6 @@ let report_bad_nts g file =
1443
1320
if ! show_warn then
1444
1321
List. iter (fun nt -> warn " %s: Unreachable symbol '%s'\n " file nt) unreachable
1445
1322
1446
-
1447
- let report_info g symdef_map =
1448
- let num_prods = List. fold_left (fun sum nt -> let prods = NTMap. find nt ! g.map in sum + (List. length prods))
1449
- 0 ! g.order
1450
- in
1451
-
1452
- Printf. eprintf " \n start symbols: %s\n " (String. concat " " start_symbols);
1453
- Printf. eprintf " %d nonterminals defined, %d productions\n " (NTMap. cardinal ! g.map) num_prods;
1454
- Printf. eprintf " %d terminals\n " (List. length tokens);
1455
-
1456
- Printf. eprintf " \n Symbols with multiple definition points in *.mlg:\n " ;
1457
- let bindings = List. sort (fun a b -> let (ak, _) = a and (bk, _) = b in
1458
- String. compare ak bk) (StringMap. bindings symdef_map) in
1459
- List. iter (fun b ->
1460
- let (k, v) = b in
1461
- if List. length v > 1 then begin
1462
- Printf. eprintf " %s: " k;
1463
- List. iter (fun f -> Printf. eprintf " %s " f) v;
1464
- Printf. eprintf " \n "
1465
- end )
1466
- bindings;
1467
- Printf. eprintf " \n "
1468
-
1469
-
1470
-
1471
- [@@@ ocaml.warning " -32" ]
1472
- let rec dump prod =
1473
- match prod with
1474
- | hd :: tl -> let s = (match hd with
1475
- | Sterm s -> sprintf " Sterm %s" s
1476
- | Snterm s -> sprintf " Snterm \" %s\" " s
1477
- | Slist1 sym -> " Slist1"
1478
- | Slist0 sym -> " Slist0"
1479
- | Sopt sym -> " Sopt"
1480
- | Slist1sep _ -> " Slist1sep"
1481
- | Slist0sep _ -> " Slist0sep"
1482
- | Sparen sym_list -> " Sparen"
1483
- | Sprod sym_list_list -> " Sprod"
1484
- | Sedit _ -> " Sedit"
1485
- | Sedit2 _ -> " Sedit2" ) in
1486
- Printf. printf " %s " s;
1487
- dump tl
1488
- | [] -> Printf. printf " \n "
1489
- [@@@ ocaml.warning " +32" ]
1490
-
1491
1323
let reorder_grammar eg reordered_rules file =
1492
1324
let og = g_empty () in
1493
1325
List. iter (fun rule ->
0 commit comments