OLD | NEW |
(Empty) | |
| 1 # Java tests for simple calculator. -*- Autotest -*- |
| 2 |
| 3 # Copyright (C) 2007, 2008 Free Software Foundation, Inc. |
| 4 |
| 5 # This program is free software: you can redistribute it and/or modify |
| 6 # it under the terms of the GNU General Public License as published by |
| 7 # the Free Software Foundation, either version 3 of the License, or |
| 8 # (at your option) any later version. |
| 9 # |
| 10 # This program is distributed in the hope that it will be useful, |
| 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 # GNU General Public License for more details. |
| 14 # |
| 15 # You should have received a copy of the GNU General Public License |
| 16 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
| 18 AT_BANNER([[Java Calculator.]]) |
| 19 |
| 20 |
| 21 # ------------------------- # |
| 22 # Helping Autotest macros. # |
| 23 # ------------------------- # |
| 24 |
| 25 |
| 26 # _AT_DATA_JAVA_CALC_Y($1, $2, $3, [BISON-DIRECTIVES]) |
| 27 # ---------------------------------------------------------------------- |
| 28 # Produce `calc.y'. Don't call this macro directly, because it contains |
| 29 # some occurrences of `$1' etc. which will be interpreted by m4. So |
| 30 # you should call it with $1, $2, and $3 as arguments, which is what |
| 31 # AT_DATA_JAVA_CALC_Y does. |
| 32 m4_define([_AT_DATA_JAVA_CALC_Y], |
| 33 [m4_if([$1$2$3], $[1]$[2]$[3], [], |
| 34 [m4_fatal([$0: Invalid arguments: $@])])dnl |
| 35 AT_DATA([Calc.y], |
| 36 [[/* Infix notation calculator--calc */ |
| 37 %language "Java" |
| 38 %name-prefix "Calc" |
| 39 %define parser_class_name "Calc" |
| 40 %define public |
| 41 |
| 42 ]$4[ |
| 43 |
| 44 %code imports { |
| 45 import java.io.StreamTokenizer; |
| 46 import java.io.InputStream; |
| 47 import java.io.InputStreamReader; |
| 48 import java.io.Reader; |
| 49 import java.io.IOException; |
| 50 } |
| 51 |
| 52 /* Bison Declarations */ |
| 53 %token <Integer> NUM "number" |
| 54 %type <Integer> exp |
| 55 |
| 56 %nonassoc '=' /* comparison */ |
| 57 %left '-' '+' |
| 58 %left '*' '/' |
| 59 %left NEG /* negation--unary minus */ |
| 60 %right '^' /* exponentiation */ |
| 61 |
| 62 /* Grammar follows */ |
| 63 %% |
| 64 input: |
| 65 line |
| 66 | input line |
| 67 ; |
| 68 |
| 69 line: |
| 70 '\n' |
| 71 | exp '\n' |
| 72 | error '\n' |
| 73 ; |
| 74 |
| 75 exp: |
| 76 NUM { $$ = $1; } |
| 77 | exp '=' exp |
| 78 { |
| 79 if ($1.intValue () != $3.intValue ()) |
| 80 yyerror ("calc: error: " + $1 + " != " + $3); |
| 81 } |
| 82 | exp '+' exp { $$ = new Integer ($1.intValue () + $3.intValue ()); } |
| 83 | exp '-' exp { $$ = new Integer ($1.intValue () - $3.intValue ()); } |
| 84 | exp '*' exp { $$ = new Integer ($1.intValue () * $3.intValue ()); } |
| 85 | exp '/' exp { $$ = new Integer ($1.intValue () / $3.intValue ()); } |
| 86 | '-' exp %prec NEG { $$ = new Integer (-$2.intValue ()); } |
| 87 | exp '^' exp { $$ = new Integer ((int) |
| 88 Math.pow ($1.intValue (), |
| 89 $3.intValue ())); } |
| 90 | '(' exp ')' { $$ = $2; } |
| 91 | '(' error ')' { $$ = new Integer (1111); } |
| 92 | '!' { $$ = new Integer (0); return YYERROR; } |
| 93 | '-' error { $$ = new Integer (0); return YYERROR; } |
| 94 ; |
| 95 |
| 96 ]AT_LEXPARAM_IF([[ |
| 97 %code lexer { |
| 98 ]], |
| 99 [[ |
| 100 %% |
| 101 class CalcLexer implements Calc.Lexer { |
| 102 ]])[ |
| 103 StreamTokenizer st; |
| 104 |
| 105 public ]AT_LEXPARAM_IF([[YYLexer]], [[CalcLexer]]) (InputStream is) |
| 106 { |
| 107 st = new StreamTokenizer (new InputStreamReader (is)); |
| 108 st.resetSyntax (); |
| 109 st.eolIsSignificant (true); |
| 110 st.whitespaceChars (9, 9); |
| 111 st.whitespaceChars (32, 32); |
| 112 st.wordChars (48, 57); |
| 113 } |
| 114 |
| 115 AT_LOCATION_IF([[ |
| 116 Position yystartpos; |
| 117 Position yyendpos = new Position (1); |
| 118 |
| 119 public Position getStartPos() { |
| 120 return yystartpos; |
| 121 } |
| 122 |
| 123 public Position getEndPos() { |
| 124 return yyendpos; |
| 125 } |
| 126 |
| 127 public void yyerror (Calc.Location l, String s) |
| 128 { |
| 129 if (l == null) |
| 130 System.err.println (s); |
| 131 else |
| 132 System.err.println (l.begin + ": " + s); |
| 133 } |
| 134 ]], [[ |
| 135 public void yyerror (String s) |
| 136 { |
| 137 System.err.println (s); |
| 138 } |
| 139 ]])[ |
| 140 |
| 141 Integer yylval; |
| 142 |
| 143 public Object getLVal() { |
| 144 return yylval; |
| 145 } |
| 146 |
| 147 public int yylex () throws IOException { |
| 148 int ttype = st.nextToken (); |
| 149 ]AT_LOCATION_IF([[yystartpos = yyendpos;]])[ |
| 150 if (ttype == st.TT_EOF) |
| 151 return Calc.EOF; |
| 152 |
| 153 else if (ttype == st.TT_EOL) |
| 154 { |
| 155 ]AT_LOCATION_IF([[yyendpos = new Position (yyendpos.lineno () + 1);]])[ |
| 156 return (int) '\n'; |
| 157 } |
| 158 |
| 159 else if (ttype == st.TT_WORD) |
| 160 { |
| 161 yylval = new Integer (st.sval); |
| 162 return Calc.NUM; |
| 163 } |
| 164 |
| 165 else |
| 166 return st.ttype; |
| 167 } |
| 168 |
| 169 |
| 170 ]AT_LEXPARAM_IF([[ |
| 171 }; |
| 172 %%]], [[ |
| 173 }]]) |
| 174 |
| 175 [ |
| 176 class Position { |
| 177 public int line; |
| 178 |
| 179 public Position () |
| 180 { |
| 181 line = 0; |
| 182 } |
| 183 |
| 184 public Position (int l) |
| 185 { |
| 186 line = l; |
| 187 } |
| 188 |
| 189 public long getHashCode () |
| 190 { |
| 191 return line; |
| 192 } |
| 193 |
| 194 public boolean equals (Position l) |
| 195 { |
| 196 return l.line == line; |
| 197 } |
| 198 |
| 199 public String toString () |
| 200 { |
| 201 return Integer.toString (line); |
| 202 } |
| 203 |
| 204 public int lineno () |
| 205 { |
| 206 return line; |
| 207 } |
| 208 } |
| 209 |
| 210 ]]) |
| 211 ])# _AT_DATA_JAVA_CALC_Y |
| 212 |
| 213 |
| 214 # AT_DATA_CALC_Y([BISON-OPTIONS]) |
| 215 # ------------------------------------------------- |
| 216 # Produce `calc.y'. |
| 217 m4_define([AT_DATA_JAVA_CALC_Y], |
| 218 [_AT_DATA_JAVA_CALC_Y($[1], $[2], $[3], [$1]) |
| 219 ]) |
| 220 |
| 221 |
| 222 |
| 223 # AT_JAVA_COMPILE(SOURCE) |
| 224 # ----------------------- |
| 225 # Compile SOURCES into Java class files. Skip the test if java or javac is |
| 226 # not installed. |
| 227 m4_define([AT_JAVA_COMPILE], |
| 228 [AT_CHECK([test -n "$CONF_JAVA" || exit 77 |
| 229 test -n "$CONF_JAVAC" || exit 77]) |
| 230 AT_CHECK([$SHELL ../../../javacomp.sh $1], |
| 231 0, [ignore], [ignore])]) |
| 232 |
| 233 |
| 234 # AT_JAVA_PARSER_CHECK(COMMAND, EXIT-STATUS, EXPOUT, EXPERR, [PRE]) |
| 235 # ----------------------------------------------------------------- |
| 236 m4_define([AT_JAVA_PARSER_CHECK], |
| 237 [AT_CHECK([$5 $SHELL ../../../javaexec.sh $1], [$2], [$3], [$4])]) |
| 238 |
| 239 |
| 240 # _AT_CHECK_JAVA_CALC_ERROR(BISON-OPTIONS, INPUT, |
| 241 # [VERBOSE-AND-LOCATED-ERROR-MESSAGE]) |
| 242 # --------------------------------------------------------- |
| 243 # Run `calc' on INPUT, and expect a `syntax error' message. |
| 244 # |
| 245 # If INPUT starts with a slash, it is used as absolute input file name, |
| 246 # otherwise as contents. |
| 247 # |
| 248 # The VERBOSE-AND-LOCATED-ERROR-MESSAGE is stripped of locations |
| 249 # and expected tokens if necessary, and compared with the output. |
| 250 m4_define([_AT_CHECK_JAVA_CALC_ERROR], |
| 251 [m4_bmatch([$2], [^/], |
| 252 [AT_JAVA_PARSER_CHECK([Calc < $2], 0, [], [stderr])], |
| 253 [AT_DATA([[input]], |
| 254 [[$2 |
| 255 ]]) |
| 256 AT_JAVA_PARSER_CHECK([Calc < input], 0, [], [stderr])]) |
| 257 |
| 258 # Normalize the observed and expected error messages, depending upon the |
| 259 # options. |
| 260 # 1. Create the reference error message. |
| 261 AT_DATA([[expout]], |
| 262 [$3 |
| 263 ]) |
| 264 # 2. If locations are not used, remove them. |
| 265 AT_YYERROR_SEES_LOC_IF([], |
| 266 [[sed 's/^[-0-9.]*: //' expout >at-expout |
| 267 mv at-expout expout]]) |
| 268 # 3. If error-verbose is not used, strip the`, unexpected....' part. |
| 269 m4_bmatch([$1], [%error-verbose], [], |
| 270 [[sed 's/syntax error, .*$/syntax error/' expout >at-expout |
| 271 mv at-expout expout]]) |
| 272 # 4. Check |
| 273 AT_CHECK([cat stderr], 0, [expout]) |
| 274 ]) |
| 275 |
| 276 # _AT_CHECK_JAVA_CALC([BISON-DIRECTIVES], [BISON-CODE]) |
| 277 # ----------------------------------------------------------------------- |
| 278 # Start a testing chunk which compiles `calc' grammar with |
| 279 # BISON-DIRECTIVES, and performs several tests over the parser. |
| 280 m4_define([_AT_CHECK_JAVA_CALC], |
| 281 [# We use integers to avoid dependencies upon the precision of doubles. |
| 282 AT_SETUP([Calculator $1]) |
| 283 |
| 284 AT_BISON_OPTION_PUSHDEFS([$1]) |
| 285 |
| 286 AT_DATA_JAVA_CALC_Y([$1 |
| 287 %code { |
| 288 $2 |
| 289 }]) |
| 290 |
| 291 AT_BISON_CHECK([-o Calc.java Calc.y]) |
| 292 AT_JAVA_COMPILE([Calc.java]) |
| 293 |
| 294 # Test the priorities. |
| 295 AT_DATA([[input]], |
| 296 [[1 + 2 * 3 = 7 |
| 297 1 + 2 * -3 = -5 |
| 298 |
| 299 -1^2 = -1 |
| 300 (-1)^2 = 1 |
| 301 |
| 302 ---1 = -1 |
| 303 |
| 304 1 - 2 - 3 = -4 |
| 305 1 - (2 - 3) = 2 |
| 306 |
| 307 2^2^3 = 256 |
| 308 (2^2)^3 = 64 |
| 309 ]]) |
| 310 AT_JAVA_PARSER_CHECK([Calc < input], 0, [], [stderr]) |
| 311 |
| 312 |
| 313 # Some syntax errors. |
| 314 _AT_CHECK_JAVA_CALC_ERROR([$1], [0 0], |
| 315 [1: syntax error, unexpected number]) |
| 316 _AT_CHECK_JAVA_CALC_ERROR([$1], [1//2], |
| 317 [1: syntax error, unexpected '/', expecting number or
'-' or '(' or '!']) |
| 318 _AT_CHECK_JAVA_CALC_ERROR([$1], [error], |
| 319 [1: syntax error, unexpected $undefined]) |
| 320 _AT_CHECK_JAVA_CALC_ERROR([$1], [1 = 2 = 3], |
| 321 [1: syntax error, unexpected '=']) |
| 322 _AT_CHECK_JAVA_CALC_ERROR([$1], [ |
| 323 +1], |
| 324 [2: syntax error, unexpected '+']) |
| 325 # Exercise error messages with EOF: work on an empty file. |
| 326 _AT_CHECK_JAVA_CALC_ERROR([$1], [/dev/null], |
| 327 [1: syntax error, unexpected end of input]) |
| 328 |
| 329 # Exercise the error token: without it, we die at the first error, |
| 330 # hence be sure to |
| 331 # |
| 332 # - have several errors which exercise different shift/discardings |
| 333 # - (): nothing to pop, nothing to discard |
| 334 # - (1 + 1 + 1 +): a lot to pop, nothing to discard |
| 335 # - (* * *): nothing to pop, a lot to discard |
| 336 # - (1 + 2 * *): some to pop and discard |
| 337 # |
| 338 # - test the action associated to `error' |
| 339 # |
| 340 # - check the lookahead that triggers an error is not discarded |
| 341 # when we enter error recovery. Below, the lookahead causing the |
| 342 # first error is ")", which is needed to recover from the error and |
| 343 # produce the "0" that triggers the "0 != 1" error. |
| 344 # |
| 345 _AT_CHECK_JAVA_CALC_ERROR([$1], |
| 346 [() + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1], |
| 347 [1: syntax error, unexpected ')', expecting number or '-' or '(' or '!' |
| 348 1: syntax error, unexpected ')', expecting number or '-' or '(' or '!' |
| 349 1: syntax error, unexpected '*', expecting number or '-' or '(' or '!' |
| 350 1: syntax error, unexpected '*', expecting number or '-' or '(' or '!' |
| 351 calc: error: 4444 != 1]) |
| 352 |
| 353 # The same, but this time exercising explicitly triggered syntax errors. |
| 354 # POSIX says the lookahead causing the error should not be discarded. |
| 355 _AT_CHECK_JAVA_CALC_ERROR([$1], [(!) + (0 0) = 1], |
| 356 [1: syntax error, unexpected number |
| 357 calc: error: 2222 != 1]) |
| 358 _AT_CHECK_JAVA_CALC_ERROR([$1], [(- *) + (0 0) = 1], |
| 359 [1: syntax error, unexpected '*', expecting number or '-' or '(' or '!' |
| 360 1: syntax error, unexpected number |
| 361 calc: error: 2222 != 1]) |
| 362 AT_BISON_OPTION_POPDEFS |
| 363 |
| 364 AT_CLEANUP |
| 365 ])# _AT_CHECK_JAVA_CALC |
| 366 |
| 367 |
| 368 # AT_CHECK_JAVA_CALC([BISON-DIRECTIVES]) |
| 369 # -------------------------------------------------------- |
| 370 # Start a testing chunk which compiles `calc' grammar with |
| 371 # BISON-DIRECTIVES, and performs several tests over the parser. |
| 372 # Run the test with and without %error-verbose. |
| 373 m4_define([AT_CHECK_JAVA_CALC], |
| 374 [_AT_CHECK_JAVA_CALC([$1], [$2]) |
| 375 _AT_CHECK_JAVA_CALC([%error-verbose $1], [$2]) |
| 376 _AT_CHECK_JAVA_CALC([%locations $1], [$2]) |
| 377 _AT_CHECK_JAVA_CALC([%error-verbose %locations $1], [$2]) |
| 378 ])# AT_CHECK_JAVA_CALC |
| 379 |
| 380 |
| 381 # ------------------------ # |
| 382 # Simple LALR Calculator. # |
| 383 # ------------------------ # |
| 384 |
| 385 AT_CHECK_JAVA_CALC([], [[ |
| 386 public static void main (String args[]) throws IOException |
| 387 { |
| 388 CalcLexer l = new CalcLexer (System.in); |
| 389 Calc p = new Calc (l); |
| 390 p.parse (); |
| 391 } |
| 392 ]]) |
| 393 |
| 394 AT_CHECK_JAVA_CALC([%lex-param { InputStream is } ], [[ |
| 395 public static void main (String args[]) throws IOException |
| 396 { |
| 397 new Calc (System.in).parse (); |
| 398 } |
| 399 ]]) |
| 400 |
| 401 |
| 402 |
| 403 # -----------------# |
| 404 # Java Directives. # |
| 405 # -----------------# |
| 406 |
| 407 AT_BANNER([Java Parameters.]) |
| 408 |
| 409 |
| 410 # AT_CHECK_JAVA_MINIMAL([DIRECTIVES], [PARSER_ACTION], [POSITION_CLASS]) |
| 411 # ---------------------------------------------------------------------- |
| 412 # Check that a mininal parser with DIRECTIVES compiles in Java. |
| 413 # Put the Java code in YYParser.java. |
| 414 m4_define([AT_CHECK_JAVA_MINIMAL], |
| 415 [ |
| 416 AT_DATA([[YYParser.y]], [ |
| 417 %language "Java" |
| 418 %locations |
| 419 %debug |
| 420 %error-verbose |
| 421 %token-table |
| 422 $1 |
| 423 %% |
| 424 start: "end" {$2}; |
| 425 %% |
| 426 class m4_default([$3], [Position]) {} |
| 427 ]) |
| 428 AT_BISON_CHECK([[YYParser.y]]) |
| 429 AT_CHECK([[grep -q '[mb]4_' YYParser.y]], [1]) |
| 430 AT_JAVA_COMPILE([[YYParser.java]]) |
| 431 ]) |
| 432 |
| 433 |
| 434 # AT_CHECK_JAVA_MINIMAL_W_LEXER([1:DIRECTIVES], [2:LEX_THROWS], |
| 435 # [3:YYLEX_ACTION], [4:LEXER_BODY], [5:PARSER_ACTION], [6:STYPE], |
| 436 # [7:POSITION_TYPE], [8:LOCATION_TYPE]) |
| 437 # --------------------------------------------------------------------- |
| 438 # Check that a mininal parser with DIRECTIVES and a "%code lexer". |
| 439 # YYLEX is the body of yylex () which throws LEX_THROW. |
| 440 # compiles in Java. |
| 441 m4_define([AT_CHECK_JAVA_MINIMAL_W_LEXER], |
| 442 [AT_CHECK_JAVA_MINIMAL([$1 |
| 443 |
| 444 %code lexer |
| 445 { |
| 446 m4_default([$6], [Object]) yylval; |
| 447 public m4_default([$6], [Object]) getLVal() { return yylval; } |
| 448 |
| 449 public m4_default([$7], [Position]) getStartPos() { return null; } |
| 450 public m4_default([$7], [Position]) getEndPos() { return null; } |
| 451 |
| 452 public void yyerror (m4_default([$8], [Location]) loc, String s) |
| 453 { |
| 454 System.err.println (loc + ": " + s); |
| 455 } |
| 456 |
| 457 public int yylex ()$2 |
| 458 { |
| 459 $3 |
| 460 } |
| 461 |
| 462 $4 |
| 463 }], [$5], [$7])]) |
| 464 |
| 465 |
| 466 # AT_CHECK_JAVA_GREP([LINE], [COUNT=1]) |
| 467 # ------------------------------------- |
| 468 # Check that YYParser.java contains exactly COUNT lines matching ^LINE$ |
| 469 # with grep. |
| 470 m4_define([AT_CHECK_JAVA_GREP], |
| 471 [AT_CHECK([grep -c '^$1$' YYParser.java], [], [m4_default([$2], [1]) |
| 472 ]) |
| 473 ]) |
| 474 |
| 475 |
| 476 # ----------------------------------- # |
| 477 # Java parser class and package names # |
| 478 # ----------------------------------- # |
| 479 |
| 480 AT_SETUP([Java parser class and package names]) |
| 481 |
| 482 AT_CHECK_JAVA_MINIMAL([]) |
| 483 AT_CHECK_JAVA_GREP([[class YYParser]]) |
| 484 |
| 485 AT_CHECK_JAVA_MINIMAL([[%name-prefix "Prefix"]]) |
| 486 AT_CHECK_JAVA_GREP([[class PrefixParser]]) |
| 487 |
| 488 AT_CHECK_JAVA_MINIMAL([[%define parser_class_name "ParserClassName"]]) |
| 489 AT_CHECK_JAVA_GREP([[class ParserClassName]]) |
| 490 |
| 491 AT_CHECK_JAVA_MINIMAL([[%define package "user_java_package"]]) |
| 492 AT_CHECK_JAVA_GREP([[package user_java_package;]]) |
| 493 |
| 494 AT_CLEANUP |
| 495 |
| 496 |
| 497 # --------------------------- # |
| 498 # Java parser class modifiers # |
| 499 # --------------------------- # |
| 500 |
| 501 AT_SETUP([Java parser class modifiers]) |
| 502 |
| 503 AT_CHECK_JAVA_MINIMAL([[%define abstract]]) |
| 504 AT_CHECK_JAVA_GREP([[abstract class YYParser]]) |
| 505 |
| 506 AT_CHECK_JAVA_MINIMAL([[%define final]]) |
| 507 AT_CHECK_JAVA_GREP([[final class YYParser]]) |
| 508 |
| 509 AT_CHECK_JAVA_MINIMAL([[%define strictfp]]) |
| 510 AT_CHECK_JAVA_GREP([[strictfp class YYParser]]) |
| 511 |
| 512 AT_CHECK_JAVA_MINIMAL([[ |
| 513 %define abstract |
| 514 %define strictfp]]) |
| 515 AT_CHECK_JAVA_GREP([[abstract strictfp class YYParser]]) |
| 516 |
| 517 AT_CHECK_JAVA_MINIMAL([[ |
| 518 %define final |
| 519 %define strictfp]]) |
| 520 AT_CHECK_JAVA_GREP([[final strictfp class YYParser]]) |
| 521 |
| 522 AT_CHECK_JAVA_MINIMAL([[%define public]]) |
| 523 AT_CHECK_JAVA_GREP([[public class YYParser]]) |
| 524 |
| 525 AT_CHECK_JAVA_MINIMAL([[ |
| 526 %define public |
| 527 %define abstract]]) |
| 528 AT_CHECK_JAVA_GREP([[public abstract class YYParser]]) |
| 529 |
| 530 AT_CHECK_JAVA_MINIMAL([[ |
| 531 %define public |
| 532 %define final]]) |
| 533 AT_CHECK_JAVA_GREP([[public final class YYParser]]) |
| 534 |
| 535 AT_CHECK_JAVA_MINIMAL([[ |
| 536 %define public |
| 537 %define strictfp]]) |
| 538 AT_CHECK_JAVA_GREP([[public strictfp class YYParser]]) |
| 539 |
| 540 AT_CHECK_JAVA_MINIMAL([[ |
| 541 %define public |
| 542 %define abstract |
| 543 %define strictfp]]) |
| 544 AT_CHECK_JAVA_GREP([[public abstract strictfp class YYParser]]) |
| 545 |
| 546 AT_CHECK_JAVA_MINIMAL([[ |
| 547 %define public |
| 548 %define final |
| 549 %define strictfp]]) |
| 550 AT_CHECK_JAVA_GREP([[public final strictfp class YYParser]]) |
| 551 |
| 552 AT_CLEANUP |
| 553 |
| 554 |
| 555 # ---------------------------------------- # |
| 556 # Java parser class extends and implements # |
| 557 # ---------------------------------------- # |
| 558 |
| 559 AT_SETUP([Java parser class extends and implements]) |
| 560 |
| 561 AT_CHECK_JAVA_MINIMAL([[%define extends "Thread"]]) |
| 562 AT_CHECK_JAVA_GREP([[class YYParser extends Thread]]) |
| 563 |
| 564 AT_CHECK_JAVA_MINIMAL([[%define implements "Cloneable"]]) |
| 565 AT_CHECK_JAVA_GREP([[class YYParser implements Cloneable]]) |
| 566 |
| 567 AT_CHECK_JAVA_MINIMAL([[ |
| 568 %define extends "Thread" |
| 569 %define implements "Cloneable"]]) |
| 570 AT_CHECK_JAVA_GREP([[class YYParser extends Thread implements Cloneable]]) |
| 571 |
| 572 AT_CLEANUP |
| 573 |
| 574 |
| 575 # -------------------------------- # |
| 576 # Java %parse-param and %lex-param # |
| 577 # -------------------------------- # |
| 578 |
| 579 AT_SETUP([Java %parse-param and %lex-param]) |
| 580 |
| 581 AT_CHECK_JAVA_MINIMAL([]) |
| 582 AT_CHECK_JAVA_GREP([[ *public YYParser (Lexer yylexer) {]]) |
| 583 |
| 584 AT_CHECK_JAVA_MINIMAL([[%parse-param {int parse_param1}]]) |
| 585 AT_CHECK_JAVA_GREP([[ *protected final int parse_param1;]]) |
| 586 AT_CHECK_JAVA_GREP([[ *public YYParser (Lexer yylexer, *int parse_param1) {]]) |
| 587 AT_CHECK_JAVA_GREP([[[ ]*this.parse_param1 = parse_param1;]]) |
| 588 |
| 589 AT_CHECK_JAVA_MINIMAL([[ |
| 590 %parse-param {int parse_param1} |
| 591 %parse-param {long parse_param2}]]) |
| 592 AT_CHECK_JAVA_GREP([[ *protected final int parse_param1;]]) |
| 593 AT_CHECK_JAVA_GREP([[ *protected final long parse_param2;]]) |
| 594 AT_CHECK_JAVA_GREP([[ *public YYParser (Lexer yylexer, *int parse_param1, *long
parse_param2) {]]) |
| 595 AT_CHECK_JAVA_GREP([[[ ]*this.parse_param1 = parse_param1;]]) |
| 596 AT_CHECK_JAVA_GREP([[[ ]*this.parse_param2 = parse_param2;]]) |
| 597 |
| 598 AT_CHECK_JAVA_MINIMAL_W_LEXER([], [], [[return EOF;]]) |
| 599 AT_CHECK_JAVA_GREP([[ *public YYParser () {]]) |
| 600 AT_CHECK_JAVA_GREP([[ *protected YYParser (Lexer yylexer) {]]) |
| 601 |
| 602 AT_CHECK_JAVA_MINIMAL_W_LEXER([[%parse-param {int parse_param1}]], |
| 603 [], [[return EOF;]]) |
| 604 AT_CHECK_JAVA_GREP([[ *protected final int parse_param1;]]) |
| 605 AT_CHECK_JAVA_GREP([[ *public YYParser (int parse_param1) {]]) |
| 606 AT_CHECK_JAVA_GREP([[ *protected YYParser (Lexer yylexer, *int parse_param1) {]]
) |
| 607 AT_CHECK_JAVA_GREP([[[ ]*this.parse_param1 = parse_param1;]], [2]) |
| 608 |
| 609 AT_CHECK_JAVA_MINIMAL_W_LEXER([[ |
| 610 %parse-param {int parse_param1} |
| 611 %parse-param {long parse_param2}]], |
| 612 [], [[return EOF;]]) |
| 613 AT_CHECK_JAVA_GREP([[ *protected final int parse_param1;]]) |
| 614 AT_CHECK_JAVA_GREP([[ *protected final long parse_param2;]]) |
| 615 AT_CHECK_JAVA_GREP([[ *public YYParser (int parse_param1, *long parse_param2) {]
]) |
| 616 AT_CHECK_JAVA_GREP([[ *protected YYParser (Lexer yylexer, *int parse_param1, *lo
ng parse_param2) {]]) |
| 617 AT_CHECK_JAVA_GREP([[[ ]*this.parse_param1 = parse_param1;]], [2]) |
| 618 AT_CHECK_JAVA_GREP([[[ ]*this.parse_param2 = parse_param2;]], [2]) |
| 619 |
| 620 AT_CHECK_JAVA_MINIMAL_W_LEXER([[%lex-param {char lex_param1}]], |
| 621 [], [[return EOF;]], [[YYLexer (char lex_param1) {}]]) |
| 622 AT_CHECK_JAVA_GREP([[ *public YYParser (char lex_param1) {]]) |
| 623 AT_CHECK_JAVA_GREP([[.* = new YYLexer *(lex_param1);]]) |
| 624 |
| 625 AT_CHECK_JAVA_MINIMAL_W_LEXER([[ |
| 626 %lex-param {char lex_param1} |
| 627 %lex-param {short lex_param2}]], |
| 628 [], [[return EOF;]], [[YYLexer (char lex_param1, short lex_param2) {}]]) |
| 629 AT_CHECK_JAVA_GREP([[ *public YYParser (char lex_param1, *short lex_param2) {]]) |
| 630 AT_CHECK_JAVA_GREP([[.* = new YYLexer *(lex_param1, *lex_param2);]]) |
| 631 |
| 632 AT_CHECK_JAVA_MINIMAL_W_LEXER([[ |
| 633 %parse-param {int parse_param1} |
| 634 %parse-param {long parse_param2} |
| 635 %lex-param {char lex_param1} |
| 636 %lex-param {short lex_param2}]], |
| 637 [], [[return EOF;]], [[YYLexer (char lex_param1, short lex_param2) {}]]) |
| 638 AT_CHECK_JAVA_GREP([[ *protected final int parse_param1;]]) |
| 639 AT_CHECK_JAVA_GREP([[ *protected final long parse_param2;]]) |
| 640 AT_CHECK_JAVA_GREP([[ *public YYParser (char lex_param1, *short lex_param2, *int
parse_param1, *long parse_param2) {]]) |
| 641 AT_CHECK_JAVA_GREP([[.* = new YYLexer *(lex_param1, *lex_param2);]]) |
| 642 AT_CHECK_JAVA_GREP([[ *protected YYParser (Lexer yylexer, *int parse_param1, *lo
ng parse_param2) {]]) |
| 643 AT_CHECK_JAVA_GREP([[[ ]*this.parse_param1 = parse_param1;]], [2]) |
| 644 AT_CHECK_JAVA_GREP([[[ ]*this.parse_param2 = parse_param2;]], [2]) |
| 645 |
| 646 AT_CLEANUP |
| 647 |
| 648 |
| 649 # ------------------------- # |
| 650 # Java throw specifications # |
| 651 # ------------------------- # |
| 652 |
| 653 AT_SETUP([Java throws specifications]) |
| 654 |
| 655 # %define throws - 0 1 2 |
| 656 # %define lex-throws - 0 1 2 |
| 657 # %code lexer 0 1 |
| 658 |
| 659 m4_define([AT_JT_lex_throws_define], [m4_case(AT_JT_lex_throws, |
| 660 -1, [], |
| 661 0, [[%define lex_throws ""]], |
| 662 1, [[%define lex_throws "InterruptedException"]], |
| 663 2, [[%define lex_throws "InterruptedException, IllegalAccessException"]
])]) |
| 664 |
| 665 m4_define([AT_JT_yylex_throws], [m4_case(AT_JT_lex_throws, |
| 666 -1, [[ throws java.io.IOException]], |
| 667 0, [], |
| 668 1, [[ throws InterruptedException]], |
| 669 2, [[ throws InterruptedException, IllegalAccessException]])]) |
| 670 |
| 671 m4_define([AT_JT_yylex_action], [m4_case(AT_JT_lex_throws, |
| 672 -1, [[throw new java.io.IOException();]], |
| 673 0, [[return EOF;]], |
| 674 1, [[throw new InterruptedException();]], |
| 675 2, [[throw new IllegalAccessException();]])]) |
| 676 |
| 677 |
| 678 m4_define([AT_JT_throws_define], [m4_case(AT_JT_throws, |
| 679 -1, [], |
| 680 0, [[%define throws ""]], |
| 681 1, [[%define throws "ClassNotFoundException"]], |
| 682 2, [[%define throws "ClassNotFoundException, InstantiationException"]])
]) |
| 683 |
| 684 m4_define([AT_JT_yyaction_throws], [m4_case(AT_JT_throws, |
| 685 -1, [], |
| 686 0, [], |
| 687 1, [[ throws ClassNotFoundException]], |
| 688 2, [[ throws ClassNotFoundException, InstantiationException]])]) |
| 689 |
| 690 m4_define([AT_JT_parse_throws_2], [m4_case(AT_JT_throws, |
| 691 -1, [], |
| 692 0, [], |
| 693 1, [[, ClassNotFoundException]], |
| 694 2, [[, ClassNotFoundException, InstantiationException]])]) |
| 695 |
| 696 m4_define([AT_JT_parse_throws], |
| 697 [m4_if(m4_quote(AT_JT_yylex_throws), [], |
| 698 [AT_JT_yyaction_throws], |
| 699 [AT_JT_yylex_throws[]AT_JT_parse_throws_2])]) |
| 700 |
| 701 m4_define([AT_JT_initial_action], [m4_case(AT_JT_throws, |
| 702 -1, [], |
| 703 0, [], |
| 704 1, [[%initial-action {if (true) throw new ClassNotFoundException();}]], |
| 705 2, [[%initial-action {if (true) throw new InstantiationException();}]])
]) |
| 706 |
| 707 m4_define([AT_JT_parse_action], [m4_case(AT_JT_throws, |
| 708 -1, [], |
| 709 0, [], |
| 710 1, [[throw new ClassNotFoundException();]], |
| 711 2, [[throw new ClassNotFoundException();]])]) |
| 712 |
| 713 m4_for([AT_JT_lexer], 0, 1, 1, |
| 714 [m4_for([AT_JT_lex_throws], -1, 2, 1, |
| 715 [m4_for([AT_JT_throws], -1, 2, 1, |
| 716 [m4_if(AT_JT_lexer, 0, |
| 717 [AT_CHECK_JAVA_MINIMAL([ |
| 718 AT_JT_throws_define |
| 719 AT_JT_lex_throws_define |
| 720 AT_JT_initial_action], |
| 721 [AT_JT_parse_action])], |
| 722 [AT_CHECK_JAVA_MINIMAL_W_LEXER([ |
| 723 AT_JT_throws_define |
| 724 AT_JT_lex_throws_define |
| 725 AT_JT_initial_action], |
| 726 [AT_JT_yylex_throws], |
| 727 [AT_JT_yylex_action], |
| 728 [], |
| 729 [AT_JT_parse_action])]) |
| 730 AT_CHECK_JAVA_GREP([[ *int yylex ()]AT_JT_yylex_throws *[;]]) |
| 731 AT_CHECK_JAVA_GREP([[ *private int yyaction ([^)]*)]AT_JT_yyaction_throws[ *]]) |
| 732 AT_CHECK_JAVA_GREP([[ *public boolean parse ()]AT_JT_parse_throws[ *]]) |
| 733 ])])]) |
| 734 |
| 735 AT_CLEANUP |
| 736 |
| 737 |
| 738 # --------------------------------------------- # |
| 739 # Java stype, position_class and location_class # |
| 740 # --------------------------------------------- # |
| 741 |
| 742 AT_SETUP([Java stype, position_class and location_class]) |
| 743 |
| 744 AT_CHECK_JAVA_MINIMAL([[ |
| 745 %define stype "java.awt.Color" |
| 746 %type<java.awt.Color> start; |
| 747 %define location_type "MyLoc" |
| 748 %define position_type "MyPos" |
| 749 %code { class MyPos {} }]], [[$$ = $<java.awt.Color>1;]], [[MyPos]]) |
| 750 AT_CHECK([[grep -q 'java.awt.Color' YYParser.java]]) |
| 751 AT_CHECK([[egrep -v ' */?\*' YYParser.java | grep -q 'Position']], [1]) |
| 752 AT_CHECK([[egrep -v ' */?\*' YYParser.java | grep -q 'Location']], [1]) |
| 753 |
| 754 AT_CHECK_JAVA_MINIMAL_W_LEXER([[ |
| 755 %define stype "java.awt.Color" |
| 756 %type<java.awt.Color> start; |
| 757 %define location_type "MyLoc" |
| 758 %define position_type "MyPos" |
| 759 %code { class MyPos {} }]], [], [[return EOF;]], [], |
| 760 [[$$ = $<java.awt.Color>1;]], |
| 761 [[java.awt.Color]], [[MyPos]], [[MyLoc]]) |
| 762 AT_CHECK([[grep -q 'java.awt.Color' YYParser.java]]) |
| 763 AT_CHECK([[egrep -v ' */?\*' YYParser.java | grep -q 'Position']], [1]) |
| 764 AT_CHECK([[egrep -v ' */?\*' YYParser.java | grep -q 'Location']], [1]) |
| 765 |
| 766 AT_CLEANUP |
OLD | NEW |