Commit dce5eab8 authored by POTTIER Francois's avatar POTTIER Francois

Fixed the bug with --infer and an uppercase nonterminal symbol.

parent 41945e2d
2015/09/11:
Fixed the mysterious message that would appear when a nonterminal symbol
begins with an uppercase letter and --infer is turned on. Clarified the
documentation to indicate that a (non-start) nonterminal symbol can begin
with an uppercase letter, but this is not recommended.
2015/08/27:
New option --inspection (added last January, documented only now). This
generates an inspection API which allows inspecting the automaton's stack,
......
......@@ -33,23 +33,16 @@
(syntaxe concrète à déterminer)
équivalent à --unused-token FOO sur la ligne de commande.
* BUG: --infer does not work when a non-terminal begins
with a lowercase letter (Maxime Dénès).
* bench/Makefile no longer works on my Mac? (egrep problem)
* Produce well-chosen (predictable) names for anonymous rules?
* Document anonymous rules.
Produce well-chosen (predictable) names for anonymous rules.
In the standard library, possibly rename "anonymous" and "embedded"
and document them. The non-inline version allows embedding an action in the
* In the standard library, possibly rename "anonymous" and "embedded" and
document them. The non-inline version allows embedding an action in the
middle of a rule.
* Should we always avoid querying the lexer before a default reduction?
Would that be difficult/possible? Would that help people who want to
trigger changes in the lexer?
* Produce well-chosen (predictable) names for anonymous rules?
* ErrorReporting: experiment with merging several symbols
so as to reduce the noise (e.g. operators, expressions,
etc.). Or just print the same way, but don't quotient
......
/* A grammar where a nonterminal symbol begins with an uppercase
letter. Non-standard, but allowed, for compatibility with
ocamlyacc. In versions of Menhir up to 20150911, this caused
a problem when --infer was used. */
%token A B EOF
%start<unit> entry
%%
entry:
AB+ EOF {}
AB:
A B {}
%start entry
%token EOF
%token B
%token A
%type <unit> entry
%%
entry:
| _1 = nonempty_list_AB_ _2 = EOF
{ ()}
AB:
| _1 = A _2 = B
{ ()}
nonempty_list_AB_:
| x = AB
{ ( [ x ] )}
| x = AB xs = nonempty_list_AB_
{ ( x :: xs )}
%%
......@@ -8,13 +8,25 @@ open TokenType
(* ------------------------------------------------------------------------- *)
(* Naming conventions. *)
(* The type variable associated with a nonterminal symbol. Its name
begins with a prefix which ensures that it cannot clash with
Objective Caml keywords. *)
(* The type variable associated with a nonterminal symbol. Its name begins
with a prefix which ensures that it begins with a lowercase letter and
cannot clash with Objective Caml keywords. *)
let ntvar symbol =
Printf.sprintf "tv_%s" (Misc.normalize symbol)
(* The term variable associated with a nonterminal symbol. Its name begins
with a prefix which ensures that it begins with a lowercase letter and
cannot clash with Objective Caml keywords. *)
let encode symbol =
Printf.sprintf "xv_%s" (Misc.normalize symbol)
let decode s =
let n = String.length s in
assert (n >= 3 && String.sub s 0 3 = "xv_");
String.sub s 3 (n - 3)
(* The name of the temporary file. *)
let base =
......@@ -136,7 +148,7 @@ let program grammar =
let ps, ts =
StringMap.fold (fun symbol _ (ps, ts) ->
PVar (Misc.normalize symbol) :: ps,
PVar (encode (Misc.normalize symbol)) :: ps,
nttype grammar symbol :: ts
) grammar.rules ([], [])
in
......@@ -306,7 +318,7 @@ let infer grammar =
let env : (string * ocamltype) list =
List.map (fun (id, openingofs, closingofs) ->
id, Inferred (String.sub output openingofs (closingofs - openingofs))
decode id, Inferred (String.sub output openingofs (closingofs - openingofs))
) env
in
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment