Commit 1d6522ca authored by POTTIER Francois's avatar POTTIER Francois
Browse files

Remove the trailing space produced by [Production.print] and a few other...

Remove the trailing space produced by [Production.print] and a few other functions based on [printaod].
parent 44f87207
......@@ -234,7 +234,7 @@ let rec follow1 tok derivation offset' = function
let comment =
"lookahead token is inherited" ^
(if pos + 1 < length then Printf.sprintf " because %scan vanish" (Symbol.printao (pos + 1) rhs) else "")
(if pos + 1 < length then Printf.sprintf " because %s can vanish" (Symbol.printao (pos + 1) rhs) else "")
in
let derivation =
Derivation.build pos rhs derivation (Some comment)
......
......@@ -496,20 +496,28 @@ module Symbol = struct
(* Printing an array of symbols. [offset] is the start offset -- we
print everything to its right. [dot] is the dot offset -- we
print a dot at this offset, if we find it. *)
print a dot at this offset, if we find it. Note that [dot] can be
equal to [length]. *)
let printaod offset dot symbols =
let buffer = Buffer.create 512 in
let b = Buffer.create 512 in
let length = Array.length symbols in
let first = ref true in
let separate () =
if not !first then Printf.bprintf b " ";
first := false
in
for i = offset to length do
if i = dot then
Buffer.add_string buffer ". ";
if i = dot then begin
separate();
Printf.bprintf b "."
end;
if i < length then begin
Buffer.add_string buffer (print symbols.(i));
Buffer.add_char buffer ' '
separate();
Printf.bprintf b "%s" (print symbols.(i))
end
done;
Buffer.contents buffer
Buffer.contents b
let printao offset symbols =
printaod offset (-1) symbols
......@@ -822,6 +830,13 @@ module Production = struct
let nt, rhs = table.(prod) in
Printf.sprintf "%s -> %s" (Nonterminal.print false nt) (Symbol.printao 0 rhs)
let describe prod =
match classify prod with
| Some nt ->
Printf.sprintf "accepting %s" (Nonterminal.print false nt)
| None ->
Printf.sprintf "reducing production %s" (print prod)
(* Tabulation and sum. *)
let tabulate f =
......@@ -1447,7 +1462,7 @@ let rec convert = function
(Terminal.print tok)
| ENullable (symbols, e) ->
let e = convert e in
Printf.sprintf "%scan vanish%s%s"
Printf.sprintf "%s can vanish%s%s"
(Symbol.printl symbols)
(if e = "" then "" else " and ")
e
......
......@@ -465,6 +465,11 @@ module Production : sig
val print: index -> string
(* This produces a representation of a production as a string of
the form "accepting <nt>" or "reducing <nt> -> <rhs>". *)
val describe: index -> string
(* Tabulation of a function over productions. *)
val tabulate: (index -> 'a) -> (index -> 'a)
......
......@@ -306,7 +306,7 @@ let export (k, toksr) =
let print_concrete leading (state : concretelr1state) =
let buffer = Buffer.create 1024 in
Item.Map.iter (fun item toks ->
Printf.bprintf buffer "%s%s[ %s ]\n"
Printf.bprintf buffer "%s%s [ %s ]\n"
leading
(Item.print item)
(TerminalSet.print toks)
......
......@@ -841,7 +841,7 @@ let warn_about_productions_never_reduced () =
incr count;
Error.grammar_warning
(Production.positions prod)
"production %sis never reduced." (Production.print prod)
"production %s is never reduced." (Production.print prod)
);
if !count > 0 then
let plural_mark, be = if !count > 1 then ("s", "are") else ("", "is") in
......@@ -972,11 +972,7 @@ let default_conflict_resolution () =
(2) checking whether the lookahead token is %s%s,\n\
which would require some other action.\n\n"
(number node)
(match Production.classify prod with
| Some nt ->
Printf.sprintf "accepting %s" (Nonterminal.print false nt)
| None ->
Printf.sprintf "reducing production %s" (Production.print prod))
(Production.describe prod)
(if TerminalSet.cardinal toks > 1 then "one of " else "")
(TerminalSet.print toks)
......
......@@ -3,7 +3,7 @@ Lookahead token is now INT (-1--1)
Shifting (INT) to state 4
State 4:
Lookahead token is now PLUS (-1--1)
Reducing production expr -> INT
Reducing production expr -> INT
State 22:
Shifting (PLUS) to state 11
State 11:
......@@ -13,7 +13,7 @@ State 12:
Shifting (INT) to state 4
State 4:
Lookahead token is now TIMES (-1--1)
Reducing production expr -> INT
Reducing production expr -> INT
State 13:
Shifting (TIMES) to state 6
State 6:
......@@ -23,11 +23,11 @@ State 8:
Shifting (INT) to state 4
State 4:
Lookahead token is now PLUS (-1--1)
Reducing production expr -> INT
Reducing production expr -> INT
State 9:
Reducing production expr -> expr TIMES optional_dot expr
Reducing production expr -> expr TIMES optional_dot expr
State 13:
Reducing production expr -> expr PLUS optional_dot expr
Reducing production expr -> expr PLUS optional_dot expr
State 22:
Shifting (PLUS) to state 11
State 11:
......@@ -37,12 +37,12 @@ State 12:
Shifting (INT) to state 4
State 4:
Lookahead token is now EOL (-1--1)
Reducing production expr -> INT
Reducing production expr -> INT
State 13:
Reducing production expr -> expr PLUS optional_dot expr
Reducing production expr -> expr PLUS optional_dot expr
State 22:
Shifting (EOL) to state 23
State 23:
Reducing production main -> expr EOL
Reducing production main -> expr EOL
State 21:
Accepting
......@@ -3,7 +3,7 @@ Lookahead token is now INT (0-3)
Shifting (INT) to state 4
State 4:
Lookahead token is now PLUS (4-5)
Reducing production expr -> INT
Reducing production expr -> INT
State 22:
Shifting (PLUS) to state 11
State 11:
......@@ -13,7 +13,7 @@ State 12:
Shifting (INT) to state 4
State 4:
Lookahead token is now TIMES (8-9)
Reducing production expr -> INT
Reducing production expr -> INT
State 13:
Shifting (TIMES) to state 6
State 6:
......@@ -23,11 +23,11 @@ State 8:
Shifting (INT) to state 4
State 4:
Lookahead token is now PLUS (12-13)
Reducing production expr -> INT
Reducing production expr -> INT
State 9:
Reducing production expr -> expr TIMES optional_dot expr
Reducing production expr -> expr TIMES optional_dot expr
State 13:
Reducing production expr -> expr PLUS optional_dot expr
Reducing production expr -> expr PLUS optional_dot expr
State 22:
Shifting (PLUS) to state 11
State 11:
......@@ -37,12 +37,12 @@ State 12:
Shifting (INT) to state 4
State 4:
Lookahead token is now EOL (17-18)
Reducing production expr -> INT
Reducing production expr -> INT
State 13:
Reducing production expr -> expr PLUS optional_dot expr
Reducing production expr -> expr PLUS optional_dot expr
State 22:
Shifting (EOL) to state 23
State 23:
Reducing production main -> expr EOL
Reducing production main -> expr EOL
State 21:
Accepting
......@@ -8,7 +8,7 @@ State 3:
Shifting (INT) to state 4
State 4:
Lookahead token is now PLUS (-1--1)
Reducing production expr -> INT
Reducing production expr -> INT
State 5:
Shifting (PLUS) to state 11
State 11:
......@@ -18,14 +18,14 @@ State 12:
Shifting (INT) to state 4
State 4:
Lookahead token is now RPAREN (-1--1)
Reducing production expr -> INT
Reducing production expr -> INT
State 13:
Reducing production expr -> expr PLUS optional_dot expr
Reducing production expr -> expr PLUS optional_dot expr
State 5:
Shifting (RPAREN) to state 10
State 10:
Lookahead token is now TIMES (-1--1)
Reducing production expr -> LPAREN nothing expr RPAREN
Reducing production expr -> LPAREN nothing expr RPAREN
State 22:
Shifting (TIMES) to state 6
State 6:
......@@ -35,9 +35,9 @@ State 8:
Shifting (INT) to state 4
State 4:
Lookahead token is now PLUS (-1--1)
Reducing production expr -> INT
Reducing production expr -> INT
State 9:
Reducing production expr -> expr TIMES optional_dot expr
Reducing production expr -> expr TIMES optional_dot expr
State 22:
Shifting (PLUS) to state 11
State 11:
......@@ -47,12 +47,12 @@ State 12:
Shifting (INT) to state 4
State 4:
Lookahead token is now EOL (-1--1)
Reducing production expr -> INT
Reducing production expr -> INT
State 13:
Reducing production expr -> expr PLUS optional_dot expr
Reducing production expr -> expr PLUS optional_dot expr
State 22:
Shifting (EOL) to state 23
State 23:
Reducing production main -> expr EOL
Reducing production main -> expr EOL
State 21:
Accepting
......@@ -8,7 +8,7 @@ State 3:
Shifting (INT) to state 4
State 4:
Lookahead token is now PLUS (5-6)
Reducing production expr -> INT
Reducing production expr -> INT
State 5:
Shifting (PLUS) to state 11
State 11:
......@@ -18,14 +18,14 @@ State 12:
Shifting (INT) to state 4
State 4:
Lookahead token is now RPAREN (8-9)
Reducing production expr -> INT
Reducing production expr -> INT
State 13:
Reducing production expr -> expr PLUS optional_dot expr
Reducing production expr -> expr PLUS optional_dot expr
State 5:
Shifting (RPAREN) to state 10
State 10:
Lookahead token is now TIMES (10-11)
Reducing production expr -> LPAREN nothing expr RPAREN
Reducing production expr -> LPAREN nothing expr RPAREN
State 22:
Shifting (TIMES) to state 6
State 6:
......@@ -35,9 +35,9 @@ State 8:
Shifting (INT) to state 4
State 4:
Lookahead token is now PLUS (14-15)
Reducing production expr -> INT
Reducing production expr -> INT
State 9:
Reducing production expr -> expr TIMES optional_dot expr
Reducing production expr -> expr TIMES optional_dot expr
State 22:
Shifting (PLUS) to state 11
State 11:
......@@ -47,12 +47,12 @@ State 12:
Shifting (INT) to state 4
State 4:
Lookahead token is now EOL (19-20)
Reducing production expr -> INT
Reducing production expr -> INT
State 13:
Reducing production expr -> expr PLUS optional_dot expr
Reducing production expr -> expr PLUS optional_dot expr
State 22:
Shifting (EOL) to state 23
State 23:
Reducing production main -> expr EOL
Reducing production main -> expr EOL
State 21:
Accepting
......@@ -8,7 +8,7 @@ State 3:
Shifting (INT) to state 4
State 4:
Lookahead token is now PLUS (-1--1)
Reducing production expr -> INT
Reducing production expr -> INT
State 5:
Shifting (PLUS) to state 11
State 11:
......@@ -18,14 +18,14 @@ State 12:
Shifting (INT) to state 4
State 4:
Lookahead token is now RPAREN (-1--1)
Reducing production expr -> INT
Reducing production expr -> INT
State 13:
Reducing production expr -> expr PLUS optional_dot expr
Reducing production expr -> expr PLUS optional_dot expr
State 5:
Shifting (RPAREN) to state 10
State 10:
Lookahead token is now TIMES (-1--1)
Reducing production expr -> LPAREN nothing expr RPAREN
Reducing production expr -> LPAREN nothing expr RPAREN
State 22:
Shifting (TIMES) to state 6
State 6:
......@@ -35,9 +35,9 @@ State 8:
Shifting (INT) to state 4
State 4:
Lookahead token is now PLUS (-1--1)
Reducing production expr -> INT
Reducing production expr -> INT
State 9:
Reducing production expr -> expr TIMES optional_dot expr
Reducing production expr -> expr TIMES optional_dot expr
State 22:
Shifting (PLUS) to state 11
State 11:
......@@ -52,7 +52,7 @@ State 3:
Shifting (INT) to state 4
State 4:
Lookahead token is now TIMES (-1--1)
Reducing production expr -> INT
Reducing production expr -> INT
State 5:
Shifting (TIMES) to state 6
State 6:
......@@ -65,18 +65,18 @@ Lookahead token is now INT (-1--1)
Shifting (INT) to state 4
State 4:
Lookahead token is now RPAREN (-1--1)
Reducing production expr -> INT
Reducing production expr -> INT
State 20:
Reducing production expr -> MINUS expr
Reducing production expr -> MINUS expr
State 9:
Reducing production expr -> expr TIMES optional_dot expr
Reducing production expr -> expr TIMES optional_dot expr
State 5:
Shifting (RPAREN) to state 10
State 10:
Lookahead token is now MINUS (-1--1)
Reducing production expr -> LPAREN nothing expr RPAREN
Reducing production expr -> LPAREN nothing expr RPAREN
State 13:
Reducing production expr -> expr PLUS optional_dot expr
Reducing production expr -> expr PLUS optional_dot expr
State 22:
Shifting (MINUS) to state 17
State 17:
......@@ -86,9 +86,9 @@ State 18:
Shifting (INT) to state 4
State 4:
Lookahead token is now MINUS (-1--1)
Reducing production expr -> INT
Reducing production expr -> INT
State 19:
Reducing production expr -> expr MINUS optional_dot expr
Reducing production expr -> expr MINUS optional_dot expr
State 22:
Shifting (MINUS) to state 17
State 17:
......@@ -98,12 +98,12 @@ State 18:
Shifting (INT) to state 4
State 4:
Lookahead token is now EOL (-1--1)
Reducing production expr -> INT
Reducing production expr -> INT
State 19:
Reducing production expr -> expr MINUS optional_dot expr
Reducing production expr -> expr MINUS optional_dot expr
State 22:
Shifting (EOL) to state 23
State 23:
Reducing production main -> expr EOL
Reducing production main -> expr EOL
State 21:
Accepting
......@@ -8,7 +8,7 @@ State 3:
Shifting (INT) to state 4
State 4:
Lookahead token is now PLUS (5-6)
Reducing production expr -> INT
Reducing production expr -> INT
State 5:
Shifting (PLUS) to state 11
State 11:
......@@ -18,14 +18,14 @@ State 12:
Shifting (INT) to state 4
State 4:
Lookahead token is now RPAREN (8-9)
Reducing production expr -> INT
Reducing production expr -> INT
State 13:
Reducing production expr -> expr PLUS optional_dot expr
Reducing production expr -> expr PLUS optional_dot expr
State 5:
Shifting (RPAREN) to state 10
State 10:
Lookahead token is now TIMES (10-11)
Reducing production expr -> LPAREN nothing expr RPAREN
Reducing production expr -> LPAREN nothing expr RPAREN
State 22:
Shifting (TIMES) to state 6
State 6:
......@@ -35,9 +35,9 @@ State 8:
Shifting (INT) to state 4
State 4:
Lookahead token is now PLUS (14-15)
Reducing production expr -> INT
Reducing production expr -> INT
State 9:
Reducing production expr -> expr TIMES optional_dot expr
Reducing production expr -> expr TIMES optional_dot expr
State 22:
Shifting (PLUS) to state 11
State 11:
......@@ -52,7 +52,7 @@ State 3:
Shifting (INT) to state 4
State 4:
Lookahead token is now TIMES (21-22)
Reducing production expr -> INT
Reducing production expr -> INT
State 5:
Shifting (TIMES) to state 6
State 6:
......@@ -65,18 +65,18 @@ Lookahead token is now INT (24-25)
Shifting (INT) to state 4
State 4:
Lookahead token is now RPAREN (25-26)
Reducing production expr -> INT
Reducing production expr -> INT
State 20:
Reducing production expr -> MINUS expr
Reducing production expr -> MINUS expr
State 9:
Reducing production expr -> expr TIMES optional_dot expr
Reducing production expr -> expr TIMES optional_dot expr
State 5:
Shifting (RPAREN) to state 10
State 10:
Lookahead token is now MINUS (27-28)
Reducing production expr -> LPAREN nothing expr RPAREN
Reducing production expr -> LPAREN nothing expr RPAREN
State 13:
Reducing production expr -> expr PLUS optional_dot expr
Reducing production expr -> expr PLUS optional_dot expr
State 22:
Shifting (MINUS) to state 17
State 17:
......@@ -86,9 +86,9 @@ State 18:
Shifting (INT) to state 4
State 4:
Lookahead token is now MINUS (31-32)
Reducing production expr -> INT
Reducing production expr -> INT
State 19:
Reducing production expr -> expr MINUS optional_dot expr
Reducing production expr -> expr MINUS optional_dot expr
State 22:
Shifting (MINUS) to state 17
State 17:
......@@ -98,12 +98,12 @@ State 18:
Shifting (INT) to state 4
State 4:
Lookahead token is now EOL (34-35)
Reducing production expr -> INT
Reducing production expr -> INT
State 19:
Reducing production expr -> expr MINUS optional_dot expr
Reducing production expr -> expr MINUS optional_dot expr
State 22:
Shifting (EOL) to state 23
State 23:
Reducing production main -> expr EOL
Reducing production main -> expr EOL
State 21:
Accepting
......@@ -8,7 +8,7 @@ State 3:
Shifting (INT) to state 4
State 4:
Lookahead token is now PLUS (-1--1)
Reducing production expr -> INT
Reducing production expr -> INT
State 5:
Shifting (PLUS) to state 11
State 11:
......@@ -16,19 +16,19 @@ Lookahead token is now DOT (-1--1)
Shifting (DOT) to state 7
State 7:
Lookahead token is now INT (-1--1)
Reducing production optional_dot -> DOT
Reducing production optional_dot -> DOT
State 12:
Shifting (INT) to state 4
State 4:
Lookahead token is now RPAREN (-1--1)
Reducing production expr -> INT
Reducing production expr -> INT
State 13:
Reducing production expr -> expr PLUS optional_dot expr
Reducing production expr -> expr PLUS optional_dot expr
State 5:
Shifting (RPAREN) to state 10
State 10:
Lookahead token is now TIMES (-1--1)
Reducing production expr -> LPAREN nothing expr RPAREN
Reducing production expr -> LPAREN nothing expr RPAREN
State 22:
Shifting (TIMES) to state 6
State 6:
......@@ -38,9 +38,9 @@ State 8:
Shifting (INT) to state 4
State 4:
Lookahead token is now PLUS (-1--1)
Reducing production expr -> INT
Reducing production expr -> INT
State 9:
Reducing production expr -> expr TIMES optional_dot expr
Reducing production expr -> expr TIMES optional_dot expr
State 22:
Shifting (PLUS) to state 11
State 11:
......@@ -55,7 +55,7 @@ State 3:
Shifting (INT) to state 4
State 4:
Lookahead token is now TIMES (-1--1)
Reducing production expr -> INT
Reducing production expr -> INT
State 5:
Shifting (TIMES) to state 6
State 6:
......@@ -68,18 +68,18 @@ Lookahead token is now INT (-1--1)
Shifting (INT) to state 4
State 4:
Lookahead token is now RPAREN (-1--1)
Reducing production expr -> INT
Reducing production expr -> INT
State 20:
Reducing production expr -> MINUS expr
Reducing production expr -> MINUS expr
State 9:
Reducing production expr -> expr TIMES optional_dot expr
Reducing production expr -> expr TIMES optional_dot expr
State 5:
Shifting (RPAREN) to state 10
State 10:
Lookahead token is now MINUS (-1--1)
Reducing production expr -> LPAREN nothing expr RPAREN
Reducing production expr -> LPAREN nothing expr RPAREN
State 13:
Reducing production expr -> expr PLUS optional_dot expr
Reducing production expr -> expr PLUS optional_dot expr
State 22:
Shifting (MINUS) to state 17
State 17:
......@@ -87,14 +87,14 @@ Lookahead token is now DOT (-1--1)
Shifting (DOT) to state 7
State 7:
Lookahead token is now INT (-1--1)
Reducing production optional_dot -> DOT
Reducing production optional_dot -> DOT
State 18:
Shifting (INT) to state 4
State 4:
Lookahead token is now MINUS (-1--1)
Reducing production expr -> INT
Reducing production expr -> INT
State 19:
Reducing production expr -> expr MINUS optional_dot expr
Reducing production expr -> expr MINUS optional_dot expr
State 22:
Shifting (MINUS) to state 17
State 17:
......@@ -104,12 +104,12 @@ State 18:
Shifting (INT) to state 4
State 4:
Lookahead token is now EOL (-1--1)
Reducing production expr -> INT
Reducing production expr -> INT
State 19:
Reducing production expr -> expr MINUS optional_dot expr
Reducing production expr -> expr MINUS optional_dot expr
State 22:
Shifting (EOL) to state 23
State 23:
Reducing production main -> expr EOL
Reducing production main -> expr EOL
State 21:
Accepting
......@@ -8,7 +8,7 @@ State 3:
Shifting (INT) to state 4
State 4:
Lookahead token is now PLUS (5-6)
Reducing production expr -> INT
Reducing production expr -> INT
State 5:
Shifting (PLUS) to state 11
State 11:
......@@ -16,19 +16,19 @@ Lookahead token is now DOT (7-8)
Shifting (DOT) to state 7
State 7:
Lookahead token is now INT (9-10)
Reducing production optional_dot -> DOT
Reducing production optional_dot -> DOT
State 12:
Shifting (INT) to state 4
State 4: