Merge pull request #598 from yallop/ocamlyacc-conflict-error

Reject conflicts in parsing/parser.mly
master
Gabriel Scherer 2016-06-26 15:36:32 -04:00 committed by GitHub
commit bd9693b3eb
6 changed files with 25 additions and 3 deletions

View File

@ -28,7 +28,7 @@ COMPFLAGS=-strict-sequence -principal -absname -w +a-4-9-41-42-44-45-48 -warn-er
-bin-annot -safe-string -strict-formats $(INCLUDES)
LINKFLAGS=
YACCFLAGS=-v
YACCFLAGS=-v --strict
CAMLLEX=$(CAMLRUN) boot/ocamllex
CAMLDEP=$(CAMLRUN) tools/ocamldep
DEPFLAGS=$(INCLUDES)

View File

@ -79,6 +79,9 @@ instead of the default naming convention.
.B \-q
This option has no effect.
.TP
.B \--strict
Reject grammars with conflicts.
.TP
.B \-v
Generate a description of the parsing tables and a report on conflicts
resulting from ambiguities in the grammar. The description is put in

View File

@ -210,6 +210,7 @@ extern char tflag;
extern char vflag;
extern char qflag;
extern char sflag;
extern char eflag;
extern char big_endian;
extern char *myname;
@ -335,6 +336,7 @@ extern void output (void);
extern void over_unionized (char *u_cptr) Noreturn;
extern void prec_redeclared (void);
extern void polymorphic_entry_point(char *s) Noreturn;
extern void forbidden_conflicts (void);
extern void reader (void);
extern void reflexive_transitive_closure (unsigned int *R, int n);
extern void reprec_warning (char *s);

View File

@ -313,3 +313,11 @@ void polymorphic_entry_point(char *s)
myname, s);
done(1);
}
void forbidden_conflicts(void)
{
fprintf(stderr,
"%s: the grammar has conflicts, but --strict was specified\n",
myname);
done(1);
}

View File

@ -30,6 +30,7 @@ char rflag;
char tflag;
char vflag;
char qflag;
char eflag;
char sflag;
char big_endian;
@ -160,7 +161,7 @@ void set_signals(void)
void usage(void)
{
fprintf(stderr, "usage: %s [-v] [-q] [-b file_prefix] filename\n",
fprintf(stderr, "usage: %s [-v] [--strict] [-q] [-b file_prefix] filename\n",
myname);
exit(1);
}
@ -184,6 +185,10 @@ void getargs(int argc, char **argv)
return;
case '-':
if (!strcmp (argv[i], "--strict")){
eflag = 1;
goto end_of_option;
}
++i;
goto no_more_options;

View File

@ -47,7 +47,11 @@ void make_parser(void)
find_final_state();
remove_conflicts();
unused_rules();
if (SRtotal + RRtotal > 0) total_conflicts();
if (SRtotal + RRtotal > 0) {
total_conflicts();
if (eflag)
forbidden_conflicts();
}
defreds();
}