jscript: Fix shift/reduce conflict in IfStatement rule.

The famous "dangling else" problem.
oldstable
Rob Shearman 2008-10-15 14:10:07 +01:00 committed by Alexandre Julliard
parent 7b9e827a75
commit 169f92b5a8
2 changed files with 16 additions and 1 deletions

View File

@ -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 */

View File

@ -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");