mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 12:23:04 +00:00
java: example: rely on autoboxing
AFAICT, autoboxing/unboxing was added in Java 5 (September 30, 2004). I think we can afford to use it. It should help us merge some Java tests with the main ones. However, beware that != does not unbox: it compares the object addresses. * examples/java/Calc.y, tests/java.at: Simplify. * examples/java/Calc.test, tests/java.at: Improve tests.
This commit is contained in:
@@ -97,24 +97,22 @@ line:
|
||||
;
|
||||
|
||||
exp:
|
||||
NUM { $$ = $1; }
|
||||
NUM { $$ = $1; }
|
||||
| exp '=' exp
|
||||
{
|
||||
if ($1.intValue () != $3.intValue ())
|
||||
yyerror (]AT_LOCATION_IF([[@$,]])[ "calc: error: " + $1 + " != " + $3);
|
||||
yyerror (]AT_LOCATION_IF([[@$, ]])["calc: error: " + $1 + " != " + $3);
|
||||
}
|
||||
| exp '+' exp { $$ = new Integer ($1.intValue () + $3.intValue ()); }
|
||||
| exp '-' exp { $$ = new Integer ($1.intValue () - $3.intValue ()); }
|
||||
| exp '*' exp { $$ = new Integer ($1.intValue () * $3.intValue ()); }
|
||||
| exp '/' exp { $$ = new Integer ($1.intValue () / $3.intValue ()); }
|
||||
| '-' exp %prec NEG { $$ = new Integer (-$2.intValue ()); }
|
||||
| exp '^' exp { $$ = new Integer ((int)
|
||||
Math.pow ($1.intValue (),
|
||||
$3.intValue ())); }
|
||||
| '(' exp ')' { $$ = $2; }
|
||||
| '(' error ')' { $$ = new Integer (1111); }
|
||||
| '!' { $$ = new Integer (0); return YYERROR; }
|
||||
| '-' error { $$ = new Integer (0); return YYERROR; }
|
||||
| exp '+' exp { $$ = $1 + $3; }
|
||||
| exp '-' exp { $$ = $1 - $3; }
|
||||
| exp '*' exp { $$ = $1 * $3; }
|
||||
| exp '/' exp { $$ = $1 / $3; }
|
||||
| '-' exp %prec NEG { $$ = -$2; }
|
||||
| exp '^' exp { $$ = (int) Math.pow ($1, $3); }
|
||||
| '(' exp ')' { $$ = $2; }
|
||||
| '(' error ')' { $$ = 1111; }
|
||||
| '!' { $$ = 0; return YYERROR; }
|
||||
| '-' error { $$ = 0; return YYERROR; }
|
||||
;
|
||||
|
||||
]AT_LEXPARAM_IF([[%code lexer {]],
|
||||
@@ -257,7 +255,7 @@ AT_DATA([[input]],
|
||||
2^2^3 = 256
|
||||
(2^2)^3 = 64
|
||||
]])
|
||||
AT_JAVA_PARSER_CHECK([Calc < input], 0, [], [stderr])
|
||||
AT_JAVA_PARSER_CHECK([Calc < input])
|
||||
|
||||
|
||||
# Some syntax errors.
|
||||
|
||||
Reference in New Issue
Block a user