1 # Java tests for simple calculator. -*- Autotest -*-
3 # Copyright (C) 2007-2015 Free Software Foundation, Inc.
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.
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.
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/>.
18 AT_BANNER([[Java Calculator.]])
21 # ------------------------- #
22 # Helping Autotest macros. #
23 # ------------------------- #
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_BISON_OPTION_PUSHDEFS([%language "Java" $4])
37 [[/* Infix notation calculator--calc */
40 %define parser_class_name {Calc}
46 import java.io.StreamTokenizer;
47 import java.io.InputStream;
48 import java.io.InputStreamReader;
49 import java.io.Reader;
50 import java.io.IOException;
53 /* Bison Declarations */
54 %token <Integer> NUM "number"
57 %nonassoc '=' /* comparison */
60 %precedence NEG /* negation--unary minus */
61 %right '^' /* exponentiation */
80 if ($1.intValue () != $3.intValue ())
81 yyerror (]AT_LOCATION_IF([[@$,]])[ "calc: error: " + $1 + " != " + $3);
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 '/' exp { $$ = new Integer ($1.intValue () / $3.intValue ()); }
87 | '-' exp %prec NEG { $$ = new Integer (-$2.intValue ()); }
88 | exp '^' exp { $$ = new Integer ((int)
89 Math.pow ($1.intValue (),
91 | '(' exp ')' { $$ = $2; }
92 | '(' error ')' { $$ = new Integer (1111); }
93 | '!' { $$ = new Integer (0); return YYERROR; }
94 | '-' error { $$ = new Integer (0); return YYERROR; }
102 class CalcLexer implements Calc.Lexer {
106 public ]AT_LEXPARAM_IF([[YYLexer]], [[CalcLexer]]) (InputStream is)
108 st = new StreamTokenizer (new InputStreamReader (is));
110 st.eolIsSignificant (true);
111 st.whitespaceChars (9, 9);
112 st.whitespaceChars (32, 32);
113 st.wordChars (48, 57);
117 Position yypos = new Position (1, 0);
119 public Position getStartPos() {
123 public Position getEndPos() {
131 public Object getLVal() {
135 public int yylex () throws IOException {
136 int ttype = st.nextToken ();
137 ]AT_LOCATION_IF([[yypos = new Position (yypos.lineno (),
138 yypos.token () + 1);]])[
139 if (ttype == st.TT_EOF)
142 else if (ttype == st.TT_EOL)
144 ]AT_LOCATION_IF([[yypos = new Position (yypos.lineno () + 1, 0);]])[
148 else if (ttype == st.TT_WORD)
150 yylval = new Integer (st.sval);
175 public Position (int l, int t)
181 public boolean equals (Position l)
183 return l.line == line && l.token == token;
186 public String toString ()
188 return Integer.toString (line) + "." + Integer.toString(token);
203 AT_BISON_OPTION_POPDEFS
204 ])# _AT_DATA_JAVA_CALC_Y
207 # AT_DATA_CALC_Y([BISON-OPTIONS])
208 # -------------------------------
210 m4_define([AT_DATA_JAVA_CALC_Y],
211 [_AT_DATA_JAVA_CALC_Y($[1], $[2], $[3], [$1])
215 # _AT_CHECK_JAVA_CALC_ERROR(BISON-OPTIONS, INPUT,
216 # [VERBOSE-AND-LOCATED-ERROR-MESSAGE])
217 # --------------------------------------------------------------
218 # Run 'calc' on INPUT, and expect a 'syntax error' message.
220 # If INPUT starts with a slash, it is used as absolute input file name,
221 # otherwise as contents.
223 # The VERBOSE-AND-LOCATED-ERROR-MESSAGE is stripped of locations
224 # and expected tokens if necessary, and compared with the output.
225 m4_define([_AT_CHECK_JAVA_CALC_ERROR],
226 [m4_bmatch([$2], [^/],
227 [AT_JAVA_PARSER_CHECK([Calc < $2], 0, [], [stderr])],
231 AT_JAVA_PARSER_CHECK([Calc < input], 0, [], [stderr])])
233 # Normalize the observed and expected error messages, depending upon the
235 # 1. Create the reference error message.
239 # 2. If locations are not used, remove them.
240 AT_YYERROR_SEES_LOC_IF([],
241 [[sed 's/^[-0-9.]*: //' expout >at-expout
242 mv at-expout expout]])
243 # 3. If error-verbose is not used, strip the', unexpected....' part.
244 m4_bmatch([$1], [%error-verbose], [],
245 [[sed 's/syntax error, .*$/syntax error/' expout >at-expout
246 mv at-expout expout]])
248 AT_CHECK([cat stderr], 0, [expout])
251 # _AT_CHECK_JAVA_CALC([BISON-DIRECTIVES], [BISON-CODE])
252 # -----------------------------------------------------
253 # Start a testing chunk which compiles 'calc' grammar with
254 # BISON-DIRECTIVES, and performs several tests over the parser.
255 m4_define([_AT_CHECK_JAVA_CALC],
256 [# We use integers to avoid dependencies upon the precision of doubles.
257 AT_SETUP([Calculator $1])
259 AT_BISON_OPTION_PUSHDEFS([$1])
261 AT_DATA_JAVA_CALC_Y([$1
266 AT_BISON_CHECK([-o Calc.java Calc.y])
267 AT_JAVA_COMPILE([Calc.java])
269 # Test the priorities.
285 AT_JAVA_PARSER_CHECK([Calc < input], 0, [], [stderr])
288 # Some syntax errors.
289 _AT_CHECK_JAVA_CALC_ERROR([$1], [0 0],
290 [1.2: syntax error, unexpected number])
291 _AT_CHECK_JAVA_CALC_ERROR([$1], [1//2],
292 [1.3: syntax error, unexpected '/', expecting number or '-' or '(' or '!'])
293 _AT_CHECK_JAVA_CALC_ERROR([$1], [error],
294 [1.1: syntax error, unexpected $undefined])
295 _AT_CHECK_JAVA_CALC_ERROR([$1], [1 = 2 = 3],
296 [1.4: syntax error, unexpected '='])
297 _AT_CHECK_JAVA_CALC_ERROR([$1], [
299 [2.1: syntax error, unexpected '+'])
300 # Exercise error messages with EOF: work on an empty file.
301 _AT_CHECK_JAVA_CALC_ERROR([$1], [/dev/null],
302 [1.1: syntax error, unexpected end of input])
304 # Exercise the error token: without it, we die at the first error,
307 # - have several errors which exercise different shift/discardings
308 # - (): nothing to pop, nothing to discard
309 # - (1 + 1 + 1 +): a lot to pop, nothing to discard
310 # - (* * *): nothing to pop, a lot to discard
311 # - (1 + 2 * *): some to pop and discard
313 # - test the action associated to 'error'
315 # - check the lookahead that triggers an error is not discarded
316 # when we enter error recovery. Below, the lookahead causing the
317 # first error is ")", which is needed to recover from the error and
318 # produce the "0" that triggers the "0 != 1" error.
320 _AT_CHECK_JAVA_CALC_ERROR([$1],
321 [() + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1],
322 [1.2: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
323 1.11: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
324 1.14: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
325 1.24: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
326 1.1-1.27: calc: error: 4444 != 1])
328 # The same, but this time exercising explicitly triggered syntax errors.
329 # POSIX says the lookahead causing the error should not be discarded.
330 _AT_CHECK_JAVA_CALC_ERROR([$1], [(!) + (0 0) = 1],
331 [1.7: syntax error, unexpected number
332 1.1-1.10: calc: error: 2222 != 1])
333 _AT_CHECK_JAVA_CALC_ERROR([$1], [(- *) + (0 0) = 1],
334 [1.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
335 1.8: syntax error, unexpected number
336 1.1-1.11: calc: error: 2222 != 1])
337 AT_BISON_OPTION_POPDEFS
340 ])# _AT_CHECK_JAVA_CALC
343 # AT_CHECK_JAVA_CALC([BISON-DIRECTIVES])
344 # --------------------------------------
345 # Start a testing chunk which compiles 'calc' grammar with
346 # BISON-DIRECTIVES, and performs several tests over the parser.
347 # Run the test with and without %error-verbose.
348 m4_define([AT_CHECK_JAVA_CALC],
349 [_AT_CHECK_JAVA_CALC([$1], [$2])
350 _AT_CHECK_JAVA_CALC([%error-verbose $1], [$2])
351 _AT_CHECK_JAVA_CALC([%locations $1], [$2])
352 _AT_CHECK_JAVA_CALC([%error-verbose %locations $1], [$2])
353 ])# AT_CHECK_JAVA_CALC
356 # ------------------------ #
357 # Simple LALR Calculator. #
358 # ------------------------ #
360 AT_CHECK_JAVA_CALC([], [[
361 public static void main (String args[]) throws IOException
363 CalcLexer l = new CalcLexer (System.in);
364 Calc p = new Calc (l);
369 AT_CHECK_JAVA_CALC([%lex-param { InputStream is } ], [[
370 public static void main (String args[]) throws IOException
372 new Calc (System.in).parse ();
382 AT_BANNER([Java Parameters.])
385 # AT_CHECK_JAVA_MINIMAL([DIRECTIVES], [PARSER_ACTION], [POSITION_CLASS])
386 # ----------------------------------------------------------------------
387 # Check that a mininal parser with DIRECTIVES compiles in Java.
388 # Put the Java code in YYParser.java.
389 m4_define([AT_CHECK_JAVA_MINIMAL],
391 AT_DATA([[YYParser.y]], [
402 class m4_default([$3], [Position]) {}
404 AT_BISON_CHECK([[YYParser.y]])
405 AT_CHECK([[grep '[mb]4_' YYParser.y]], [1], [ignore])
406 AT_JAVA_COMPILE([[YYParser.java]])
410 # AT_CHECK_JAVA_MINIMAL_W_LEXER([1:DIRECTIVES], [2:LEX_THROWS],
411 # [3:YYLEX_ACTION], [4:LEXER_BODY], [5:PARSER_ACTION], [6:VALUE_TYPE],
412 # [7:POSITION_TYPE], [8:LOCATION_TYPE])
413 # ---------------------------------------------------------------------
414 # Check that a mininal parser with DIRECTIVES and a "%code lexer".
415 # YYLEX is the body of yylex () which throws LEX_THROW.
417 m4_define([AT_CHECK_JAVA_MINIMAL_W_LEXER],
418 [AT_CHECK_JAVA_MINIMAL([$1
422 m4_default([$6], [Object]) yylval;
423 public m4_default([$6], [Object]) getLVal() { return yylval; }
425 public m4_default([$7], [Position]) getStartPos() { return null; }
426 public m4_default([$7], [Position]) getEndPos() { return null; }
428 public void yyerror (m4_default([$8], [Location]) loc, String s)
430 System.err.println (loc + ": " + s);
433 public int yylex ()$2
442 # AT_CHECK_JAVA_GREP([LINE], [COUNT=1])
443 # -------------------------------------
444 # Check that YYParser.java contains exactly COUNT lines matching ^LINE$
446 m4_define([AT_CHECK_JAVA_GREP],
447 [AT_CHECK([grep -c '^$1$' YYParser.java], [ignore], [m4_default([$2], [1])
451 # ------------------------------------- #
452 # Java parser class and package names. #
453 # ------------------------------------- #
455 AT_SETUP([Java parser class and package names])
457 AT_CHECK_JAVA_MINIMAL([])
458 AT_CHECK_JAVA_GREP([[class YYParser]])
460 AT_CHECK_JAVA_MINIMAL([[%name-prefix "Prefix"]])
461 AT_CHECK_JAVA_GREP([[class PrefixParser]])
463 AT_CHECK_JAVA_MINIMAL([[%define api.token.prefix {TOK_}]])
464 AT_CHECK_JAVA_GREP([[.*TOK_END.*]])
466 AT_CHECK_JAVA_MINIMAL([[%define parser_class_name {ParserClassName}]])
467 AT_CHECK_JAVA_GREP([[class ParserClassName]])
469 AT_CHECK_JAVA_MINIMAL([[%define package {user_java_package}]])
470 AT_CHECK_JAVA_GREP([[package user_java_package;]])
475 # ----------------------------- #
476 # Java parser class modifiers. #
477 # ----------------------------- #
479 AT_SETUP([Java parser class modifiers])
481 AT_CHECK_JAVA_MINIMAL([[%define abstract]])
482 AT_CHECK_JAVA_GREP([[abstract class YYParser]])
484 AT_CHECK_JAVA_MINIMAL([[%define final]])
485 AT_CHECK_JAVA_GREP([[final class YYParser]])
487 AT_CHECK_JAVA_MINIMAL([[%define strictfp]])
488 AT_CHECK_JAVA_GREP([[strictfp class YYParser]])
490 AT_CHECK_JAVA_MINIMAL([[
493 AT_CHECK_JAVA_GREP([[abstract strictfp class YYParser]])
495 AT_CHECK_JAVA_MINIMAL([[
498 AT_CHECK_JAVA_GREP([[final strictfp class YYParser]])
500 AT_CHECK_JAVA_MINIMAL([[%define public]])
501 AT_CHECK_JAVA_GREP([[public class YYParser]])
503 AT_CHECK_JAVA_MINIMAL([[
506 AT_CHECK_JAVA_GREP([[public abstract class YYParser]])
508 AT_CHECK_JAVA_MINIMAL([[
511 AT_CHECK_JAVA_GREP([[public final class YYParser]])
513 AT_CHECK_JAVA_MINIMAL([[
516 AT_CHECK_JAVA_GREP([[public strictfp class YYParser]])
518 AT_CHECK_JAVA_MINIMAL([[
522 AT_CHECK_JAVA_GREP([[public abstract strictfp class YYParser]])
524 AT_CHECK_JAVA_MINIMAL([[
528 AT_CHECK_JAVA_GREP([[public final strictfp class YYParser]])
530 # FIXME: Can't do a Java compile because javacomp.sh is configured for 1.3
531 AT_CHECK_JAVA_MINIMAL([[
532 %define annotations {/*@Deprecated @SupressWarnings("unchecked") @SupressWarnings({"unchecked", "deprecation"}) @SupressWarnings(value={"unchecked", "deprecation"})*/}
534 AT_CHECK_JAVA_GREP([[/\*@Deprecated @SupressWarnings("unchecked") @SupressWarnings({"unchecked", "deprecation"}) @SupressWarnings(value={"unchecked", "deprecation"})\*/ public class YYParser]])
539 # ---------------------------------------- #
540 # Java parser class extends and implements #
541 # ---------------------------------------- #
543 AT_SETUP([Java parser class extends and implements])
545 AT_CHECK_JAVA_MINIMAL([[%define extends {Thread}]])
546 AT_CHECK_JAVA_GREP([[class YYParser extends Thread]])
548 AT_CHECK_JAVA_MINIMAL([[%define implements {Cloneable}]])
549 AT_CHECK_JAVA_GREP([[class YYParser implements Cloneable]])
551 AT_CHECK_JAVA_MINIMAL([[
552 %define extends {Thread}
553 %define implements {Cloneable}]])
554 AT_CHECK_JAVA_GREP([[class YYParser extends Thread implements Cloneable]])
559 # -------------------------------- #
560 # Java %parse-param and %lex-param #
561 # -------------------------------- #
563 AT_SETUP([Java %parse-param and %lex-param])
565 AT_CHECK_JAVA_MINIMAL([])
566 AT_CHECK_JAVA_GREP([[ *public YYParser (Lexer yylexer) *]])
568 AT_CHECK_JAVA_MINIMAL([[%parse-param {int parse_param1}]])
569 AT_CHECK_JAVA_GREP([[ *protected final int parse_param1;]])
570 AT_CHECK_JAVA_GREP([[ *public YYParser (Lexer yylexer, *int parse_param1) *]])
571 AT_CHECK_JAVA_GREP([[ *this.parse_param1 = parse_param1;]])
573 AT_CHECK_JAVA_MINIMAL([[
574 %parse-param {int parse_param1}
575 %parse-param {long parse_param2}]])
576 AT_CHECK_JAVA_GREP([[ *protected final int parse_param1;]])
577 AT_CHECK_JAVA_GREP([[ *protected final long parse_param2;]])
578 AT_CHECK_JAVA_GREP([[ *public YYParser (Lexer yylexer, *int parse_param1, *long parse_param2) *]])
579 AT_CHECK_JAVA_GREP([[ *this.parse_param1 = parse_param1;]])
580 AT_CHECK_JAVA_GREP([[ *this.parse_param2 = parse_param2;]])
582 AT_CHECK_JAVA_MINIMAL_W_LEXER([], [], [[return EOF;]])
583 AT_CHECK_JAVA_GREP([[ *public YYParser () *]])
584 AT_CHECK_JAVA_GREP([[ *protected YYParser (Lexer yylexer) *]])
586 AT_CHECK_JAVA_MINIMAL_W_LEXER([[%parse-param {int parse_param1}]],
588 AT_CHECK_JAVA_GREP([[ *protected final int parse_param1;]])
589 AT_CHECK_JAVA_GREP([[ *public YYParser (int parse_param1) *]])
590 AT_CHECK_JAVA_GREP([[ *protected YYParser (Lexer yylexer, *int parse_param1) *]])
591 AT_CHECK_JAVA_GREP([[ *this.parse_param1 = parse_param1;]], [2])
593 AT_CHECK_JAVA_MINIMAL_W_LEXER([[
594 %parse-param {int parse_param1}
595 %parse-param {long parse_param2}]],
597 AT_CHECK_JAVA_GREP([[ *protected final int parse_param1;]])
598 AT_CHECK_JAVA_GREP([[ *protected final long parse_param2;]])
599 AT_CHECK_JAVA_GREP([[ *public YYParser (int parse_param1, *long parse_param2) *]])
600 AT_CHECK_JAVA_GREP([[ *protected YYParser (Lexer yylexer, *int parse_param1, *long parse_param2) *]])
601 AT_CHECK_JAVA_GREP([[ *this.parse_param1 = parse_param1;]], [2])
602 AT_CHECK_JAVA_GREP([[ *this.parse_param2 = parse_param2;]], [2])
604 AT_CHECK_JAVA_MINIMAL_W_LEXER([[%lex-param {char lex_param1}]],
605 [], [[return EOF;]], [[YYLexer (char lex_param1) {}]])
606 AT_CHECK_JAVA_GREP([[ *public YYParser (char lex_param1) *]])
607 AT_CHECK_JAVA_GREP([[.* = new YYLexer *(lex_param1);]])
609 AT_CHECK_JAVA_MINIMAL_W_LEXER([[
610 %lex-param {char lex_param1}
611 %lex-param {short lex_param2}]],
612 [], [[return EOF;]], [[YYLexer (char lex_param1, short lex_param2) {}]])
613 AT_CHECK_JAVA_GREP([[ *public YYParser (char lex_param1, *short lex_param2) *]])
614 AT_CHECK_JAVA_GREP([[.* = new YYLexer *(lex_param1, *lex_param2);]])
616 AT_CHECK_JAVA_MINIMAL_W_LEXER([[
617 %parse-param {int parse_param1}
618 %parse-param {long parse_param2}
619 %lex-param {char lex_param1}
620 %lex-param {short lex_param2}]],
621 [], [[return EOF;]], [[YYLexer (char lex_param1, short lex_param2) {}]])
622 AT_CHECK_JAVA_GREP([[ *protected final int parse_param1;]])
623 AT_CHECK_JAVA_GREP([[ *protected final long parse_param2;]])
624 AT_CHECK_JAVA_GREP([[ *public YYParser (char lex_param1, *short lex_param2, *int parse_param1, *long parse_param2) *]])
625 AT_CHECK_JAVA_GREP([[.* = new YYLexer *(lex_param1, *lex_param2);]])
626 AT_CHECK_JAVA_GREP([[ *protected YYParser (Lexer yylexer, *int parse_param1, *long parse_param2) *]])
627 AT_CHECK_JAVA_GREP([[ *this.parse_param1 = parse_param1;]], [2])
628 AT_CHECK_JAVA_GREP([[ *this.parse_param2 = parse_param2;]], [2])
633 # ------------------------- #
634 # Java throw specifications #
635 # ------------------------- #
637 AT_SETUP([Java throws specifications])
639 # %define throws - 0 1 2
640 # %define lex-throws - 0 1 2
643 m4_define([AT_JT_lex_throws_define], [m4_case(AT_JT_lex_throws,
645 0, [[%define lex_throws {}]],
646 1, [[%define lex_throws {InterruptedException}]],
647 2, [[%define lex_throws {InterruptedException, IllegalAccessException}]])])
649 m4_define([AT_JT_yylex_throws], [m4_case(AT_JT_lex_throws,
650 -1, [[ throws java.io.IOException]],
652 1, [[ throws InterruptedException]],
653 2, [[ throws InterruptedException, IllegalAccessException]])])
655 m4_define([AT_JT_yylex_action], [m4_case(AT_JT_lex_throws,
656 -1, [[throw new java.io.IOException();]],
658 1, [[throw new InterruptedException();]],
659 2, [[throw new IllegalAccessException();]])])
662 m4_define([AT_JT_throws_define], [m4_case(AT_JT_throws,
664 0, [[%define throws {}]],
665 1, [[%define throws {ClassNotFoundException}]],
666 2, [[%define throws {ClassNotFoundException, InstantiationException}]])])
668 m4_define([AT_JT_yyaction_throws], [m4_case(AT_JT_throws,
671 1, [[ throws ClassNotFoundException]],
672 2, [[ throws ClassNotFoundException, InstantiationException]])])
674 m4_define([AT_JT_parse_throws_2], [m4_case(AT_JT_throws,
677 1, [[, ClassNotFoundException]],
678 2, [[, ClassNotFoundException, InstantiationException]])])
680 m4_define([AT_JT_parse_throws],
681 [m4_if(m4_quote(AT_JT_yylex_throws), [],
682 [AT_JT_yyaction_throws],
683 [AT_JT_yylex_throws[]AT_JT_parse_throws_2])])
685 m4_define([AT_JT_initial_action], [m4_case(AT_JT_throws,
688 1, [[%initial-action {if (true) throw new ClassNotFoundException();}]],
689 2, [[%initial-action {if (true) throw new InstantiationException();}]])])
691 m4_define([AT_JT_parse_action], [m4_case(AT_JT_throws,
694 1, [[throw new ClassNotFoundException();]],
695 2, [[throw new ClassNotFoundException();]])])
697 m4_for([AT_JT_lexer], 0, 1, 1,
698 [m4_for([AT_JT_lex_throws], -1, 2, 1,
699 [m4_for([AT_JT_throws], -1, 2, 1,
700 [m4_if(AT_JT_lexer, 0,
701 [AT_CHECK_JAVA_MINIMAL([
703 AT_JT_lex_throws_define
704 AT_JT_initial_action],
705 [AT_JT_parse_action])],
706 [AT_CHECK_JAVA_MINIMAL_W_LEXER([
708 AT_JT_lex_throws_define
709 AT_JT_initial_action],
710 [AT_JT_yylex_throws],
711 [AT_JT_yylex_action],
713 [AT_JT_parse_action])])
714 AT_CHECK_JAVA_GREP([[ *int yylex ()]AT_JT_yylex_throws *[;]])
715 AT_CHECK_JAVA_GREP([[ *private int yyaction ([^)]*)]AT_JT_yyaction_throws[ *]])
716 AT_CHECK_JAVA_GREP([[ *public boolean parse ()]AT_JT_parse_throws[ *]])
722 # ------------------------------------- #
723 # Java constructor init and init_throws #
724 # ------------------------------------- #
726 AT_SETUP([Java constructor init and init_throws])
728 m4_pushdef([AT_Witness],
729 [super("Test Thread"); if (true) throw new InterruptedException();])
731 AT_CHECK_JAVA_MINIMAL([[
732 %define extends {Thread}
733 %code init { ]AT_Witness[ }
734 %define init_throws {InterruptedException}
735 %lex-param {int lex_param}]])
736 AT_CHECK([[grep ']AT_Witness[' YYParser.java]], 0, [ignore])
738 AT_CHECK_JAVA_MINIMAL_W_LEXER([[
739 %define extends {Thread}
740 %code init { ]AT_Witness[ }
741 %define init_throws {InterruptedException}]], [], [[return EOF;]])
742 AT_CHECK([[grep ']AT_Witness[' YYParser.java]], 0, [ignore])
744 m4_popdef([AT_Witness])
749 # ------------------------------------------ #
750 # Java value, position, and location types. #
751 # ------------------------------------------ #
753 AT_SETUP([Java value, position, and location types])
755 AT_CHECK_JAVA_MINIMAL([[
756 %define api.value.type {java.awt.Color}
757 %type<java.awt.Color> start;
758 %define api.location.type {MyLoc}
759 %define api.position.type {MyPos}
760 %code { class MyPos {} }]], [[$$ = $<java.awt.Color>1;]], [[MyPos]])
761 AT_CHECK([[grep 'java.awt.Color' YYParser.java]], [0], [ignore])
762 AT_CHECK([[$EGREP -v ' */?\*' YYParser.java | grep 'Position']], [1], [ignore])
763 AT_CHECK([[$EGREP -v ' */?\*' YYParser.java | grep 'Location']], [1], [ignore])
765 AT_CHECK_JAVA_MINIMAL_W_LEXER([[
766 %define api.value.type {java.awt.Color}
767 %type<java.awt.Color> start;
768 %define api.location.type {MyLoc}
769 %define api.position.type {MyPos}
770 %code { class MyPos {} }]], [], [[return EOF;]], [],
771 [[$$ = $<java.awt.Color>1;]],
772 [[java.awt.Color]], [[MyPos]], [[MyLoc]])
773 AT_CHECK([[grep 'java.awt.Color' YYParser.java]], [0], [ignore])
774 AT_CHECK([[$EGREP -v ' */?\*' YYParser.java | grep 'Position']], [1], [ignore])
775 AT_CHECK([[$EGREP -v ' */?\*' YYParser.java | grep 'Location']], [1], [ignore])
780 # ----------------------------------------------- #
781 # Java syntax error handling without error token. #
782 # ----------------------------------------------- #
784 AT_SETUP([Java syntax error handling without error token])
786 AT_DATA([[YYParser.y]], [[%language "Java"
788 %lex-param { String s }
791 import java.io.IOException;
798 public YYLexer (String s)
804 public void yyerror (String s)
806 System.err.println (s);
809 public Object getLVal ()
814 public int yylex () throws IOException
816 if (Position >= Input.length ())
819 return Input.charAt (Position++);
824 public static void main (String args []) throws IOException
826 YYParser p = new YYParser (args [0]);
835 AT_BISON_CHECK([[YYParser.y]])
836 AT_JAVA_COMPILE([[YYParser.java]])
837 AT_JAVA_PARSER_CHECK([[YYParser aa]], [[0]], [[]], [[]])
838 AT_JAVA_PARSER_CHECK([[YYParser ab]], [[0]], [[]], [[syntax error
840 AT_JAVA_PARSER_CHECK([[YYParser ba]], [[0]], [[]], [[syntax error