summaryrefslogtreecommitdiff
path: root/yacc
diff options
context:
space:
mode:
authorJeremy Yallop <yallop@gmail.com>2016-05-31 20:20:46 +0100
committerJeremy Yallop <yallop@gmail.com>2016-05-31 20:45:06 +0100
commit54065bb1d08ff0e75ec2165543daa467dd4f207f (patch)
treef4da415bb6688e5915ed9b0f8179bd574e8f1bee /yacc
parentf54c38ba0c88a74b710ff392cf466c0427dc7b26 (diff)
downloadocaml-54065bb1d08ff0e75ec2165543daa467dd4f207f.tar.gz
Add an -e option to ocamlyacc to reject grammars with conflicts.
Diffstat (limited to 'yacc')
-rw-r--r--yacc/defs.h2
-rw-r--r--yacc/error.c8
-rw-r--r--yacc/main.c7
-rw-r--r--yacc/mkpar.c6
4 files changed, 21 insertions, 2 deletions
diff --git a/yacc/defs.h b/yacc/defs.h
index 4168076515..8377d05de5 100644
--- a/yacc/defs.h
+++ b/yacc/defs.h
@@ -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);
diff --git a/yacc/error.c b/yacc/error.c
index 1b533a4342..30275942e3 100644
--- a/yacc/error.c
+++ b/yacc/error.c
@@ -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 -e was specified\n",
+ myname);
+ done(1);
+}
diff --git a/yacc/main.c b/yacc/main.c
index 329d397fbd..60993f961e 100644
--- a/yacc/main.c
+++ b/yacc/main.c
@@ -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] [-e] [-q] [-b file_prefix] filename\n",
myname);
exit(1);
}
@@ -213,6 +214,10 @@ void getargs(int argc, char **argv)
usage();
continue;
+ case 'e':
+ eflag = 1;
+ continue;
+
default:
usage();
}
diff --git a/yacc/mkpar.c b/yacc/mkpar.c
index 79b2f928bd..8064f5b3b1 100644
--- a/yacc/mkpar.c
+++ b/yacc/mkpar.c
@@ -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();
}