[Mesa-dev] [PATCH 07/10] glsl: Instruct bison to expect one shift/reduce conflict

Carl Worth cworth at cworth.org
Sat Dec 8 13:43:42 PST 2012


This one is unavoidable as C is inherently ambiguous, (from the point-of-view
of the parser), in the dangling-else case. Now, C is unambiguous in that the
dangling "else" should bind to the innermost "if". This is exactly what bison
accomplishes by preferring to shift rather than reduce.

The "expect" statement here tells bison to expect one shift/reduce conflict
silently. It will then trigger an error if any future changes in the grammar
introduce additional conflicts.
---
 src/glsl/glsl_parser.yy |    6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/glsl/glsl_parser.yy b/src/glsl/glsl_parser.yy
index d849466..0af71e7 100644
--- a/src/glsl/glsl_parser.yy
+++ b/src/glsl/glsl_parser.yy
@@ -56,6 +56,12 @@ static void yyerror(YYLTYPE *loc, _mesa_glsl_parse_state *st, const char *msg)
 %lex-param   {void *scanner}
 %parse-param {struct _mesa_glsl_parse_state *state}
 
+/* C grammar has 1 unavoidable shift/reduce conflict, (the dangling-
+ * else ambiguity), which bison correctly resolves by preferring
+ * to shift.
+ */
+%expect 1
+
 %union {
    int n;
    float real;
-- 
1.7.10



More information about the mesa-dev mailing list