Rob Shearman : jscript: Fix shift/reduce conflict in IfStatement rule.

Alexandre Julliard julliard at winehq.org
Wed Oct 15 10:08:52 CDT 2008


Module: wine
Branch: master
Commit: 169f92b5a807425972674d207736fa4b4b4743e3
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=169f92b5a807425972674d207736fa4b4b4743e3

Author: Rob Shearman <robertshearman at gmail.com>
Date:   Wed Oct 15 14:10:07 2008 +0100

jscript: Fix shift/reduce conflict in IfStatement rule.

The famous "dangling else" problem.

---

 dlls/jscript/parser.y      |    5 ++++-
 dlls/jscript/tests/lang.js |   12 ++++++++++++
 2 files changed, 16 insertions(+), 1 deletions(-)

diff --git a/dlls/jscript/parser.y b/dlls/jscript/parser.y
index 565f08b..af3d35d 100644
--- a/dlls/jscript/parser.y
+++ b/dlls/jscript/parser.y
@@ -253,6 +253,9 @@ static source_elements_t *source_elements_add_function(source_elements_t*,functi
 %type <literal> BooleanLiteral
 %type <srcptr> KFunction
 
+%nonassoc LOWER_THAN_ELSE
+%nonassoc kELSE
+
 %%
 
 /* ECMA-262 3rd Edition    14 */
@@ -389,7 +392,7 @@ ExpressionStatement
 IfStatement
         : kIF '(' Expression ')' Statement kELSE Statement
                                 { $$ = new_if_statement(ctx, $3, $5, $7); }
-        | kIF '(' Expression ')' Statement
+        | kIF '(' Expression ')' Statement %prec LOWER_THAN_ELSE
                                 { $$ = new_if_statement(ctx, $3, $5, NULL); }
 
 /* ECMA-262 3rd Edition    12.6 */
diff --git a/dlls/jscript/tests/lang.js b/dlls/jscript/tests/lang.js
index 16dadbd..b989645 100644
--- a/dlls/jscript/tests/lang.js
+++ b/dlls/jscript/tests/lang.js
@@ -773,6 +773,18 @@ try {
     ok(false, "deleteTest not throwed exception?");
 }catch(ex) {}
 
+if (false)
+    if (true)
+        ok(false, "if evaluated");
+    else
+        ok(false, "else should be associated with nearest if statement");
+
+if (true)
+    if (false)
+        ok(false, "if evaluated");
+    else
+        ok(true, "else should be associated with nearest if statement");
+
 ok(isNaN(0.5) === false, "isNaN(0.5) !== false");
 ok(isNaN() === true, "isNaN() !== true");
 




More information about the wine-cvs mailing list