Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
menhir
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
10
Issues
10
List
Boards
Labels
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Container Registry
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
POTTIER Francois
menhir
Commits
2abde9bf
Commit
2abde9bf
authored
Apr 06, 2017
by
POTTIER Francois
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved [has_default_reduction] out of [Invariant] and into a new module, [Default].
parent
6563739a
Changes
246
Expand all
Hide whitespace changes
Inline
Sidebyside
Showing
246 changed files
with
339 additions
and
336 deletions
+339
336
LRijkstra.ml
src/LRijkstra.ml
+5
6
codeBackend.ml
src/codeBackend.ml
+4
4
coqBackend.ml
src/coqBackend.ml
+2
2
default.ml
src/default.ml
+72
0
default.mli
src/default.mli
+6
0
interpret.ml
src/interpret.ml
+2
2
invariant.ml
src/invariant.ml
+1
72
invariant.mli
src/invariant.mli
+0
8
lr1.ml
src/lr1.ml
+7
2
referenceInterpreter.ml
src/referenceInterpreter.ml
+2
2
tableBackend.ml
src/tableBackend.ml
+3
3
JSParse.exp
test/good/JSParse.exp
+1
1
K3Parser.exp
test/good/K3Parser.exp
+1
1
albatross.exp
test/good/albatross.exp
+1
1
alphaCamldemosinteractive.exp
test/good/alphaCamldemosinteractive.exp
+1
1
alphaCamldemosmixins.exp
test/good/alphaCamldemosmixins.exp
+1
1
alphaCamldemospoplmark.exp
test/good/alphaCamldemospoplmark.exp
+1
1
alphaCaml.exp
test/good/alphaCaml.exp
+1
1
alphaprolog.exp
test/good/alphaprolog.exp
+1
1
amalthea.exp
test/good/amalthea.exp
+1
1
anonymousnested.exp
test/good/anonymousnested.exp
+1
1
anonymousparamredundant.exp
test/good/anonymousparamredundant.exp
+1
1
anonymousparam.exp
test/good/anonymousparam.exp
+1
1
anonymous.exp
test/good/anonymous.exp
+1
1
atd_parser.exp
test/good/atd_parser.exp
+1
1
attapldeptypes.exp
test/good/attapldeptypes.exp
+1
1
attaplmini.exp
test/good/attaplmini.exp
+1
1
attributesexpansion.exp
test/good/attributesexpansion.exp
+1
1
attributes.exp
test/good/attributes.exp
+1
1
bauer.exp
test/good/bauer.exp
+1
1
belloeil.exp
test/good/belloeil.exp
+1
1
bibtex_parser.exp
test/good/bibtex_parser.exp
+1
1
bisonmysteriousconflict.exp
test/good/bisonmysteriousconflict.exp
+1
1
borismini.exp
test/good/borismini.exp
+1
1
bran.exp
test/good/bran.exp
+1
1
c.exp
test/good/c.exp
+1
1
c_unambiguous.exp
test/good/c_unambiguous.exp
+1
1
calcanonymous.exp
test/good/calcanonymous.exp
+1
1
calclocations.exp
test/good/calclocations.exp
+1
1
calc.exp
test/good/calc.exp
+1
1
christian.exp
test/good/christian.exp
+1
1
cigencparser.exp
test/good/cigencparser.exp
+1
1
cilcparser.exp
test/good/cilcparser.exp
+1
1
cilformatparse.exp
test/good/cilformatparse.exp
+1
1
cimecoq.exp
test/good/cimecoq.exp
+1
1
cimegenpoly.exp
test/good/cimegenpoly.exp
+1
1
cimeparameterizedsignatures.exp
test/good/cimeparameterizedsignatures.exp
+1
1
cimepolyinterp.exp
test/good/cimepolyinterp.exp
+1
1
cimepoly.exp
test/good/cimepoly.exp
+1
1
cimesignature.exp
test/good/cimesignature.exp
+1
1
cimesyntax.exp
test/good/cimesyntax.exp
+1
1
cimeterm.exp
test/good/cimeterm.exp
+1
1
cimetermssignature.exp
test/good/cimetermssignature.exp
+1
1
cimeterms.exp
test/good/cimeterms.exp
+1
1
cimetheory.exp
test/good/cimetheory.exp
+1
1
cimetoplevel.exp
test/good/cimetoplevel.exp
+1
1
cimeword.exp
test/good/cimeword.exp
+1
1
cminor.exp
test/good/cminor.exp
+1
1
cocci.exp
test/good/cocci.exp
+1
1
coercionconstraint.exp
test/good/coercionconstraint.exp
+1
1
coercionmini.exp
test/good/coercionmini.exp
+1
1
compcert_pre_parser.exp
test/good/compcert_pre_parser.exp
+1
1
compcert_pre_parser_new.exp
test/good/compcert_pre_parser_new.exp
+1
1
compsyn.exp
test/good/compsyn.exp
+1
1
condition_parser.exp
test/good/condition_parser.exp
+1
1
confluencefnf.exp
test/good/confluencefnf.exp
+1
1
confluencepsl.exp
test/good/confluencepsl.exp
+1
1
confluence.exp
test/good/confluence.exp
+1
1
couac.exp
test/good/couac.exp
+1
1
cutdown.exp
test/good/cutdown.exp
+1
1
dario.exp
test/good/dario.exp
+1
1
dml.exp
test/good/dml.exp
+1
1
docOckXmlParser.exp
test/good/docOckXmlParser.exp
+1
1
dule.exp
test/good/dule.exp
+1
1
duplicated_prec.exp
test/good/duplicated_prec.exp
+1
1
efuns.exp
test/good/efuns.exp
+1
1
emptyaction.exp
test/good/emptyaction.exp
+1
1
endofstreamconflict.exp
test/good/endofstreamconflict.exp
+1
1
execparser.exp
test/good/execparser.exp
+1
1
featherweight.exp
test/good/featherweight.exp
+1
1
filiot.exp
test/good/filiot.exp
+1
1
flowcamldocgen.exp
test/good/flowcamldocgen.exp
+1
1
flowcaml.exp
test/good/flowcaml.exp
+1
1
foccpuredef.exp
test/good/foccpuredef.exp
+1
1
foo.exp
test/good/foo.exp
+1
1
fork.exp
test/good/fork.exp
+1
1
fp.exp
test/good/fp.exp
+1
1
framaccparser.exp
test/good/framaccparser.exp
+1
1
framacprint_apigrammar.exp
test/good/framacprint_apigrammar.exp
+1
1
fsharp.exp
test/good/fsharp.exp
+1
1
fslexpars.exp
test/good/fslexpars.exp
+1
1
fstar.exp
test/good/fstar.exp
+1
1
fsyaccpars.exp
test/good/fsyaccpars.exp
+1
1
godiva.exp
test/good/godiva.exp
+1
1
gromit.exp
test/good/gromit.exp
+1
1
grune924.exp
test/good/grune924.exp
+1
1
hmxmulti.exp
test/good/hmxmulti.exp
+1
1
hmxsets.exp
test/good/hmxsets.exp
+1
1
htparser.exp
test/good/htparser.exp
+1
1
ibal.exp
test/good/ibal.exp
+1
1
ics.exp
test/good/ics.exp
+1
1
idl_parser.exp
test/good/idl_parser.exp
+1
1
ilpars.exp
test/good/ilpars.exp
+1
1
infinite.exp
test/good/infinite.exp
+1
1
inlinemultilevel.exp
test/good/inlinemultilevel.exp
+1
1
inlinemultisons.exp
test/good/inlinemultisons.exp
+1
1
inlineposition.exp
test/good/inlineposition.exp
+1
1
inlinerename.exp
test/good/inlinerename.exp
+1
1
inlineshift.exp
test/good/inlineshift.exp
+1
1
inlinetest.exp
test/good/inlinetest.exp
+1
1
inlinewithdollar.exp
test/good/inlinewithdollar.exp
+1
1
inlineddollar.exp
test/good/inlineddollar.exp
+1
1
inliningcapture.exp
test/good/inliningcapture.exp
+1
1
jasmc.exp
test/good/jasmc.exp
+1
1
java.exp
test/good/java.exp
+1
1
jml.exp
test/good/jml.exp
+1
1
jocamlambients.exp
test/good/jocamlambients.exp
+1
1
jocamlnewparser.exp
test/good/jocamlnewparser.exp
+1
1
jocaml.exp
test/good/jocaml.exp
+1
1
jparser.exp
test/good/jparser.exp
+1
1
judicael.exp
test/good/judicael.exp
+1
1
julia.exp
test/good/julia.exp
+1
1
ketti.exp
test/good/ketti.exp
+1
1
kimmit.exp
test/good/kimmit.exp
+1
1
labltkcompiler.exp
test/good/labltkcompiler.exp
+1
1
labltkppyac.exp
test/good/labltkppyac.exp
+1
1
lambdoc_rlambtex_parser.exp
test/good/lambdoc_rlambtex_parser.exp
+1
1
lem.exp
test/good/lem.exp
+1
1
liberty_parser.exp
test/good/liberty_parser.exp
+1
1
link.exp
test/good/link.exp
+1
1
links.exp
test/good/links.exp
+1
1
llparse.exp
test/good/llparse.exp
+1
1
logic_parser.exp
test/good/logic_parser.exp
+1
1
loop.exp
test/good/loop.exp
+1
1
lrbutnotlalr.exp
test/good/lrbutnotlalr.exp
+1
1
ltlparser.exp
test/good/ltlparser.exp
+1
1
lustreParser.exp
test/good/lustreParser.exp
+1
1
macrodown.exp
test/good/macrodown.exp
+1
1
maple.exp
test/good/maple.exp
+1
1
mccfc.exp
test/good/mccfc.exp
+1
1
mccfj.exp
test/good/mccfj.exp
+1
1
mccfrontends.exp
test/good/mccfrontends.exp
+1
1
mccmc.exp
test/good/mccmc.exp
+1
1
mccmoogle.exp
test/good/mccmoogle.exp
+1
1
mccnaml.exp
test/good/mccnaml.exp
+1
1
mccpascal.exp
test/good/mccpascal.exp
+1
1
mccpasqual.exp
test/good/mccpasqual.exp
+1
1
mccphobos.exp
test/good/mccphobos.exp
+1
1
mccprof.exp
test/good/mccprof.exp
+1
1
mccpython.exp
test/good/mccpython.exp
+1
1
metaocaml.exp
test/good/metaocaml.exp
+1
1
mezzo.exp
test/good/mezzo.exp
+1
1
miniCparser.exp
test/good/miniCparser.exp
+1
1
miniMLparser.exp
test/good/miniMLparser.exp
+1
1
modelica.exp
test/good/modelica.exp
+1
1
modelyze.exp
test/good/modelyze.exp
+1
1
modulo.exp
test/good/modulo.exp
+1
1
multiplefunctor.exp
test/good/multiplefunctor.exp
+1
1
nameclash1.exp
test/good/nameclash1.exp
+1
1
netsem.exp
test/good/netsem.exp
+1
1
nexus.exp
test/good/nexus.exp
+1
1
nmlipparser.exp
test/good/nmlipparser.exp
+1
1
noendofstreamconflict.exp
test/good/noendofstreamconflict.exp
+1
1
obcsym.exp
test/good/obcsym.exp
+1
1
obc.exp
test/good/obc.exp
+1
1
ocamldebugger.exp
test/good/ocamldebugger.exp
+1
1
ocamllex.exp
test/good/ocamllex.exp
+1
1
ocamltestLex.exp
test/good/ocamltestLex.exp
+1
1
ocamltestasmcompcmm.exp
test/good/ocamltestasmcompcmm.exp
+1
1
ocaml.exp
test/good/ocaml.exp
+1
1
ocamldocodoc.exp
test/good/ocamldocodoc.exp
+1
1
ocamldocodoc_text.exp
test/good/ocamldocodoc_text.exp
+1
1
ocamlwebyacc.exp
test/good/ocamlwebyacc.exp
+1
1
oclisp.exp
test/good/oclisp.exp
+1
1
oflux.exp
test/good/oflux.exp
+1
1
ojacare.exp
test/good/ojacare.exp
+1
1
omake_ast_parse.exp
test/good/omake_ast_parse.exp
+1
1
omake_shell_parse.exp
test/good/omake_shell_parse.exp
+1
1
onerrorreduceinlined.exp
test/good/onerrorreduceinlined.exp
+1
1
onerrorreduceunreachable.exp
test/good/onerrorreduceunreachable.exp
+1
1
option2.exp
test/good/option2.exp
+1
1
parameterizednonterminal.exp
test/good/parameterizednonterminal.exp
+1
1
parse_xquery.exp
test/good/parse_xquery.exp
+1
1
parser_cocci_menhir.exp
test/good/parser_cocci_menhir.exp
+1
1
parser_cpp.exp
test/good/parser_cpp.exp
+1
1
parser_css.exp
test/good/parser_css.exp
+1
1
parser_java.exp
test/good/parser_java.exp
+1
1
parser_js.exp
test/good/parser_js.exp
+1
1
parser_php.exp
test/good/parser_php.exp
+1
1
parser_raw.exp
test/good/parser_raw.exp
+1
1
petit1.exp
test/good/petit1.exp
+1
1
photos.exp
test/good/photos.exp
+1
1
phpparser.exp
test/good/phpparser.exp
+1
1
pippijn.exp
test/good/pippijn.exp
+1
1
pre_parser.exp
test/good/pre_parser.exp
+1
1
prec_inline.exp
test/good/prec_inline.exp
+1
1
privateandpublic1.exp
test/good/privateandpublic1.exp
+1
1
promelaparser.exp
test/good/promelaparser.exp
+1
1
promelaparser_withexps.exp
test/good/promelaparser_withexps.exp
+1
1
prooflang.exp
test/good/prooflang.exp
+1
1
public1.exp
test/good/public1.exp
+1
1
publicinline1.exp
test/good/publicinline1.exp
+1
1
pxpm2parsergen.exp
test/good/pxpm2parsergen.exp
+1
1
pxpucs2_to_utf8.exp
test/good/pxpucs2_to_utf8.exp
+1
1
rdf_sparql_parser.exp
test/good/rdf_sparql_parser.exp
+1
1
reason_parser.exp
test/good/reason_parser.exp
+1
1
ruby18_parser.exp
test/good/ruby18_parser.exp
+1
1
sage.exp
test/good/sage.exp
+1
1
scilabParser.exp
test/good/scilabParser.exp
+1
1
self.exp
test/good/self.exp
+1
1
simnml.exp
test/good/simnml.exp
+1
1
simpleifconflict.exp
test/good/simpleifconflict.exp
+1
1
spike.exp
test/good/spike.exp
+1
1
splitpublicsymbolwithrenaming.exp
test/good/splitpublicsymbolwithrenaming.exp
+1
1
splitpublicsymbol.exp
test/good/splitpublicsymbol.exp
+1
1
subiso.exp
test/good/subiso.exp
+1
1
subtleconflictpager.exp
test/good/subtleconflictpager.exp
+1
1
symbolstartofs.exp
test/good/symbolstartofs.exp
+1
1
symbolstartpos.exp
test/good/symbolstartpos.exp
+1
1
sysver.exp
test/good/sysver.exp
+1
1
talparser.exp
test/good/talparser.exp
+1
1
tonyrc_parse.exp
test/good/tonyrc_parse.exp
+1
1
tonyxmlparse.exp
test/good/tonyxmlparse.exp
+1
1
toy.exp
test/good/toy.exp
+1
1
tptp2cime.exp
test/good/tptp2cime.exp
+1
1
typage.exp
test/good/typage.exp
+1
1
typedfreshml.exp
test/good/typedfreshml.exp
+1
1
unigram.exp
test/good/unigram.exp
+1
1
unreachablesymbol.exp
test/good/unreachablesymbol.exp
+1
1
unusedattribute.exp
test/good/unusedattribute.exp
+1
1
unusedpseudotoken.exp
test/good/unusedpseudotoken.exp
+1
1
unusedtoken1.exp
test/good/unusedtoken1.exp
+1
1
unusedvalue.exp
test/good/unusedvalue.exp
+1
1
uppercase.exp
test/good/uppercase.exp
+1
1
uselesspriorities.exp
test/good/uselesspriorities.exp
+1
1
uselesspseudotoken.exp
test/good/uselesspseudotoken.exp
+1
1
verilog.exp
test/good/verilog.exp
+1
1
wallace.exp
test/good/wallace.exp
+1
1
whyclparser.exp
test/good/whyclparser.exp
+1
1
whycparser.exp
test/good/whycparser.exp
+1
1
xpath_parser.exp
test/good/xpath_parser.exp
+1
1
yann.exp
test/good/yann.exp
+1
1
yaparser.exp
test/good/yaparser.exp
+1
1
zenon.exp
test/good/zenon.exp
+1
1
zyvaall.exp
test/good/zyvaall.exp
+1
1
zyvaflo.exp
test/good/zyvaflo.exp
+1
1
No files found.
src/LRijkstra.ml
View file @
2abde9bf
...
...
@@ 139,7 +139,7 @@ let reductions_on s z : Production.index list =
let
has_reduction
s
z
:
Production
.
index
option
=
assert
(
Terminal
.
real
z
);
match
Invarian
t
.
has_default_reduction
s
with
match
Defaul
t
.
has_default_reduction
s
with

