1 # Java tests for simple calculator. -*- Autotest -*-
3 # Copyright (C) 2007-2012 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
36 [[/* Infix notation calculator--calc */
39 %define parser_class_name "Calc"
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;
52 /* Bison Declarations */
53 %token <Integer> NUM "number"
56 %nonassoc '=' /* comparison */
59 %left NEG /* negation--unary minus */
60 %right '^' /* exponentiation */
79 if ($1.intValue () != $3.intValue ())
80 yyerror (]AT_LOCATION_IF([[@$,]])[ "calc: error: " + $1 + " != " + $3);
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 (),
90 | '(' exp ')' { $$ = $2; }
91 | '(' error ')' { $$ = new Integer (1111); }
92 | '!' { $$ = new Integer (0); return YYERROR; }
93 | '-' error { $$ = new Integer (0); return YYERROR; }
101 class CalcLexer implements Calc.Lexer {
105 public ]AT_LEXPARAM_IF([[YYLexer]], [[CalcLexer]]) (InputStream is)
107 st = new StreamTokenizer (new InputStreamReader (is));
109 st.eolIsSignificant (true);
110 st.whitespaceChars (9, 9);
111 st.whitespaceChars (32, 32);
112 st.wordChars (48, 57);
116 Position yypos = new Position (1, 0);
118 public Position getStartPos() {
122 public Position getEndPos() {
126 public void yyerror (Calc.Location l, String s)
129 System.err.println (s);
131 System.err.println (l + ": " + s);
134 public void yyerror (String s)
136 System.err.println (s);
142 public Object getLVal() {
146 public int yylex () throws IOException {
147 int ttype = st.nextToken ();
148 ]AT_LOCATION_IF([[yypos = new Position (yypos.lineno (),
149 yypos.token () + 1);]])[
150 if (ttype == st.TT_EOF)
153 else if (ttype == st.TT_EOL)
155 ]AT_LOCATION_IF([[yypos = new Position (yypos.lineno () + 1, 0);]])[
159 else if (ttype == st.TT_WORD)
161 yylval = new Integer (st.sval);
186 public Position (int l, int t)
192 public boolean equals (Position l)
194 return l.line == line && l.token == token;
197 public String toString ()
199 return Integer.toString (line) + "." + Integer.toString(token);
214 ])# _AT_DATA_JAVA_CALC_Y
217 # AT_DATA_CALC_Y([BISON-OPTIONS])
218 # -------------------------------------------------
220 m4_define([AT_DATA_JAVA_CALC_Y],
221 [_AT_DATA_JAVA_CALC_Y($[1], $[2], $[3], [$1])
225 # _AT_CHECK_JAVA_CALC_ERROR(BISON-OPTIONS, INPUT,
226 # [VERBOSE-AND-LOCATED-ERROR-MESSAGE])
227 # ---------------------------------------------------------
228 # Run `calc' on INPUT, and expect a `syntax error' message.
230 # If INPUT starts with a slash, it is used as absolute input file name,
231 # otherwise as contents.
233 # The VERBOSE-AND-LOCATED-ERROR-MESSAGE is stripped of locations
234 # and expected tokens if necessary, and compared with the output.
235 m4_define([_AT_CHECK_JAVA_CALC_ERROR],
236 [m4_bmatch([$2], [^/],
237 [AT_JAVA_PARSER_CHECK([Calc < $2], 0, [], [stderr])],
241 AT_JAVA_PARSER_CHECK([Calc < input], 0, [], [stderr])])
243 # Normalize the observed and expected error messages, depending upon the
245 # 1. Create the reference error message.
249 # 2. If locations are not used, remove them.
250 AT_YYERROR_SEES_LOC_IF([],
251 [[sed 's/^[-0-9.]*: //' expout >at-expout
252 mv at-expout expout]])
253 # 3. If error-verbose is not used, strip the`, unexpected....' part.
254 m4_bmatch([$1], [%error-verbose], [],
255 [[sed 's/syntax error, .*$/syntax error/' expout >at-expout
256 mv at-expout expout]])
258 AT_CHECK([cat stderr], 0, [expout])
261 # _AT_CHECK_JAVA_CALC([BISON-DIRECTIVES], [BISON-CODE])
262 # -----------------------------------------------------------------------
263 # Start a testing chunk which compiles `calc' grammar with
264 # BISON-DIRECTIVES, and performs several tests over the parser.
265 m4_define([_AT_CHECK_JAVA_CALC],
266 [# We use integers to avoid dependencies upon the precision of doubles.
267 AT_SETUP([Calculator $1])
269 AT_BISON_OPTION_PUSHDEFS([$1])
271 AT_DATA_JAVA_CALC_Y([$1
276 AT_BISON_CHECK([-o Calc.java Calc.y])
277 AT_JAVA_COMPILE([Calc.java])
279 # Test the priorities.
295 AT_JAVA_PARSER_CHECK([Calc < input], 0, [], [stderr])
298 # Some syntax errors.
299 _AT_CHECK_JAVA_CALC_ERROR([$1], [0 0],
300 [1.2: syntax error, unexpected number])
301 _AT_CHECK_JAVA_CALC_ERROR([$1], [1//2],
302 [1.3: syntax error, unexpected '/', expecting number or '-' or '(' or '!'])
303 _AT_CHECK_JAVA_CALC_ERROR([$1], [error],
304 [1.1: syntax error, unexpected $undefined])
305 _AT_CHECK_JAVA_CALC_ERROR([$1], [1 = 2 = 3],
306 [1.4: syntax error, unexpected '='])
307 _AT_CHECK_JAVA_CALC_ERROR([$1], [
309 [2.1: syntax error, unexpected '+'])
310 # Exercise error messages with EOF: work on an empty file.
311 _AT_CHECK_JAVA_CALC_ERROR([$1], [/dev/null],
312 [1.1: syntax error, unexpected end of input])
314 # Exercise the error token: without it, we die at the first error,
317 # - have several errors which exercise different shift/discardings
318 # - (): nothing to pop, nothing to discard
319 # - (1 + 1 + 1 +): a lot to pop, nothing to discard
320 # - (* * *): nothing to pop, a lot to discard
321 # - (1 + 2 * *): some to pop and discard
323 # - test the action associated to `error'
325 # - check the lookahead that triggers an error is not discarded
326 # when we enter error recovery. Below, the lookahead causing the
327 # first error is ")", which is needed to recover from the error and
328 # produce the "0" that triggers the "0 != 1" error.
330 _AT_CHECK_JAVA_CALC_ERROR([$1],
331 [() + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1],
332 [1.2: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
333 1.11: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
334 1.14: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
335 1.24: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
336 1.1-1.27: calc: error: 4444 != 1])
338 # The same, but this time exercising explicitly triggered syntax errors.
339 # POSIX says the lookahead causing the error should not be discarded.
340 _AT_CHECK_JAVA_CALC_ERROR([$1], [(!) + (0 0) = 1],
341 [1.7: syntax error, unexpected number
342 1.1-1.10: calc: error: 2222 != 1])
343 _AT_CHECK_JAVA_CALC_ERROR([$1], [(- *) + (0 0) = 1],
344 [1.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
345 1.8: syntax error, unexpected number
346 1.1-1.11: calc: error: 2222 != 1])
347 AT_BISON_OPTION_POPDEFS
350 ])# _AT_CHECK_JAVA_CALC
353 # AT_CHECK_JAVA_CALC([BISON-DIRECTIVES])
354 # --------------------------------------------------------
355 # Start a testing chunk which compiles `calc' grammar with
356 # BISON-DIRECTIVES, and performs several tests over the parser.
357 # Run the test with and without %error-verbose.
358 m4_define([AT_CHECK_JAVA_CALC],
359 [_AT_CHECK_JAVA_CALC([$1], [$2])
360 _AT_CHECK_JAVA_CALC([%error-verbose $1], [$2])
361 _AT_CHECK_JAVA_CALC([%locations $1], [$2])
362 _AT_CHECK_JAVA_CALC([%error-verbose %locations $1], [$2])
363 ])# AT_CHECK_JAVA_CALC
366 # ------------------------ #
367 # Simple LALR Calculator. #
368 # ------------------------ #
370 AT_CHECK_JAVA_CALC([], [[
371 public static void main (String args[]) throws IOException
373 CalcLexer l = new CalcLexer (System.in);
374 Calc p = new Calc (l);
379 AT_CHECK_JAVA_CALC([%lex-param { InputStream is } ], [[
380 public static void main (String args[]) throws IOException
382 new Calc (System.in).parse ();
392 AT_BANNER([Java Parameters.])
395 # AT_CHECK_JAVA_MINIMAL([DIRECTIVES], [PARSER_ACTION], [POSITION_CLASS])
396 # ----------------------------------------------------------------------
397 # Check that a mininal parser with DIRECTIVES compiles in Java.
398 # Put the Java code in YYParser.java.
399 m4_define([AT_CHECK_JAVA_MINIMAL],
401 AT_DATA([[YYParser.y]], [
411 class m4_default([$3], [Position]) {}
413 AT_BISON_CHECK([[YYParser.y]])
414 AT_CHECK([[grep '[mb]4_' YYParser.y]], [1], [ignore])
415 AT_JAVA_COMPILE([[YYParser.java]])
419 # AT_CHECK_JAVA_MINIMAL_W_LEXER([1:DIRECTIVES], [2:LEX_THROWS],
420 # [3:YYLEX_ACTION], [4:LEXER_BODY], [5:PARSER_ACTION], [6:STYPE],
421 # [7:POSITION_TYPE], [8:LOCATION_TYPE])
422 # ---------------------------------------------------------------------
423 # Check that a mininal parser with DIRECTIVES and a "%code lexer".
424 # YYLEX is the body of yylex () which throws LEX_THROW.
426 m4_define([AT_CHECK_JAVA_MINIMAL_W_LEXER],
427 [AT_CHECK_JAVA_MINIMAL([$1
431 m4_default([$6], [Object]) yylval;
432 public m4_default([$6], [Object]) getLVal() { return yylval; }
434 public m4_default([$7], [Position]) getStartPos() { return null; }
435 public m4_default([$7], [Position]) getEndPos() { return null; }
437 public void yyerror (m4_default([$8], [Location]) loc, String s)
439 System.err.println (loc + ": " + s);
442 public int yylex ()$2
451 # AT_CHECK_JAVA_GREP([LINE], [COUNT=1])
452 # -------------------------------------
453 # Check that YYParser.java contains exactly COUNT lines matching ^LINE$
455 m4_define([AT_CHECK_JAVA_GREP],
456 [AT_CHECK([grep -c '^$1$' YYParser.java], [], [m4_default([$2], [1])
461 # ----------------------------------- #
462 # Java parser class and package names #
463 # ----------------------------------- #
465 AT_SETUP([Java parser class and package names])
467 AT_CHECK_JAVA_MINIMAL([])
468 AT_CHECK_JAVA_GREP([[class YYParser]])
470 AT_CHECK_JAVA_MINIMAL([[%name-prefix "Prefix"]])
471 AT_CHECK_JAVA_GREP([[class PrefixParser]])
473 AT_CHECK_JAVA_MINIMAL([[%define parser_class_name "ParserClassName"]])
474 AT_CHECK_JAVA_GREP([[class ParserClassName]])
476 AT_CHECK_JAVA_MINIMAL([[%define package "user_java_package"]])
477 AT_CHECK_JAVA_GREP([[package user_java_package;]])
482 # --------------------------- #
483 # Java parser class modifiers #
484 # --------------------------- #
486 AT_SETUP([Java parser class modifiers])
488 AT_CHECK_JAVA_MINIMAL([[%define abstract]])
489 AT_CHECK_JAVA_GREP([[abstract class YYParser]])
491 AT_CHECK_JAVA_MINIMAL([[%define final]])
492 AT_CHECK_JAVA_GREP([[final class YYParser]])
494 AT_CHECK_JAVA_MINIMAL([[%define strictfp]])
495 AT_CHECK_JAVA_GREP([[strictfp class YYParser]])
497 AT_CHECK_JAVA_MINIMAL([[
500 AT_CHECK_JAVA_GREP([[abstract strictfp class YYParser]])
502 AT_CHECK_JAVA_MINIMAL([[
505 AT_CHECK_JAVA_GREP([[final strictfp class YYParser]])
507 AT_CHECK_JAVA_MINIMAL([[%define public]])
508 AT_CHECK_JAVA_GREP([[public class YYParser]])
510 AT_CHECK_JAVA_MINIMAL([[
513 AT_CHECK_JAVA_GREP([[public abstract class YYParser]])
515 AT_CHECK_JAVA_MINIMAL([[
518 AT_CHECK_JAVA_GREP([[public final class YYParser]])
520 AT_CHECK_JAVA_MINIMAL([[
523 AT_CHECK_JAVA_GREP([[public strictfp class YYParser]])
525 AT_CHECK_JAVA_MINIMAL([[
529 AT_CHECK_JAVA_GREP([[public abstract strictfp class YYParser]])
531 AT_CHECK_JAVA_MINIMAL([[
535 AT_CHECK_JAVA_GREP([[public final strictfp class YYParser]])
540 # ---------------------------------------- #
541 # Java parser class extends and implements #
542 # ---------------------------------------- #
544 AT_SETUP([Java parser class extends and implements])
546 AT_CHECK_JAVA_MINIMAL([[%define extends "Thread"]])
547 AT_CHECK_JAVA_GREP([[class YYParser extends Thread]])
549 AT_CHECK_JAVA_MINIMAL([[%define implements "Cloneable"]])
550 AT_CHECK_JAVA_GREP([[class YYParser implements Cloneable]])
552 AT_CHECK_JAVA_MINIMAL([[
553 %define extends "Thread"
554 %define implements "Cloneable"]])
555 AT_CHECK_JAVA_GREP([[class YYParser extends Thread implements Cloneable]])
560 # -------------------------------- #
561 # Java %parse-param and %lex-param #
562 # -------------------------------- #
564 AT_SETUP([Java %parse-param and %lex-param])
566 AT_CHECK_JAVA_MINIMAL([])
567 AT_CHECK_JAVA_GREP([[ *public YYParser (Lexer yylexer) {]])
569 AT_CHECK_JAVA_MINIMAL([[%parse-param {int parse_param1}]])
570 AT_CHECK_JAVA_GREP([[ *protected final int parse_param1;]])
571 AT_CHECK_JAVA_GREP([[ *public YYParser (Lexer yylexer, *int parse_param1) {]])
572 AT_CHECK_JAVA_GREP([[[ ]*this.parse_param1 = parse_param1;]])
574 AT_CHECK_JAVA_MINIMAL([[
575 %parse-param {int parse_param1}
576 %parse-param {long parse_param2}]])
577 AT_CHECK_JAVA_GREP([[ *protected final int parse_param1;]])
578 AT_CHECK_JAVA_GREP([[ *protected final long parse_param2;]])
579 AT_CHECK_JAVA_GREP([[ *public YYParser (Lexer yylexer, *int parse_param1, *long parse_param2) {]])
580 AT_CHECK_JAVA_GREP([[[ ]*this.parse_param1 = parse_param1;]])
581 AT_CHECK_JAVA_GREP([[[ ]*this.parse_param2 = parse_param2;]])
583 AT_CHECK_JAVA_MINIMAL_W_LEXER([], [], [[return EOF;]])
584 AT_CHECK_JAVA_GREP([[ *public YYParser () {]])
585 AT_CHECK_JAVA_GREP([[ *protected YYParser (Lexer yylexer) {]])
587 AT_CHECK_JAVA_MINIMAL_W_LEXER([[%parse-param {int parse_param1}]],
589 AT_CHECK_JAVA_GREP([[ *protected final int parse_param1;]])
590 AT_CHECK_JAVA_GREP([[ *public YYParser (int parse_param1) {]])
591 AT_CHECK_JAVA_GREP([[ *protected YYParser (Lexer yylexer, *int parse_param1) {]])
592 AT_CHECK_JAVA_GREP([[[ ]*this.parse_param1 = parse_param1;]], [2])
594 AT_CHECK_JAVA_MINIMAL_W_LEXER([[
595 %parse-param {int parse_param1}
596 %parse-param {long parse_param2}]],
598 AT_CHECK_JAVA_GREP([[ *protected final int parse_param1;]])
599 AT_CHECK_JAVA_GREP([[ *protected final long parse_param2;]])
600 AT_CHECK_JAVA_GREP([[ *public YYParser (int parse_param1, *long parse_param2) {]])
601 AT_CHECK_JAVA_GREP([[ *protected YYParser (Lexer yylexer, *int parse_param1, *long parse_param2) {]])
602 AT_CHECK_JAVA_GREP([[[ ]*this.parse_param1 = parse_param1;]], [2])
603 AT_CHECK_JAVA_GREP([[[ ]*this.parse_param2 = parse_param2;]], [2])
605 AT_CHECK_JAVA_MINIMAL_W_LEXER([[%lex-param {char lex_param1}]],
606 [], [[return EOF;]], [[YYLexer (char lex_param1) {}]])
607 AT_CHECK_JAVA_GREP([[ *public YYParser (char lex_param1) {]])
608 AT_CHECK_JAVA_GREP([[.* = new YYLexer *(lex_param1);]])
610 AT_CHECK_JAVA_MINIMAL_W_LEXER([[
611 %lex-param {char lex_param1}
612 %lex-param {short lex_param2}]],
613 [], [[return EOF;]], [[YYLexer (char lex_param1, short lex_param2) {}]])
614 AT_CHECK_JAVA_GREP([[ *public YYParser (char lex_param1, *short lex_param2) {]])
615 AT_CHECK_JAVA_GREP([[.* = new YYLexer *(lex_param1, *lex_param2);]])
617 AT_CHECK_JAVA_MINIMAL_W_LEXER([[
618 %parse-param {int parse_param1}
619 %parse-param {long parse_param2}
620 %lex-param {char lex_param1}
621 %lex-param {short lex_param2}]],
622 [], [[return EOF;]], [[YYLexer (char lex_param1, short lex_param2) {}]])
623 AT_CHECK_JAVA_GREP([[ *protected final int parse_param1;]])
624 AT_CHECK_JAVA_GREP([[ *protected final long parse_param2;]])
625 AT_CHECK_JAVA_GREP([[ *public YYParser (char lex_param1, *short lex_param2, *int parse_param1, *long parse_param2) {]])
626 AT_CHECK_JAVA_GREP([[.* = new YYLexer *(lex_param1, *lex_param2);]])
627 AT_CHECK_JAVA_GREP([[ *protected YYParser (Lexer yylexer, *int parse_param1, *long parse_param2) {]])
628 AT_CHECK_JAVA_GREP([[[ ]*this.parse_param1 = parse_param1;]], [2])
629 AT_CHECK_JAVA_GREP([[[ ]*this.parse_param2 = parse_param2;]], [2])
634 # ------------------------- #
635 # Java throw specifications #
636 # ------------------------- #
638 AT_SETUP([Java throws specifications])
640 # %define throws - 0 1 2
641 # %define lex-throws - 0 1 2
644 m4_define([AT_JT_lex_throws_define], [m4_case(AT_JT_lex_throws,
646 0, [[%define lex_throws ""]],
647 1, [[%define lex_throws "InterruptedException"]],
648 2, [[%define lex_throws "InterruptedException, IllegalAccessException"]])])
650 m4_define([AT_JT_yylex_throws], [m4_case(AT_JT_lex_throws,
651 -1, [[ throws java.io.IOException]],
653 1, [[ throws InterruptedException]],
654 2, [[ throws InterruptedException, IllegalAccessException]])])
656 m4_define([AT_JT_yylex_action], [m4_case(AT_JT_lex_throws,
657 -1, [[throw new java.io.IOException();]],
659 1, [[throw new InterruptedException();]],
660 2, [[throw new IllegalAccessException();]])])
663 m4_define([AT_JT_throws_define], [m4_case(AT_JT_throws,
665 0, [[%define throws ""]],
666 1, [[%define throws "ClassNotFoundException"]],
667 2, [[%define throws "ClassNotFoundException, InstantiationException"]])])
669 m4_define([AT_JT_yyaction_throws], [m4_case(AT_JT_throws,
672 1, [[ throws ClassNotFoundException]],
673 2, [[ throws ClassNotFoundException, InstantiationException]])])
675 m4_define([AT_JT_parse_throws_2], [m4_case(AT_JT_throws,
678 1, [[, ClassNotFoundException]],
679 2, [[, ClassNotFoundException, InstantiationException]])])
681 m4_define([AT_JT_parse_throws],
682 [m4_if(m4_quote(AT_JT_yylex_throws), [],
683 [AT_JT_yyaction_throws],
684 [AT_JT_yylex_throws[]AT_JT_parse_throws_2])])
686 m4_define([AT_JT_initial_action], [m4_case(AT_JT_throws,
689 1, [[%initial-action {if (true) throw new ClassNotFoundException();}]],
690 2, [[%initial-action {if (true) throw new InstantiationException();}]])])
692 m4_define([AT_JT_parse_action], [m4_case(AT_JT_throws,
695 1, [[throw new ClassNotFoundException();]],
696 2, [[throw new ClassNotFoundException();]])])
698 m4_for([AT_JT_lexer], 0, 1, 1,
699 [m4_for([AT_JT_lex_throws], -1, 2, 1,
700 [m4_for([AT_JT_throws], -1, 2, 1,
701 [m4_if(AT_JT_lexer, 0,
702 [AT_CHECK_JAVA_MINIMAL([
704 AT_JT_lex_throws_define
705 AT_JT_initial_action],
706 [AT_JT_parse_action])],
707 [AT_CHECK_JAVA_MINIMAL_W_LEXER([
709 AT_JT_lex_throws_define
710 AT_JT_initial_action],
711 [AT_JT_yylex_throws],
712 [AT_JT_yylex_action],
714 [AT_JT_parse_action])])
715 AT_CHECK_JAVA_GREP([[ *int yylex ()]AT_JT_yylex_throws *[;]])
716 AT_CHECK_JAVA_GREP([[ *private int yyaction ([^)]*)]AT_JT_yyaction_throws[ *]])
717 AT_CHECK_JAVA_GREP([[ *public boolean parse ()]AT_JT_parse_throws[ *]])
723 # --------------------------------------------- #
724 # Java stype, position_class and location_class #
725 # --------------------------------------------- #
727 AT_SETUP([Java stype, position_class and location_class])
729 AT_CHECK_JAVA_MINIMAL([[
730 %define stype "java.awt.Color"
731 %type<java.awt.Color> start;
732 %define location_type "MyLoc"
733 %define position_type "MyPos"
734 %code { class MyPos {} }]], [[$$ = $<java.awt.Color>1;]], [[MyPos]])
735 AT_CHECK([[grep 'java.awt.Color' YYParser.java]], [0], [ignore])
736 AT_CHECK([[$EGREP -v ' */?\*' YYParser.java | grep 'Position']], [1], [ignore])
737 AT_CHECK([[$EGREP -v ' */?\*' YYParser.java | grep 'Location']], [1], [ignore])
739 AT_CHECK_JAVA_MINIMAL_W_LEXER([[
740 %define stype "java.awt.Color"
741 %type<java.awt.Color> start;
742 %define location_type "MyLoc"
743 %define position_type "MyPos"
744 %code { class MyPos {} }]], [], [[return EOF;]], [],
745 [[$$ = $<java.awt.Color>1;]],
746 [[java.awt.Color]], [[MyPos]], [[MyLoc]])
747 AT_CHECK([[grep 'java.awt.Color' YYParser.java]], [0], [ignore])
748 AT_CHECK([[$EGREP -v ' */?\*' YYParser.java | grep 'Position']], [1], [ignore])
749 AT_CHECK([[$EGREP -v ' */?\*' YYParser.java | grep 'Location']], [1], [ignore])
754 # ----------------------------------------------- #
755 # Java syntax error handling without error token. #
756 # ----------------------------------------------- #
758 AT_SETUP([Java syntax error handling without error token])
760 AT_DATA([[YYParser.y]], [[%language "Java"
762 %lex-param { String s }
765 import java.io.IOException;
772 public YYLexer (String s)
778 public void yyerror (String s)
780 System.err.println (s);
783 public Object getLVal ()
788 public int yylex () throws IOException
790 if (Position >= Input.length ())
793 return Input.charAt (Position++);
798 public static void main (String args []) throws IOException
800 YYParser p = new YYParser (args [0]);
809 AT_BISON_CHECK([[YYParser.y]])
810 AT_JAVA_COMPILE([[YYParser.java]])
811 AT_JAVA_PARSER_CHECK([[YYParser aa]], [[0]], [[]], [[]])
812 AT_JAVA_PARSER_CHECK([[YYParser ab]], [[0]], [[]], [[syntax error
814 AT_JAVA_PARSER_CHECK([[YYParser ba]], [[0]], [[]], [[syntax error