Module: Mesa
Branch: master
Commit: 73620709c9dce79e58bd0d29be95c658ac95779b
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=73620709c9dce79e58bd0d29be95c658ac95779b

Author: Kenneth Graunke <[email protected]>
Date:   Fri Jul 12 23:10:14 2013 -0700

glsl: Silence the last shift/reduce conflict warning in the grammar.

The single remaining shift/reduce conflict was the classic ELSE problem:

  292 selection_rest_statement: statement . ELSE statement
  293                         | statement .

    ELSE  shift, and go to state 479

    ELSE      [reduce using rule 293 (selection_rest_statement)]
    $default  reduce using rule 293 (selection_rest_statement)

The correct behavior here is to shift, which is what happens by default.
However, resolving it explicitly will make it possible to fail the build
on new errors, making them much easier to detect.

The classic way to solve this is to use right associativity:
http://www.gnu.org/software/bison/manual/html_node/Non-Operators.html

Since there is no THEN token in GLSL, we need to fake one.  %right THEN
creates a new terminal symbol; the %prec directive says to use the
precedence of that terminal.

Signed-off-by: Kenneth Graunke <[email protected]>
Reviewed-by: Chris Forbes <[email protected]>

---

 src/glsl/glsl_parser.yy |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/src/glsl/glsl_parser.yy b/src/glsl/glsl_parser.yy
index 78f5bf6..e4b7ff7 100644
--- a/src/glsl/glsl_parser.yy
+++ b/src/glsl/glsl_parser.yy
@@ -248,6 +248,8 @@ static void yyerror(YYLTYPE *loc, _mesa_glsl_parse_state 
*st, const char *msg)
 %type <node> for_init_statement
 %type <for_rest_statement> for_rest_statement
 %type <n> integer_constant
+
+%right THEN ELSE
 %%
 
 translation_unit: 
@@ -1738,7 +1740,7 @@ selection_rest_statement:
           $$.then_statement = $1;
           $$.else_statement = $3;
        }
-       | statement
+       | statement %prec THEN
        {
           $$.then_statement = $1;
           $$.else_statement = NULL;

_______________________________________________
mesa-commit mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/mesa-commit

Reply via email to