Some
(
prod
,
_
)
>
Some
prod

None
>
...
...
@@ 155,7 +155,7 @@ let has_reduction s z : Production.index option =
reduction). *)
let
can_reduce
s
prod
=
match
Invarian
t
.
has_default_reduction
s
with
match
Defaul
t
.
has_default_reduction
s
with

Some
(
prod'
,
_
)
when
prod
=
prod'
>
true

_
>
...
...
@@ 170,7 +170,7 @@ let can_reduce s prod =
let
causes_an_error
s
z
:
bool
=
assert
(
Terminal
.
real
z
);
match
Invarian
t
.
has_default_reduction
s
with
match
Defaul
t
.
has_default_reduction
s
with

Some
_
>
false

None
>
...
...
@@ 189,7 +189,7 @@ let foreach_terminal =
[causes_an_error]. This implementation is significantly more efficient. *)
let
foreach_terminal_not_causing_an_error
s
f
=
match
Invarian
t
.
has_default_reduction
s
with
match
Defaul
t
.
has_default_reduction
s
with

Some
_
>
(* There is a default reduction. No symbol causes an error. *)
foreach_terminal
f
...
...
@@ 1087,7 +1087,7 @@ let new_fact fact =
[prod, z] such that the [current] state can reduce [prod] on [z]
and [position] accepts [prod]. *)
match
Invarian
t
.
has_default_reduction
current
with
match
Defaul
t
.
has_default_reduction
current
with

