]> git.saurik.com Git - bison.git/blob - tests/java.at
Fix regeneration of atconfig.
[bison.git] / tests / java.at
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 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 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_KEYWORDS(java)
229 AT_CHECK([test -n "$CONF_JAVA" || exit 77
230 test -n "$CONF_JAVAC" || exit 77])
231 AT_CHECK([$SHELL ../../../javacomp.sh $1],
232 0, [ignore], [ignore])])
233
234
235 # AT_JAVA_PARSER_CHECK(COMMAND, EXIT-STATUS, EXPOUT, EXPERR, [PRE])
236 # -----------------------------------------------------------------
237 m4_define([AT_JAVA_PARSER_CHECK],
238 [AT_CHECK([$5 $SHELL ../../../javaexec.sh $1], [$2], [$3], [$4])])
239
240
241 # _AT_CHECK_JAVA_CALC_ERROR(BISON-OPTIONS, INPUT,
242 # [VERBOSE-AND-LOCATED-ERROR-MESSAGE])
243 # ---------------------------------------------------------
244 # Run `calc' on INPUT, and expect a `syntax error' message.
245 #
246 # If INPUT starts with a slash, it is used as absolute input file name,
247 # otherwise as contents.
248 #
249 # The VERBOSE-AND-LOCATED-ERROR-MESSAGE is stripped of locations
250 # and expected tokens if necessary, and compared with the output.
251 m4_define([_AT_CHECK_JAVA_CALC_ERROR],
252 [m4_bmatch([$2], [^/],
253 [AT_JAVA_PARSER_CHECK([Calc < $2], 0, [], [stderr])],
254 [AT_DATA([[input]],
255 [[$2
256 ]])
257 AT_JAVA_PARSER_CHECK([Calc < input], 0, [], [stderr])])
258
259 # Normalize the observed and expected error messages, depending upon the
260 # options.
261 # 1. Create the reference error message.
262 AT_DATA([[expout]],
263 [$3
264 ])
265 # 2. If locations are not used, remove them.
266 AT_YYERROR_SEES_LOC_IF([],
267 [[sed 's/^[-0-9.]*: //' expout >at-expout
268 mv at-expout expout]])
269 # 3. If error-verbose is not used, strip the`, unexpected....' part.
270 m4_bmatch([$1], [%error-verbose], [],
271 [[sed 's/syntax error, .*$/syntax error/' expout >at-expout
272 mv at-expout expout]])
273 # 4. Check
274 AT_CHECK([cat stderr], 0, [expout])
275 ])
276
277 # _AT_CHECK_JAVA_CALC([BISON-DIRECTIVES], [BISON-CODE])
278 # -----------------------------------------------------------------------
279 # Start a testing chunk which compiles `calc' grammar with
280 # BISON-DIRECTIVES, and performs several tests over the parser.
281 m4_define([_AT_CHECK_JAVA_CALC],
282 [# We use integers to avoid dependencies upon the precision of doubles.
283 AT_SETUP([Calculator $1])
284
285 AT_BISON_OPTION_PUSHDEFS([$1])
286
287 AT_DATA_JAVA_CALC_Y([$1
288 %code {
289 $2
290 }])
291
292 AT_BISON_CHECK([-o Calc.java Calc.y])
293 AT_JAVA_COMPILE([Calc.java])
294
295 # Test the priorities.
296 AT_DATA([[input]],
297 [[1 + 2 * 3 = 7
298 1 + 2 * -3 = -5
299
300 -1^2 = -1
301 (-1)^2 = 1
302
303 ---1 = -1
304
305 1 - 2 - 3 = -4
306 1 - (2 - 3) = 2
307
308 2^2^3 = 256
309 (2^2)^3 = 64
310 ]])
311 AT_JAVA_PARSER_CHECK([Calc < input], 0, [], [stderr])
312
313
314 # Some syntax errors.
315 _AT_CHECK_JAVA_CALC_ERROR([$1], [0 0],
316 [1: syntax error, unexpected number])
317 _AT_CHECK_JAVA_CALC_ERROR([$1], [1//2],
318 [1: syntax error, unexpected '/', expecting number or '-' or '(' or '!'])
319 _AT_CHECK_JAVA_CALC_ERROR([$1], [error],
320 [1: syntax error, unexpected $undefined])
321 _AT_CHECK_JAVA_CALC_ERROR([$1], [1 = 2 = 3],
322 [1: syntax error, unexpected '='])
323 _AT_CHECK_JAVA_CALC_ERROR([$1], [
324 +1],
325 [2: syntax error, unexpected '+'])
326 # Exercise error messages with EOF: work on an empty file.
327 _AT_CHECK_JAVA_CALC_ERROR([$1], [/dev/null],
328 [1: syntax error, unexpected end of input])
329
330 # Exercise the error token: without it, we die at the first error,
331 # hence be sure to
332 #
333 # - have several errors which exercise different shift/discardings
334 # - (): nothing to pop, nothing to discard
335 # - (1 + 1 + 1 +): a lot to pop, nothing to discard
336 # - (* * *): nothing to pop, a lot to discard
337 # - (1 + 2 * *): some to pop and discard
338 #
339 # - test the action associated to `error'
340 #
341 # - check the lookahead that triggers an error is not discarded
342 # when we enter error recovery. Below, the lookahead causing the
343 # first error is ")", which is needed to recover from the error and
344 # produce the "0" that triggers the "0 != 1" error.
345 #
346 _AT_CHECK_JAVA_CALC_ERROR([$1],
347 [() + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1],
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 1: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
352 calc: error: 4444 != 1])
353
354 # The same, but this time exercising explicitly triggered syntax errors.
355 # POSIX says the lookahead causing the error should not be discarded.
356 _AT_CHECK_JAVA_CALC_ERROR([$1], [(!) + (0 0) = 1],
357 [1: syntax error, unexpected number
358 calc: error: 2222 != 1])
359 _AT_CHECK_JAVA_CALC_ERROR([$1], [(- *) + (0 0) = 1],
360 [1: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
361 1: syntax error, unexpected number
362 calc: error: 2222 != 1])
363 AT_BISON_OPTION_POPDEFS
364
365 AT_CLEANUP
366 ])# _AT_CHECK_JAVA_CALC
367
368
369 # AT_CHECK_JAVA_CALC([BISON-DIRECTIVES])
370 # --------------------------------------------------------
371 # Start a testing chunk which compiles `calc' grammar with
372 # BISON-DIRECTIVES, and performs several tests over the parser.
373 # Run the test with and without %error-verbose.
374 m4_define([AT_CHECK_JAVA_CALC],
375 [_AT_CHECK_JAVA_CALC([$1], [$2])
376 _AT_CHECK_JAVA_CALC([%error-verbose $1], [$2])
377 _AT_CHECK_JAVA_CALC([%locations $1], [$2])
378 _AT_CHECK_JAVA_CALC([%error-verbose %locations $1], [$2])
379 ])# AT_CHECK_JAVA_CALC
380
381
382 # ------------------------ #
383 # Simple LALR Calculator. #
384 # ------------------------ #
385
386 AT_CHECK_JAVA_CALC([], [[
387 public static void main (String args[]) throws IOException
388 {
389 CalcLexer l = new CalcLexer (System.in);
390 Calc p = new Calc (l);
391 p.parse ();
392 }
393 ]])
394
395 AT_CHECK_JAVA_CALC([%lex-param { InputStream is } ], [[
396 public static void main (String args[]) throws IOException
397 {
398 new Calc (System.in).parse ();
399 }
400 ]])
401
402
403
404 # -----------------#
405 # Java Directives. #
406 # -----------------#
407
408 AT_BANNER([Java Parameters.])
409
410
411 # AT_CHECK_JAVA_MINIMAL([DIRECTIVES], [PARSER_ACTION], [POSITION_CLASS])
412 # ----------------------------------------------------------------------
413 # Check that a mininal parser with DIRECTIVES compiles in Java.
414 # Put the Java code in YYParser.java.
415 m4_define([AT_CHECK_JAVA_MINIMAL],
416 [
417 AT_DATA([[YYParser.y]], [
418 %language "Java"
419 %locations
420 %debug
421 %error-verbose
422 %token-table
423 $1
424 %%
425 start: "end" {$2};
426 %%
427 class m4_default([$3], [Position]) {}
428 ])
429 AT_BISON_CHECK([[YYParser.y]])
430 AT_CHECK([[grep -q '[mb]4_' YYParser.y]], [1])
431 AT_JAVA_COMPILE([[YYParser.java]])
432 ])
433
434
435 # AT_CHECK_JAVA_MINIMAL_W_LEXER([1:DIRECTIVES], [2:LEX_THROWS],
436 # [3:YYLEX_ACTION], [4:LEXER_BODY], [5:PARSER_ACTION], [6:STYPE],
437 # [7:POSITION_TYPE], [8:LOCATION_TYPE])
438 # ---------------------------------------------------------------------
439 # Check that a mininal parser with DIRECTIVES and a "%code lexer".
440 # YYLEX is the body of yylex () which throws LEX_THROW.
441 # compiles in Java.
442 m4_define([AT_CHECK_JAVA_MINIMAL_W_LEXER],
443 [AT_CHECK_JAVA_MINIMAL([$1
444
445 %code lexer
446 {
447 m4_default([$6], [Object]) yylval;
448 public m4_default([$6], [Object]) getLVal() { return yylval; }
449
450 public m4_default([$7], [Position]) getStartPos() { return null; }
451 public m4_default([$7], [Position]) getEndPos() { return null; }
452
453 public void yyerror (m4_default([$8], [Location]) loc, String s)
454 {
455 System.err.println (loc + ": " + s);
456 }
457
458 public int yylex ()$2
459 {
460 $3
461 }
462
463 $4
464 }], [$5], [$7])])
465
466
467 # AT_CHECK_JAVA_GREP([LINE], [COUNT=1])
468 # -------------------------------------
469 # Check that YYParser.java contains exactly COUNT lines matching ^LINE$
470 # with grep.
471 m4_define([AT_CHECK_JAVA_GREP],
472 [AT_CHECK([grep -c '^$1$' YYParser.java], [], [m4_default([$2], [1])
473 ])
474 ])
475
476
477 # ----------------------------------- #
478 # Java parser class and package names #
479 # ----------------------------------- #
480
481 AT_SETUP([Java parser class and package names])
482
483 AT_CHECK_JAVA_MINIMAL([])
484 AT_CHECK_JAVA_GREP([[class YYParser]])
485
486 AT_CHECK_JAVA_MINIMAL([[%name-prefix "Prefix"]])
487 AT_CHECK_JAVA_GREP([[class PrefixParser]])
488
489 AT_CHECK_JAVA_MINIMAL([[%define parser_class_name "ParserClassName"]])
490 AT_CHECK_JAVA_GREP([[class ParserClassName]])
491
492 AT_CHECK_JAVA_MINIMAL([[%define package "user_java_package"]])
493 AT_CHECK_JAVA_GREP([[package user_java_package;]])
494
495 AT_CLEANUP
496
497
498 # --------------------------- #
499 # Java parser class modifiers #
500 # --------------------------- #
501
502 AT_SETUP([Java parser class modifiers])
503
504 AT_CHECK_JAVA_MINIMAL([[%define abstract]])
505 AT_CHECK_JAVA_GREP([[abstract class YYParser]])
506
507 AT_CHECK_JAVA_MINIMAL([[%define final]])
508 AT_CHECK_JAVA_GREP([[final class YYParser]])
509
510 AT_CHECK_JAVA_MINIMAL([[%define strictfp]])
511 AT_CHECK_JAVA_GREP([[strictfp class YYParser]])
512
513 AT_CHECK_JAVA_MINIMAL([[
514 %define abstract
515 %define strictfp]])
516 AT_CHECK_JAVA_GREP([[abstract strictfp class YYParser]])
517
518 AT_CHECK_JAVA_MINIMAL([[
519 %define final
520 %define strictfp]])
521 AT_CHECK_JAVA_GREP([[final strictfp class YYParser]])
522
523 AT_CHECK_JAVA_MINIMAL([[%define public]])
524 AT_CHECK_JAVA_GREP([[public class YYParser]])
525
526 AT_CHECK_JAVA_MINIMAL([[
527 %define public
528 %define abstract]])
529 AT_CHECK_JAVA_GREP([[public abstract class YYParser]])
530
531 AT_CHECK_JAVA_MINIMAL([[
532 %define public
533 %define final]])
534 AT_CHECK_JAVA_GREP([[public final class YYParser]])
535
536 AT_CHECK_JAVA_MINIMAL([[
537 %define public
538 %define strictfp]])
539 AT_CHECK_JAVA_GREP([[public strictfp class YYParser]])
540
541 AT_CHECK_JAVA_MINIMAL([[
542 %define public
543 %define abstract
544 %define strictfp]])
545 AT_CHECK_JAVA_GREP([[public abstract strictfp class YYParser]])
546
547 AT_CHECK_JAVA_MINIMAL([[
548 %define public
549 %define final
550 %define strictfp]])
551 AT_CHECK_JAVA_GREP([[public final strictfp class YYParser]])
552
553 # FIXME: Can't do a Java compile because javacomp.sh is configured for 1.3
554 AT_CHECK_JAVA_MINIMAL([[
555 %define annotations "/*@Deprecated @SupressWarnings(\"unchecked\") @SupressWarnings({\"unchecked\", \"deprecation\"}) @SupressWarnings(value={\"unchecked\", \"deprecation\"})*/"
556 %define public]])
557 AT_CHECK_JAVA_GREP([[/\*@Deprecated @SupressWarnings("unchecked") @SupressWarnings({"unchecked", "deprecation"}) @SupressWarnings(value={"unchecked", "deprecation"})\*/ public class YYParser]])
558
559 AT_CLEANUP
560
561
562 # ---------------------------------------- #
563 # Java parser class extends and implements #
564 # ---------------------------------------- #
565
566 AT_SETUP([Java parser class extends and implements])
567
568 AT_CHECK_JAVA_MINIMAL([[%define extends "Thread"]])
569 AT_CHECK_JAVA_GREP([[class YYParser extends Thread]])
570
571 AT_CHECK_JAVA_MINIMAL([[%define implements "Cloneable"]])
572 AT_CHECK_JAVA_GREP([[class YYParser implements Cloneable]])
573
574 AT_CHECK_JAVA_MINIMAL([[
575 %define extends "Thread"
576 %define implements "Cloneable"]])
577 AT_CHECK_JAVA_GREP([[class YYParser extends Thread implements Cloneable]])
578
579 AT_CLEANUP
580
581
582 # -------------------------------- #
583 # Java %parse-param and %lex-param #
584 # -------------------------------- #
585
586 AT_SETUP([Java %parse-param and %lex-param])
587
588 AT_CHECK_JAVA_MINIMAL([])
589 AT_CHECK_JAVA_GREP([[ *public YYParser (Lexer yylexer) *]])
590
591 AT_CHECK_JAVA_MINIMAL([[%parse-param {int parse_param1}]])
592 AT_CHECK_JAVA_GREP([[ *protected final int parse_param1;]])
593 AT_CHECK_JAVA_GREP([[ *public YYParser (Lexer yylexer, *int parse_param1) *]])
594 AT_CHECK_JAVA_GREP([[ *this.parse_param1 = parse_param1;]])
595
596 AT_CHECK_JAVA_MINIMAL([[
597 %parse-param {int parse_param1}
598 %parse-param {long parse_param2}]])
599 AT_CHECK_JAVA_GREP([[ *protected final int parse_param1;]])
600 AT_CHECK_JAVA_GREP([[ *protected final long parse_param2;]])
601 AT_CHECK_JAVA_GREP([[ *public YYParser (Lexer yylexer, *int parse_param1, *long parse_param2) *]])
602 AT_CHECK_JAVA_GREP([[ *this.parse_param1 = parse_param1;]])
603 AT_CHECK_JAVA_GREP([[ *this.parse_param2 = parse_param2;]])
604
605 AT_CHECK_JAVA_MINIMAL_W_LEXER([], [], [[return EOF;]])
606 AT_CHECK_JAVA_GREP([[ *public YYParser () *]])
607 AT_CHECK_JAVA_GREP([[ *protected YYParser (Lexer yylexer) *]])
608
609 AT_CHECK_JAVA_MINIMAL_W_LEXER([[%parse-param {int parse_param1}]],
610 [], [[return EOF;]])
611 AT_CHECK_JAVA_GREP([[ *protected final int parse_param1;]])
612 AT_CHECK_JAVA_GREP([[ *public YYParser (int parse_param1) *]])
613 AT_CHECK_JAVA_GREP([[ *protected YYParser (Lexer yylexer, *int parse_param1) *]])
614 AT_CHECK_JAVA_GREP([[ *this.parse_param1 = parse_param1;]], [2])
615
616 AT_CHECK_JAVA_MINIMAL_W_LEXER([[
617 %parse-param {int parse_param1}
618 %parse-param {long parse_param2}]],
619 [], [[return EOF;]])
620 AT_CHECK_JAVA_GREP([[ *protected final int parse_param1;]])
621 AT_CHECK_JAVA_GREP([[ *protected final long parse_param2;]])
622 AT_CHECK_JAVA_GREP([[ *public YYParser (int parse_param1, *long parse_param2) *]])
623 AT_CHECK_JAVA_GREP([[ *protected YYParser (Lexer yylexer, *int parse_param1, *long parse_param2) *]])
624 AT_CHECK_JAVA_GREP([[ *this.parse_param1 = parse_param1;]], [2])
625 AT_CHECK_JAVA_GREP([[ *this.parse_param2 = parse_param2;]], [2])
626
627 AT_CHECK_JAVA_MINIMAL_W_LEXER([[%lex-param {char lex_param1}]],
628 [], [[return EOF;]], [[YYLexer (char lex_param1) {}]])
629 AT_CHECK_JAVA_GREP([[ *public YYParser (char lex_param1) *]])
630 AT_CHECK_JAVA_GREP([[.* = new YYLexer *(lex_param1);]])
631
632 AT_CHECK_JAVA_MINIMAL_W_LEXER([[
633 %lex-param {char lex_param1}
634 %lex-param {short lex_param2}]],
635 [], [[return EOF;]], [[YYLexer (char lex_param1, short lex_param2) {}]])
636 AT_CHECK_JAVA_GREP([[ *public YYParser (char lex_param1, *short lex_param2) *]])
637 AT_CHECK_JAVA_GREP([[.* = new YYLexer *(lex_param1, *lex_param2);]])
638
639 AT_CHECK_JAVA_MINIMAL_W_LEXER([[
640 %parse-param {int parse_param1}
641 %parse-param {long parse_param2}
642 %lex-param {char lex_param1}
643 %lex-param {short lex_param2}]],
644 [], [[return EOF;]], [[YYLexer (char lex_param1, short lex_param2) {}]])
645 AT_CHECK_JAVA_GREP([[ *protected final int parse_param1;]])
646 AT_CHECK_JAVA_GREP([[ *protected final long parse_param2;]])
647 AT_CHECK_JAVA_GREP([[ *public YYParser (char lex_param1, *short lex_param2, *int parse_param1, *long parse_param2) *]])
648 AT_CHECK_JAVA_GREP([[.* = new YYLexer *(lex_param1, *lex_param2);]])
649 AT_CHECK_JAVA_GREP([[ *protected YYParser (Lexer yylexer, *int parse_param1, *long parse_param2) *]])
650 AT_CHECK_JAVA_GREP([[ *this.parse_param1 = parse_param1;]], [2])
651 AT_CHECK_JAVA_GREP([[ *this.parse_param2 = parse_param2;]], [2])
652
653 AT_CLEANUP
654
655
656 # ------------------------- #
657 # Java throw specifications #
658 # ------------------------- #
659
660 AT_SETUP([Java throws specifications])
661
662 # %define throws - 0 1 2
663 # %define lex-throws - 0 1 2
664 # %code lexer 0 1
665
666 m4_define([AT_JT_lex_throws_define], [m4_case(AT_JT_lex_throws,
667 -1, [],
668 0, [[%define lex_throws ""]],
669 1, [[%define lex_throws "InterruptedException"]],
670 2, [[%define lex_throws "InterruptedException, IllegalAccessException"]])])
671
672 m4_define([AT_JT_yylex_throws], [m4_case(AT_JT_lex_throws,
673 -1, [[ throws java.io.IOException]],
674 0, [],
675 1, [[ throws InterruptedException]],
676 2, [[ throws InterruptedException, IllegalAccessException]])])
677
678 m4_define([AT_JT_yylex_action], [m4_case(AT_JT_lex_throws,
679 -1, [[throw new java.io.IOException();]],
680 0, [[return EOF;]],
681 1, [[throw new InterruptedException();]],
682 2, [[throw new IllegalAccessException();]])])
683
684
685 m4_define([AT_JT_throws_define], [m4_case(AT_JT_throws,
686 -1, [],
687 0, [[%define throws ""]],
688 1, [[%define throws "ClassNotFoundException"]],
689 2, [[%define throws "ClassNotFoundException, InstantiationException"]])])
690
691 m4_define([AT_JT_yyaction_throws], [m4_case(AT_JT_throws,
692 -1, [],
693 0, [],
694 1, [[ throws ClassNotFoundException]],
695 2, [[ throws ClassNotFoundException, InstantiationException]])])
696
697 m4_define([AT_JT_parse_throws_2], [m4_case(AT_JT_throws,
698 -1, [],
699 0, [],
700 1, [[, ClassNotFoundException]],
701 2, [[, ClassNotFoundException, InstantiationException]])])
702
703 m4_define([AT_JT_parse_throws],
704 [m4_if(m4_quote(AT_JT_yylex_throws), [],
705 [AT_JT_yyaction_throws],
706 [AT_JT_yylex_throws[]AT_JT_parse_throws_2])])
707
708 m4_define([AT_JT_initial_action], [m4_case(AT_JT_throws,
709 -1, [],
710 0, [],
711 1, [[%initial-action {if (true) throw new ClassNotFoundException();}]],
712 2, [[%initial-action {if (true) throw new InstantiationException();}]])])
713
714 m4_define([AT_JT_parse_action], [m4_case(AT_JT_throws,
715 -1, [],
716 0, [],
717 1, [[throw new ClassNotFoundException();]],
718 2, [[throw new ClassNotFoundException();]])])
719
720 m4_for([AT_JT_lexer], 0, 1, 1,
721 [m4_for([AT_JT_lex_throws], -1, 2, 1,
722 [m4_for([AT_JT_throws], -1, 2, 1,
723 [m4_if(AT_JT_lexer, 0,
724 [AT_CHECK_JAVA_MINIMAL([
725 AT_JT_throws_define
726 AT_JT_lex_throws_define
727 AT_JT_initial_action],
728 [AT_JT_parse_action])],
729 [AT_CHECK_JAVA_MINIMAL_W_LEXER([
730 AT_JT_throws_define
731 AT_JT_lex_throws_define
732 AT_JT_initial_action],
733 [AT_JT_yylex_throws],
734 [AT_JT_yylex_action],
735 [],
736 [AT_JT_parse_action])])
737 AT_CHECK_JAVA_GREP([[ *int yylex ()]AT_JT_yylex_throws *[;]])
738 AT_CHECK_JAVA_GREP([[ *private int yyaction ([^)]*)]AT_JT_yyaction_throws[ *]])
739 AT_CHECK_JAVA_GREP([[ *public boolean parse ()]AT_JT_parse_throws[ *]])
740 ])])])
741
742 AT_CLEANUP
743
744
745 # ------------------------------------- #
746 # Java constructor init and init_throws #
747 # ------------------------------------- #
748
749 AT_SETUP([Java constructor init and init_throws])
750
751 AT_CHECK_JAVA_MINIMAL([[
752 %define extends "Thread"
753 %code init { super("Test Thread"); if (true) throw new InterruptedException(); }
754 %define init_throws "InterruptedException"
755 %lex-param {int lex_param}]])
756 AT_CHECK([[grep -q 'super("Test Thread"); if (true) throw new InterruptedException();' YYParser.java]])
757
758 AT_CHECK_JAVA_MINIMAL_W_LEXER([[
759 %define extends "Thread"
760 %code init { super("Test Thread"); if (true) throw new InterruptedException(); }
761 %define init_throws "InterruptedException"]], [], [[return EOF;]])
762 AT_CHECK([[grep -q 'super("Test Thread"); if (true) throw new InterruptedException();' YYParser.java]])
763
764 AT_CLEANUP
765
766
767 # --------------------------------------------- #
768 # Java stype, position_class and location_class #
769 # --------------------------------------------- #
770
771 AT_SETUP([Java stype, position_class and location_class])
772
773 AT_CHECK_JAVA_MINIMAL([[
774 %define stype "java.awt.Color"
775 %type<java.awt.Color> start;
776 %define location_type "MyLoc"
777 %define position_type "MyPos"
778 %code { class MyPos {} }]], [[$$ = $<java.awt.Color>1;]], [[MyPos]])
779 AT_CHECK([[grep -q 'java.awt.Color' YYParser.java]])
780 AT_CHECK([[egrep -v ' */?\*' YYParser.java | grep -q 'Position']], [1])
781 AT_CHECK([[egrep -v ' */?\*' YYParser.java | grep -q 'Location']], [1])
782
783 AT_CHECK_JAVA_MINIMAL_W_LEXER([[
784 %define stype "java.awt.Color"
785 %type<java.awt.Color> start;
786 %define location_type "MyLoc"
787 %define position_type "MyPos"
788 %code { class MyPos {} }]], [], [[return EOF;]], [],
789 [[$$ = $<java.awt.Color>1;]],
790 [[java.awt.Color]], [[MyPos]], [[MyLoc]])
791 AT_CHECK([[grep -q 'java.awt.Color' YYParser.java]])
792 AT_CHECK([[egrep -v ' */?\*' YYParser.java | grep -q 'Position']], [1])
793 AT_CHECK([[egrep -v ' */?\*' YYParser.java | grep -q 'Location']], [1])
794
795 AT_CLEANUP