Some
(
prod
,
_
)
>
if
Trie
.
accepts
prod
position
then
(* [new_edge] does not accept [any] as its 4th parameter, so we
...
...
@@ 1390,4 +1390,3 @@ let () =
(*  *)
end
src/codeBackend.ml
View file @
2abde9bf
...
...
@@ 369,7 +369,7 @@ let gotopushes : Nonterminal.t > bool =
not
(
Lr1
.
targets
(
fun
accu
_
target
>
accu
&&
match
Invarian
t
.
has_default_reduction
target
with
match
Defaul
t
.
has_default_reduction
target
with

Some
(
prod
,
_
)
>
Production
.
length
prod
>
0

None
>
false
...
...
@@ 440,7 +440,7 @@ let (shiftreduce : Production.index > bool), shiftreducecount =
default reduction. *)
Invariant
.
fold_reduced
(
fun
s
accu
>
accu
&&
(
match
Invarian
t
.
has_default_reduction
s
with
None
>
false

Some
_
>
true
)
accu
&&
(
match
Defaul
t
.
has_default_reduction
s
with
None
>
false

Some
_
>
true
)
&&
(
runpushes
s
)
)
prod
true
...
...
@@ 474,7 +474,7 @@ let () =
else
Lr1
.
targets
(
fun
accu
_
target
>
accu
&&
match
Invarian
t
.
has_default_reduction
target
with
match
Defaul
t
.
has_default_reduction
target
with

Some
(
prod
,
_
)
>
shiftreduce
prod

None
>
...
...
@@ 1059,7 +1059,7 @@ let initiate s =
let
rundef
s
:
valdef
=
match
Invarian
t
.
has_default_reduction
s
with
match
Defaul
t
.
has_default_reduction
s
with

Some
(
prod
,
toks
)
as
defred
>
(* Perform reduction without looking ahead.
...
...
src/coqBackend.ml
View file @
2abde9bf
...
...
@@ 38,7 +38,7 @@ module Run (T: sig end) = struct

Stretch
.
Inferred
_
>
assert
false
(* We cannot infer coq types *)
let
is_final_state
node
=
match
Invarian
t
.
has_default_reduction
node
with
match
Defaul
t
.
has_default_reduction
node
with

Some
(
prod
,
_
)
>
Production
.
is_start
prod

None
>
false
...
...
@@ 277,7 +277,7 @@ module Run (T: sig end) = struct
fprintf
f
" match state with
\n
"
;
lr1_iter_nonfinal
(
fun
node
>
fprintf
f
"  %s => "
(
print_st
node
);
match
Invarian
t
.
has_default_reduction
node
with
match
Defaul
t
.
has_default_reduction
node
with

Some
(
prod
,
_
)
>
fprintf
f
"Default_reduce_act %s
\n
"
(
print_prod
prod
)

None
>
...
...
src/default.ml
0 → 100644
View file @
2abde9bf
open
Grammar
module
C
=
Conflict
(* artificial dependency; ensures that [Conflict] runs first *)
(* Here is how we check whether state [s] should have a default reduction.
We check whether [s] has no outgoing shift transitions and only has
one possible reduction action. In that case, we produce a default
reduction action, that is, we perform reduction without consulting
the lookahead token. This saves code, but can alter the parser's
behavior in the presence of errors.
The check for default actions subsumes the check for the case where
[s] admits a reduce action with lookahead symbol "#". In that case,
it must be the only possible action  see
[Lr1.default_conflict_resolution]. That is, we have reached a point
where we have recognized a wellformed input and are now expecting
an endofstream. In that case, performing reduction without
looking at the next token is the right thing to do, since there
should in fact be none. The state that we reduce to will also have
the same property, and so on, so we will in fact end up rewinding
the entire stack and accepting the input when the stack becomes
empty.
(New as of 2012/01/23.) A state where a shift/reduce conflict was
solved in favor of neither (due to a use of the %nonassoc
directive) must not perform a default reduction. Indeed, this would
effectively mean that the failure that was requested by the user is
forgotten and replaced with a reduction. This surprising behavior
is present in ocamlyacc and was present in earlier versions of
Menhir. See e.g. http://caml.inria.fr/mantis/view.php?id=5462
There is a chance that we might run into trouble if the ideas
described in the above two paragraphs collide, that is, if we
forbid a default reduction (due to a shift/reduce conflict solved
by %nonassoc) in a node where we would like to have default
reduction on "#". This situation seems unlikely to arise, so I will
not do anything about it for the moment. (Furthermore, someone who
uses precedence declarations is looking for trouble anyway.)
Between 2012/05/25 and 2015/09/25, if [canonical] has been specified,
then we disallow default reductions on a normal token, because we do not
want to introduce any spurious actions into the automaton. We do still
allow default reductions on "#", since they are needed for the automaton to
terminate properly. From 2015/09/25 on, we again always allow default
reductions, as they seem to be beneficial when explaining syntax errors. *)
let
has_default_reduction
,
count
=
Misc
.
tabulateo
Lr1
.
number
Lr1
.
fold
Lr1
.
n
(
fun
s
>
if
Lr1
.
forbid_default_reduction
s
then
None
else
let
reduction
=
ProductionMap
.
is_singleton
(
Lr1
.
invert
(
Lr1
.
reductions
s
))
in
match
reduction
with

Some
_
>
if
SymbolMap
.
purelynonterminal
(
Lr1
.
transitions
s
)
then
reduction
else
None

None
>
reduction
)
let
()
=
Error
.
logC
1
(
fun
f
>
Printf
.
fprintf
f
"%d out of %d states have a default reduction.
\n
"
count
Lr1
.
n
)
let
()
=
Time
.
tick
"Computing default reductions"
src/default.mli
0 → 100644
View file @
2abde9bf
open
Grammar
(* [has_default_reduction s] tells whether state [s] has a default reduction,
and, if so, upon which set of tokens. *)
val
has_default_reduction
:
Lr1
.
node
>
(
Production
.
index
*
TerminalSet
.
t
)
option
src/interpret.ml
View file @
2abde9bf
...
...
@@ 11,7 +11,8 @@
(* *)
(******************************************************************************)
module
I
=
Invariant
(* artificial dependency; ensures that [Invariant] runs first *)
module
I
=
Invariant
(* artificial dependency *)
module
D
=
Default
(* artificial dependency *)
(*  *)
...
...
@@ 774,4 +775,3 @@ let () =
exit
0
)
src/invariant.ml
View file @
2abde9bf
...
...
@@ 849,75 +849,6 @@ let errorpeekers =
let
errorpeeker
node
=
Lr1
.
NodeSet
.
mem
node
errorpeekers
(*  *)
(* Here is how we check whether state [s] should have a default
reduction.
We check whether [s] has no outgoing shift transitions and only has
one possible reduction action. In that case, we produce a default
reduction action, that is, we perform reduction without consulting
the lookahead token. This saves code, but can alter the parser's
behavior in the presence of errors.
The check for default actions subsumes the check for the case where
[s] admits a reduce action with lookahead symbol "#". In that case,
it must be the only possible action  see
[Lr1.default_conflict_resolution]. That is, we have reached a point
where we have recognized a wellformed input and are now expecting
an endofstream. In that case, performing reduction without
looking at the next token is the right thing to do, since there
should in fact be none. The state that we reduce to will also have
the same property, and so on, so we will in fact end up rewinding
the entire stack and accepting the input when the stack becomes
empty.
(New as of 2012/01/23.) A state where a shift/reduce conflict was
solved in favor of neither (due to a use of the %nonassoc
directive) must not perform a default reduction. Indeed, this would
effectively mean that the failure that was requested by the user is
forgotten and replaced with a reduction. This surprising behavior
is present in ocamlyacc and was present in earlier versions of
Menhir. See e.g. http://caml.inria.fr/mantis/view.php?id=5462
There is a chance that we might run into trouble if the ideas
described in the above two paragraphs collide, that is, if we
forbid a default reduction (due to a shift/reduce conflict solved
by %nonassoc) in a node where we would like to have default
reduction on "#". This situation seems unlikely to arise, so I will
not do anything about it for the moment. (Furthermore, someone who
uses precedence declarations is looking for trouble anyway.)
Between 2012/05/25 and 2015/09/25, if [canonical] has been specified,
then we disallow default reductions on a normal token, because we do not
want to introduce any spurious actions into the automaton. We do still
allow default reductions on "#", since they are needed for the automaton to
terminate properly. From 2015/09/25 on, we again always allow default
reductions, as they seem to be beneficial when explaining syntax errors. *)
let
(
has_default_reduction
:
Lr1
.
node
>
(
Production
.
index
*
TerminalSet
.
t
)
option
)
,
hdrcount
=
Misc
.
tabulateo
Lr1
.
number
Lr1
.
fold
Lr1
.
n
(
fun
s
>
if
Lr1
.
forbid_default_reduction
s
then
None
else
let
reduction
=
ProductionMap
.
is_singleton
(
Lr1
.
invert
(
Lr1
.
reductions
s
))
in
match
reduction
with

Some
_
>
if
SymbolMap
.
purelynonterminal
(
Lr1
.
transitions
s
)
then
reduction
else
None

None
>
reduction
)
let
()
=
Error
.
logC
1
(
fun
f
>
Printf
.
fprintf
f
"%d out of %d states have a default reduction.
\n
"
hdrcount
Lr1
.
n
)
(*  *)
let
()
=
...
...
@@ 925,9 +856,7 @@ let () =
(*  *)
(* If any fatal error was signaled up to this point, stop now. This may include
errors signaled in the modules [lr1] and [invariant] by calling the function
[Error.grammar_warning]. *)
(* If any fatal error was signaled up to this point, stop now. *)
let
()
=
if
Error
.
errors
()
then
...
...
src/invariant.mli
View file @
2abde9bf
...
...
@@ 129,14 +129,6 @@ val ever_reduced: Production.index > bool
val
fold_reduced
:
(
Lr1
.
node
>
'
a
>
'
a
)
>
Production
.
index
>
'
a
>
'
a
(*  *)
(* Information about default reductions. *)
(* [has_default_reduction s] tells whether state [s] has a default reduction,
and, if so, upon which set of tokens. *)
val
has_default_reduction
:
Lr1
.
node
>
(
Production
.
index
*
TerminalSet
.
t
)
option
(*  *)
(* Miscellaneous. *)
...
...
src/lr1.ml
View file @
2abde9bf
...
...
@@ 926,8 +926,13 @@ let () =
else
if
!
reduce_reduce
>
1
then
Error
.
grammar_warning
[]
"%d states have reduce/reduce conflicts."
!
reduce_reduce
(* There is a global check for errors at the end of [Invariant], so we do
not need to check & stop here. *)
(*  *)
(* If any fatal error was signaled up to this point, stop now. *)
let
()
=
if
Error
.
errors
()
then
exit
1
(*  *)
(* When requested by the code generator, apply default conflict
...
...
src/referenceInterpreter.ml
View file @
2abde9bf
...
...
@@ 61,7 +61,7 @@ module T = struct
let
find_production
=
Production
.
i2p
let
default_reduction
(
s
:
state
)
defred
nodefred
env
=
match
Invarian
t
.
has_default_reduction
s
with
match
Defaul
t
.
has_default_reduction
s
with

Some
(
prod
,
_
)
>
defred
env
prod

None
>
...
...
@@ 79,7 +79,7 @@ module T = struct
[ShiftNoDiscard], depending on the existence of a default
reduction on [#] at [s']. *)
match
Invarian
t
.
has_default_reduction
s'
with
match
Defaul
t
.
has_default_reduction
s'
with

Some
(
_
,
toks
)
when
TerminalSet
.
mem
Terminal
.
sharp
toks
>
shift
env
false
tok
value
s'

_
>
...
...
src/tableBackend.ml
View file @
2abde9bf
...
...
@@ 488,7 +488,7 @@ let marshal2 name m n (matrix : int list list) =
(* The action table. *)
let
action
node
t
=
match
Invarian
t
.
has_default_reduction
node
with
match
Defaul
t
.
has_default_reduction
node
with

Some
_
>
(* [node] has a default reduction; in that case, the action
...
...
@@ 504,7 +504,7 @@ let action node t =
(* [node] has a transition to [target]. If [target] has a default
reduction on [#], use [ShiftNoDiscard], otherwise [ShiftDiscard]. *)
match
Invarian
t
.
has_default_reduction
target
with
match
Defaul
t
.
has_default_reduction
target
with

Some
(
_
,
toks
)
when
TerminalSet
.
mem
Terminal
.
sharp
toks
>
assert
(
TerminalSet
.
cardinal
toks
=
1
);
encode_ShiftNoDiscard
target
...
...
@@ 555,7 +555,7 @@ let error node t =
(* The default reductions table. *)
let
default_reduction
node
=
match
Invarian
t
.
has_default_reduction
node
with
match
Defaul
t
.
has_default_reduction
node
with

Some
(
prod
,
_
)
>
encode_DefRed
prod

None
>
...
...
test/good/JSParse.exp
View file @
2abde9bf
...
...
@@ 427,10 +427,10 @@ The grammar is not SLR(1)  12 states have a conflict.
Built an LR(1) automaton with 660 states.
Warning: one state has shift/reduce conflicts.
Warning: one shift/reduce conflict was arbitrarily resolved.
239 out of 660 states have a default reduction.
224 out of 660 states are represented.
0 out of 257 symbols keep track of their start position.
0 out of 257 symbols keep track of their end position.
239 out of 660 states have a default reduction.
188 out of 362 productions exploit shiftreduce optimization.
0 out of 660 states can peek at an error.
1805 functions before inlining, 237 functions after inlining.
test/good/K3Parser.exp
View file @
2abde9bf
...
...
@@ 207,6 +207,7 @@ Warning: 3 states have reduce/reduce conflicts.
Warning: 576 shift/reduce conflicts were arbitrarily resolved.
Warning: 142 reduce/reduce conflicts were arbitrarily resolved.
Warning: 266 states have an endofstream conflict.
445 out of 1441 states have a default reduction.
File "K3Parser.mly", line 399, characters 04:
Warning: symbol expr is never accepted.
File "K3Parser.mly", line 760, characters 626:
...
...
@@ 221,7 +222,6 @@ Warning: in total, 5 productions are never reduced.
639 out of 1441 states are represented.
0 out of 179 symbols keep track of their start position.
0 out of 179 symbols keep track of their end position.
445 out of 1441 states have a default reduction.
220 out of 307 productions exploit shiftreduce optimization.
297 out of 1441 states can peek at an error.
3246 functions before inlining, 579 functions after inlining.
test/good/albatross.exp
View file @
2abde9bf
...
...
@@ 337,6 +337,7 @@ Warning: the precedence level assigned to UMINUS is never useful.
File "albatross.mly", line 440, characters 2334:
Warning: this %prec declaration is never useful.
Warning: 117 states have an endofstream conflict.
166 out of 428 states have a default reduction.
File "albatross.mly", line 202, characters 225:
Warning: production file > use_block optsemi decls is never reduced.
File "albatross.mly", line 203, characters 27:
...
...
@@ 347,7 +348,6 @@ Warning: in total, 3 productions are never reduced.
198 out of 428 states are represented.
0 out of 188 symbols keep track of their start position.
0 out of 188 symbols keep track of their end position.
166 out of 428 states have a default reduction.
130 out of 250 productions exploit shiftreduce optimization.
0 out of 428 states can peek at an error.
1201 functions before inlining, 203 functions after inlining.
test/good/alphaCamldemosinteractive.exp
View file @
2abde9bf
...
...
@@ 11,10 +11,10 @@ Built an LR(0) automaton with 11 states.
The grammar is not SLR(1)  1 states have a conflict.
Built an LR(1) automaton with 11 states.
One shift/reduce conflict was silently solved.
6 out of 11 states have a default reduction.
2 out of 11 states are represented.
0 out of 11 symbols keep track of their start position.
0 out of 11 symbols keep track of their end position.
6 out of 11 states have a default reduction.
5 out of 6 productions exploit shiftreduce optimization.
0 out of 11 states can peek at an error.
36 functions before inlining, 7 functions after inlining.
test/good/alphaCamldemosmixins.exp
View file @
2abde9bf
...
...
@@ 43,10 +43,10 @@ follow(atomic_expression) = VAL RPAREN RCURLY PLUS IN EOF END DOT AND
Built an LR(0) automaton with 68 states.
The grammar is SLR(1).
Built an LR(1) automaton with 68 states.
27 out of 68 states have a default reduction.
15 out of 68 states are represented.
0 out of 41 symbols keep track of their start position.
0 out of 41 symbols keep track of their end position.
27 out of 68 states have a default reduction.
18 out of 32 productions exploit shiftreduce optimization.
0 out of 68 states can peek at an error.
187 functions before inlining, 26 functions after inlining.
test/good/alphaCamldemospoplmark.exp
View file @
2abde9bf
...
...
@@ 61,10 +61,10 @@ follow(ATerm) = SEMI RPAREN RCURLY LSQUARE LPAREN LCURLY LCID IN DOT COMMA
Built an LR(0) automaton with 97 states.
The grammar is SLR(1).
Built an LR(1) automaton with 97 states.
34 out of 97 states have a default reduction.
32 out of 97 states are represented.
0 out of 44 symbols keep track of their start position.
0 out of 44 symbols keep track of their end position.
34 out of 97 states have a default reduction.
24 out of 47 productions exploit shiftreduce optimization.
0 out of 97 states can peek at an error.
266 functions before inlining, 45 functions after inlining.
test/good/alphaCaml.exp
View file @
2abde9bf
...
...
@@ 85,10 +85,10 @@ follow(container) = error TYPE STAR SORT SEMICOLON RBRACE RANGLE IDENTIFIER EOF
Built an LR(0) automaton with 139 states.
The grammar is SLR(1).
Built an LR(1) automaton with 143 states.
74 out of 143 states have a default reduction.
35 out of 143 states are represented.
0 out of 61 symbols keep track of their start position.
0 out of 61 symbols keep track of their end position.
74 out of 143 states have a default reduction.
66 out of 85 productions exploit shiftreduce optimization.
9 out of 143 states can peek at an error.
404 functions before inlining, 74 functions after inlining.
test/good/alphaprolog.exp
View file @
2abde9bf
...
...
@@ 107,10 +107,10 @@ Built an LR(0) automaton with 259 states.
The grammar is not SLR(1)  54 states have a conflict.
Built an LR(1) automaton with 259 states.
1418 shift/reduce conflicts were silently solved.
79 out of 259 states have a default reduction.
87 out of 259 states are represented.
0 out of 116 symbols keep track of their start position.
0 out of 116 symbols keep track of their end position.
79 out of 259 states have a default reduction.
66 out of 142 productions exploit shiftreduce optimization.
0 out of 259 states can peek at an error.
701 functions before inlining, 133 functions after inlining.
test/good/amalthea.exp
View file @
2abde9bf
...
...
@@ 46,10 +46,10 @@ follow(atom) = Lstring Lsemi Lrpar Lperiod Llpar Llambda Lint Lident Lend
Built an LR(0) automaton with 71 states.
The grammar is SLR(1).
Built an LR(1) automaton with 71 states.
29 out of 71 states have a default reduction.
24 out of 71 states are represented.
0 out of 34 symbols keep track of their start position.
0 out of 34 symbols keep track of their end position.
29 out of 71 states have a default reduction.
19 out of 36 productions exploit shiftreduce optimization.
0 out of 71 states can peek at an error.
198 functions before inlining, 33 functions after inlining.
test/good/anonymousnested.exp
View file @
2abde9bf
...
...
@@ 15,10 +15,10 @@ follow(bar) = EOF C A
Built an LR(0) automaton with 16 states.
The grammar is SLR(1).
Built an LR(1) automaton with 16 states.
7 out of 16 states have a default reduction.
3 out of 16 states are represented.
0 out of 11 symbols keep track of their start position.
0 out of 11 symbols keep track of their end position.
7 out of 16 states have a default reduction.
7 out of 7 productions exploit shiftreduce optimization.
0 out of 16 states can peek at an error.
48 functions before inlining, 6 functions after inlining.
test/good/anonymousparamredundant.exp
View file @
2abde9bf
...
...
@@ 21,10 +21,10 @@ follow(embedded(__anonymous_1)) = A
Built an LR(0) automaton with 20 states.
The grammar is SLR(1).
Built an LR(1) automaton with 20 states.
9 out of 20 states have a default reduction.
6 out of 20 states are represented.
0 out of 14 symbols keep track of their start position.
0 out of 14 symbols keep track of their end position.
9 out of 20 states have a default reduction.
6 out of 11 productions exploit shiftreduce optimization.
0 out of 20 states can peek at an error.
63 functions before inlining, 13 functions after inlining.
test/good/anonymousparam.exp
View file @
2abde9bf
...
...
@@ 21,10 +21,10 @@ follow(list(__anonymous_0(A,B))) = EOF D C
Built an LR(0) automaton with 15 states.
The grammar is SLR(1).
Built an LR(1) automaton with 15 states.
8 out of 15 states have a default reduction.
6 out of 15 states are represented.
0 out of 13 symbols keep track of their start position.
0 out of 13 symbols keep track of their end position.
8 out of 15 states have a default reduction.
8 out of 10 productions exploit shiftreduce optimization.
0 out of 15 states can peek at an error.
51 functions before inlining, 12 functions after inlining.
test/good/anonymous.exp
View file @
2abde9bf
...
...
@@ 15,10 +15,10 @@ follow(list(__anonymous_0)) = EOF D
Built an LR(0) automaton with 14 states.
The grammar is SLR(1).
Built an LR(1) automaton with 14 states.
6 out of 14 states have a default reduction.
6 out of 14 states are represented.
0 out of 11 symbols keep track of their start position.
0 out of 11 symbols keep track of their end position.
6 out of 14 states have a default reduction.
2 out of 8 productions exploit shiftreduce optimization.
0 out of 14 states can peek at an error.
45 functions before inlining, 12 functions after inlining.
test/good/atd_parser.exp
View file @
2abde9bf
...
...
@@ 67,10 +67,10 @@ follow(afield) = error LIDENT GT
Built an LR(0) automaton with 108 states.
The grammar is not SLR(1)  2 states have a conflict.
Built an LR(1) automaton with 146 states.
60 out of 146 states have a default reduction.
50 out of 146 states are represented.
18 out of 48 symbols keep track of their start position.
21 out of 48 symbols keep track of their end position.
60 out of 146 states have a default reduction.
31 out of 65 productions exploit shiftreduce optimization.
38 out of 146 states can peek at an error.
The generated parser cannot raise Error.
...
...
test/good/attapldeptypes.exp
View file @
2abde9bf
...
...
@@ 103,10 +103,10 @@ The grammar is not SLR(1)  1 states have a conflict.
Built an LR(1) automaton with 111 states.
File "attapldeptypes.mly", line 84, characters 06:
Warning: the precedence level assigned to COMMA is never useful.
38 out of 111 states have a default reduction.
37 out of 111 states are represented.
0 out of 68 symbols keep track of their start position.
0 out of 68 symbols keep track of their end position.
38 out of 111 states have a default reduction.
24 out of 43 productions exploit shiftreduce optimization.
0 out of 111 states can peek at an error.
286 functions before inlining, 40 functions after inlining.
test/good/attaplmini.exp
View file @
2abde9bf
...
...
@@ 119,10 +119,10 @@ Built an LR(0) automaton with 128 states.
The grammar is not SLR(1)  6 states have a conflict.
Built an LR(1) automaton with 128 states.
36 shift/reduce conflicts were silently solved.
51 out of 128 states have a default reduction.
46 out of 128 states are represented.
0 out of 75 symbols keep track of their start position.
0 out of 75 symbols keep track of their end position.
51 out of 128 states have a default reduction.
36 out of 72 productions exploit shiftreduce optimization.
0 out of 128 states can peek at an error.
362 functions before inlining, 57 functions after inlining.
test/good/attributesexpansion.exp
View file @
2abde9bf
...
...
@@ 17,13 +17,13 @@ Built an LR(0) automaton with 11 states.
The grammar is SLR(1).
Built an LR(1) automaton with 11 states.
Warning: 8 states have an endofstream conflict.
5 out of 11 states have a default reduction.
File "attributesexpansion.mly", line 13, characters 11:
Warning: production liste(C) > is never reduced.
Warning: in total, 1 productions are never reduced.
6 out of 11 states are represented.
0 out of 10 symbols keep track of their start position.
0 out of 10 symbols keep track of their end position.
5 out of 11 states have a default reduction.
3 out of 8 productions exploit shiftreduce optimization.
0 out of 11 states can peek at an error.
39 functions before inlining, 11 functions after inlining.
test/good/attributes.exp
View file @
2abde9bf
...
...
@@ 7,10 +7,10 @@ follow(main) = #
Built an LR(0) automaton with 5 states.
The grammar is SLR(1).
Built an LR(1) automaton with 5 states.
2 out of 5 states have a default reduction.
0 out of 5 states are represented.
0 out of 7 symbols keep track of their start position.
0 out of 7 symbols keep track of their end position.
2 out of 5 states have a default reduction.
2 out of 2 productions exploit shiftreduce optimization.
0 out of 5 states can peek at an error.
19 functions before inlining, 2 functions after inlining.
test/good/bauer.exp
View file @
2abde9bf
...
...
@@ 33,10 +33,10 @@ follow(clause) = EOF DOT
Built an LR(0) automaton with 22 states.
The grammar is SLR(1).
Built an LR(1) automaton with 22 states.
11 out of 22 states have a default reduction.
5 out of 22 states are represented.
0 out of 20 symbols keep track of their start position.
0 out of 20 symbols keep track of their end position.
11 out of 22 states have a default reduction.
10 out of 17 productions exploit shiftreduce optimization.
0 out of 22 states can peek at an error.
76 functions before inlining, 14 functions after inlining.
test/good/belloeil.exp
View file @
2abde9bf
...
...
@@ 16,10 +16,10 @@ Built an LR(1) automaton with 14 states.
3 shift/reduce conflicts were silently solved.
Warning: 3 states have shift/reduce conflicts.
Warning: 3 shift/reduce conflicts were arbitrarily resolved.
7 out of 14 states have a default reduction.
4 out of 14 states are represented.
0 out of 11 symbols keep track of their start position.
0 out of 11 symbols keep track of their end position.
7 out of 14 states have a default reduction.
4 out of 8 productions exploit shiftreduce optimization.
0 out of 14 states can peek at an error.
45 functions before inlining, 7 functions after inlining.
test/good/bibtex_parser.exp
View file @
2abde9bf
...
...
@@ 33,10 +33,10 @@ follow(atom) = Tsharp Trbrace Tcomma
Built an LR(0) automaton with 34 states.
The grammar is SLR(1).
Built an LR(1) automaton with 47 states.
21 out of 47 states have a default reduction.
11 out of 47 states are represented.
0 out of 25 symbols keep track of their start position.
0 out of 25 symbols keep track of their end position.
21 out of 47 states have a default reduction.
13 out of 21 productions exploit shiftreduce optimization.
0 out of 47 states can peek at an error.
131 functions before inlining, 22 functions after inlining.
test/good/bisonmysteriousconflict.exp
View file @
2abde9bf
...
...
@@ 22,10 +22,10 @@ follow(def) = #
Built an LR(0) automaton with 19 states.
The grammar is not SLR(1)  1 states have a conflict.
Built an LR(1) automaton with 20 states.
9 out of 20 states have a default reduction.
5 out of 20 states are represented.
0 out of 12 symbols keep track of their start position.
0 out of 12 symbols keep track of their end position.
9 out of 20 states have a default reduction.
6 out of 10 productions exploit shiftreduce optimization.
0 out of 20 states can peek at an error.
62 functions before inlining, 10 functions after inlining.
test/good/borismini.exp
View file @
2abde9bf
...
...
@@ 18,13 +18,13 @@ Warning: 3 states have reduce/reduce conflicts.
Warning: 5 shift/reduce conflicts were arbitrarily resolved.
Warning: 3 reduce/reduce conflicts were arbitrarily resolved.
Warning: one state has an endofstream conflict.
3 out of 15 states have a default reduction.