]> git.saurik.com Git - bison.git/blame - tests/java.at
doc: token.prefix
[bison.git] / tests / java.at
CommitLineData
0049ec86 1# Java tests for simple calculator. -*- Autotest -*-
8405b70c 2
74553c98 3# Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc.
8405b70c 4
f16b0819 5# This program is free software: you can redistribute it and/or modify
8405b70c 6# it under the terms of the GNU General Public License as published by
f16b0819
PE
7# the Free Software Foundation, either version 3 of the License, or
8# (at your option) any later version.
9#
8405b70c
PB
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.
f16b0819 14#
8405b70c 15# You should have received a copy of the GNU General Public License
f16b0819 16# along with this program. If not, see <http://www.gnu.org/licenses/>.
8405b70c
PB
17
18AT_BANNER([[Java Calculator.]])
19
20
21# ------------------------- #
22# Helping Autotest macros. #
23# ------------------------- #
24
25
01b477c6 26# _AT_DATA_JAVA_CALC_Y($1, $2, $3, [BISON-DIRECTIVES])
417e31d2 27# ----------------------------------------------------
8405b70c
PB
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.
32m4_define([_AT_DATA_JAVA_CALC_Y],
33[m4_if([$1$2$3], $[1]$[2]$[3], [],
34 [m4_fatal([$0: Invalid arguments: $@])])dnl
35AT_DATA([Calc.y],
36[[/* Infix notation calculator--calc */
37%language "Java"
01b477c6 38%name-prefix "Calc"
8405b70c
PB
39%define parser_class_name "Calc"
40%define public
41
01b477c6
PB
42]$4[
43
8405b70c
PB
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%%
64input:
65 line
66| input line
67;
68
69line:
70 '\n'
71| exp '\n'
72| error '\n'
73;
74
75exp:
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;
01b477c6
PB
95
96]AT_LEXPARAM_IF([[
97%code lexer {
98]],
99[[
8405b70c 100%%
01b477c6
PB
101class 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
115AT_LOCATION_IF([[
116 Position yystartpos;
117 Position yyendpos = new Position (1);
8405b70c 118
01b477c6
PB
119 public Position getStartPos() {
120 return yystartpos;
8405b70c
PB
121 }
122
01b477c6
PB
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 {
11707b2b 137 System.err.println (s);
01b477c6
PB
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)
1979121c 151 return EOF;
01b477c6
PB
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);
1979121c 162 return NUM;
01b477c6
PB
163 }
164
165 else
166 return st.ttype;
167 }
168
169
170]AT_LEXPARAM_IF([[
171};
172%%]], [[
173}]])
174
175[
176class 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]])
8405b70c
PB
211])# _AT_DATA_JAVA_CALC_Y
212
213
01b477c6 214# AT_DATA_CALC_Y([BISON-OPTIONS])
417e31d2 215# -------------------------------
8405b70c
PB
216# Produce `calc.y'.
217m4_define([AT_DATA_JAVA_CALC_Y],
01b477c6 218[_AT_DATA_JAVA_CALC_Y($[1], $[2], $[3], [$1])
8405b70c
PB
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.
227m4_define([AT_JAVA_COMPILE],
1979121c
DJ
228[AT_KEYWORDS(java)
229AT_CHECK([test -n "$CONF_JAVA" || exit 77
0049ec86 230test -n "$CONF_JAVAC" || exit 77])
8405b70c
PB
231AT_CHECK([$SHELL ../../../javacomp.sh $1],
232 0, [ignore], [ignore])])
233
234
235# AT_JAVA_PARSER_CHECK(COMMAND, EXIT-STATUS, EXPOUT, EXPERR, [PRE])
236# -----------------------------------------------------------------
237m4_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.
251m4_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]])
257AT_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.
262AT_DATA([[expout]],
263[$3
264])
265# 2. If locations are not used, remove them.
266AT_YYERROR_SEES_LOC_IF([],
267[[sed 's/^[-0-9.]*: //' expout >at-expout
268mv at-expout expout]])
269# 3. If error-verbose is not used, strip the`, unexpected....' part.
270m4_bmatch([$1], [%error-verbose], [],
271[[sed 's/syntax error, .*$/syntax error/' expout >at-expout
272mv at-expout expout]])
273# 4. Check
274AT_CHECK([cat stderr], 0, [expout])
275])
276
01b477c6 277# _AT_CHECK_JAVA_CALC([BISON-DIRECTIVES], [BISON-CODE])
417e31d2 278# -----------------------------------------------------
8405b70c
PB
279# Start a testing chunk which compiles `calc' grammar with
280# BISON-DIRECTIVES, and performs several tests over the parser.
281m4_define([_AT_CHECK_JAVA_CALC],
282[# We use integers to avoid dependencies upon the precision of doubles.
283AT_SETUP([Calculator $1])
284
285AT_BISON_OPTION_PUSHDEFS([$1])
286
287AT_DATA_JAVA_CALC_Y([$1
288%code {
289$2
01b477c6 290}])
8405b70c 291
da730230 292AT_BISON_CHECK([-o Calc.java Calc.y])
8405b70c
PB
293AT_JAVA_COMPILE([Calc.java])
294
295# Test the priorities.
296AT_DATA([[input]],
297[[1 + 2 * 3 = 7
2981 + 2 * -3 = -5
299
300-1^2 = -1
301(-1)^2 = 1
302
303---1 = -1
304
3051 - 2 - 3 = -4
3061 - (2 - 3) = 2
307
3082^2^3 = 256
309(2^2)^3 = 64
310]])
311AT_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#
11707b2b 346_AT_CHECK_JAVA_CALC_ERROR([$1],
8405b70c
PB
347 [() + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1],
348[1: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
3491: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
3501: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
3511: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
352calc: 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
358calc: error: 2222 != 1])
359_AT_CHECK_JAVA_CALC_ERROR([$1], [(- *) + (0 0) = 1],
360[1: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
3611: syntax error, unexpected number
362calc: error: 2222 != 1])
363AT_BISON_OPTION_POPDEFS
364
365AT_CLEANUP
366])# _AT_CHECK_JAVA_CALC
367
368
01b477c6 369# AT_CHECK_JAVA_CALC([BISON-DIRECTIVES])
417e31d2 370# --------------------------------------
8405b70c
PB
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.
374m4_define([AT_CHECK_JAVA_CALC],
01b477c6
PB
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])
8405b70c
PB
379])# AT_CHECK_JAVA_CALC
380
381
382# ------------------------ #
383# Simple LALR Calculator. #
384# ------------------------ #
385
01b477c6 386AT_CHECK_JAVA_CALC([], [[
8405b70c
PB
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 }
01b477c6 393]])
8405b70c 394
01b477c6
PB
395AT_CHECK_JAVA_CALC([%lex-param { InputStream is } ], [[
396 public static void main (String args[]) throws IOException
8405b70c 397 {
01b477c6 398 new Calc (System.in).parse ();
8405b70c 399 }
8405b70c 400]])
e254a580
DJ
401
402
403
404# -----------------#
405# Java Directives. #
406# -----------------#
407
408AT_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.
415m4_define([AT_CHECK_JAVA_MINIMAL],
416[
417AT_DATA([[YYParser.y]], [
418%language "Java"
419%locations
420%debug
421%error-verbose
422%token-table
417e31d2 423%token END "end"
e254a580
DJ
424$1
425%%
417e31d2 426start: END {$2};
e254a580
DJ
427%%
428class m4_default([$3], [Position]) {}
429])
430AT_BISON_CHECK([[YYParser.y]])
74553c98 431AT_CHECK([[grep '[mb]4_' YYParser.y]], [1], [ignore])
e254a580
DJ
432AT_JAVA_COMPILE([[YYParser.java]])
433])
434
435
436# AT_CHECK_JAVA_MINIMAL_W_LEXER([1:DIRECTIVES], [2:LEX_THROWS],
437# [3:YYLEX_ACTION], [4:LEXER_BODY], [5:PARSER_ACTION], [6:STYPE],
438# [7:POSITION_TYPE], [8:LOCATION_TYPE])
439# ---------------------------------------------------------------------
440# Check that a mininal parser with DIRECTIVES and a "%code lexer".
441# YYLEX is the body of yylex () which throws LEX_THROW.
442# compiles in Java.
443m4_define([AT_CHECK_JAVA_MINIMAL_W_LEXER],
444[AT_CHECK_JAVA_MINIMAL([$1
445
446%code lexer
447{
448 m4_default([$6], [Object]) yylval;
449 public m4_default([$6], [Object]) getLVal() { return yylval; }
450
451 public m4_default([$7], [Position]) getStartPos() { return null; }
452 public m4_default([$7], [Position]) getEndPos() { return null; }
453
454 public void yyerror (m4_default([$8], [Location]) loc, String s)
455 {
456 System.err.println (loc + ": " + s);
457 }
458
459 public int yylex ()$2
460 {
461 $3
462 }
11707b2b 463
e254a580
DJ
464 $4
465}], [$5], [$7])])
466
467
468# AT_CHECK_JAVA_GREP([LINE], [COUNT=1])
469# -------------------------------------
470# Check that YYParser.java contains exactly COUNT lines matching ^LINE$
471# with grep.
472m4_define([AT_CHECK_JAVA_GREP],
473 [AT_CHECK([grep -c '^$1$' YYParser.java], [], [m4_default([$2], [1])
474])
475])
476
477
417e31d2
AD
478# ------------------------------------- #
479# Java parser class and package names. #
480# ------------------------------------- #
e254a580
DJ
481
482AT_SETUP([Java parser class and package names])
483
484AT_CHECK_JAVA_MINIMAL([])
485AT_CHECK_JAVA_GREP([[class YYParser]])
486
487AT_CHECK_JAVA_MINIMAL([[%name-prefix "Prefix"]])
488AT_CHECK_JAVA_GREP([[class PrefixParser]])
489
417e31d2
AD
490AT_CHECK_JAVA_MINIMAL([[%define token.prefix "TOK_"]])
491AT_CHECK_JAVA_GREP([[.*TOK_END.*]])
492
e254a580
DJ
493AT_CHECK_JAVA_MINIMAL([[%define parser_class_name "ParserClassName"]])
494AT_CHECK_JAVA_GREP([[class ParserClassName]])
495
496AT_CHECK_JAVA_MINIMAL([[%define package "user_java_package"]])
497AT_CHECK_JAVA_GREP([[package user_java_package;]])
498
499AT_CLEANUP
500
501
417e31d2
AD
502# ----------------------------- #
503# Java parser class modifiers. #
504# ----------------------------- #
e254a580
DJ
505
506AT_SETUP([Java parser class modifiers])
507
508AT_CHECK_JAVA_MINIMAL([[%define abstract]])
509AT_CHECK_JAVA_GREP([[abstract class YYParser]])
510
511AT_CHECK_JAVA_MINIMAL([[%define final]])
512AT_CHECK_JAVA_GREP([[final class YYParser]])
513
514AT_CHECK_JAVA_MINIMAL([[%define strictfp]])
515AT_CHECK_JAVA_GREP([[strictfp class YYParser]])
516
517AT_CHECK_JAVA_MINIMAL([[
518%define abstract
519%define strictfp]])
520AT_CHECK_JAVA_GREP([[abstract strictfp class YYParser]])
521
522AT_CHECK_JAVA_MINIMAL([[
523%define final
524%define strictfp]])
525AT_CHECK_JAVA_GREP([[final strictfp class YYParser]])
526
527AT_CHECK_JAVA_MINIMAL([[%define public]])
528AT_CHECK_JAVA_GREP([[public class YYParser]])
529
530AT_CHECK_JAVA_MINIMAL([[
531%define public
532%define abstract]])
533AT_CHECK_JAVA_GREP([[public abstract class YYParser]])
534
535AT_CHECK_JAVA_MINIMAL([[
536%define public
537%define final]])
538AT_CHECK_JAVA_GREP([[public final class YYParser]])
539
540AT_CHECK_JAVA_MINIMAL([[
541%define public
542%define strictfp]])
543AT_CHECK_JAVA_GREP([[public strictfp class YYParser]])
544
545AT_CHECK_JAVA_MINIMAL([[
546%define public
547%define abstract
548%define strictfp]])
549AT_CHECK_JAVA_GREP([[public abstract strictfp class YYParser]])
550
551AT_CHECK_JAVA_MINIMAL([[
552%define public
553%define final
554%define strictfp]])
555AT_CHECK_JAVA_GREP([[public final strictfp class YYParser]])
556
1979121c
DJ
557# FIXME: Can't do a Java compile because javacomp.sh is configured for 1.3
558AT_CHECK_JAVA_MINIMAL([[
559%define annotations "/*@Deprecated @SupressWarnings(\"unchecked\") @SupressWarnings({\"unchecked\", \"deprecation\"}) @SupressWarnings(value={\"unchecked\", \"deprecation\"})*/"
560%define public]])
561AT_CHECK_JAVA_GREP([[/\*@Deprecated @SupressWarnings("unchecked") @SupressWarnings({"unchecked", "deprecation"}) @SupressWarnings(value={"unchecked", "deprecation"})\*/ public class YYParser]])
562
e254a580
DJ
563AT_CLEANUP
564
565
566# ---------------------------------------- #
567# Java parser class extends and implements #
568# ---------------------------------------- #
569
570AT_SETUP([Java parser class extends and implements])
571
572AT_CHECK_JAVA_MINIMAL([[%define extends "Thread"]])
573AT_CHECK_JAVA_GREP([[class YYParser extends Thread]])
574
575AT_CHECK_JAVA_MINIMAL([[%define implements "Cloneable"]])
576AT_CHECK_JAVA_GREP([[class YYParser implements Cloneable]])
577
578AT_CHECK_JAVA_MINIMAL([[
579%define extends "Thread"
580%define implements "Cloneable"]])
581AT_CHECK_JAVA_GREP([[class YYParser extends Thread implements Cloneable]])
582
583AT_CLEANUP
584
585
586# -------------------------------- #
587# Java %parse-param and %lex-param #
588# -------------------------------- #
589
590AT_SETUP([Java %parse-param and %lex-param])
591
592AT_CHECK_JAVA_MINIMAL([])
1979121c 593AT_CHECK_JAVA_GREP([[ *public YYParser (Lexer yylexer) *]])
e254a580
DJ
594
595AT_CHECK_JAVA_MINIMAL([[%parse-param {int parse_param1}]])
596AT_CHECK_JAVA_GREP([[ *protected final int parse_param1;]])
1979121c 597AT_CHECK_JAVA_GREP([[ *public YYParser (Lexer yylexer, *int parse_param1) *]])
11707b2b 598AT_CHECK_JAVA_GREP([[ *this.parse_param1 = parse_param1;]])
e254a580
DJ
599
600AT_CHECK_JAVA_MINIMAL([[
601%parse-param {int parse_param1}
602%parse-param {long parse_param2}]])
603AT_CHECK_JAVA_GREP([[ *protected final int parse_param1;]])
604AT_CHECK_JAVA_GREP([[ *protected final long parse_param2;]])
1979121c 605AT_CHECK_JAVA_GREP([[ *public YYParser (Lexer yylexer, *int parse_param1, *long parse_param2) *]])
11707b2b
AD
606AT_CHECK_JAVA_GREP([[ *this.parse_param1 = parse_param1;]])
607AT_CHECK_JAVA_GREP([[ *this.parse_param2 = parse_param2;]])
e254a580
DJ
608
609AT_CHECK_JAVA_MINIMAL_W_LEXER([], [], [[return EOF;]])
1979121c
DJ
610AT_CHECK_JAVA_GREP([[ *public YYParser () *]])
611AT_CHECK_JAVA_GREP([[ *protected YYParser (Lexer yylexer) *]])
e254a580
DJ
612
613AT_CHECK_JAVA_MINIMAL_W_LEXER([[%parse-param {int parse_param1}]],
1979121c 614 [], [[return EOF;]])
e254a580 615AT_CHECK_JAVA_GREP([[ *protected final int parse_param1;]])
1979121c
DJ
616AT_CHECK_JAVA_GREP([[ *public YYParser (int parse_param1) *]])
617AT_CHECK_JAVA_GREP([[ *protected YYParser (Lexer yylexer, *int parse_param1) *]])
11707b2b 618AT_CHECK_JAVA_GREP([[ *this.parse_param1 = parse_param1;]], [2])
e254a580
DJ
619
620AT_CHECK_JAVA_MINIMAL_W_LEXER([[
621%parse-param {int parse_param1}
622%parse-param {long parse_param2}]],
1979121c 623 [], [[return EOF;]])
e254a580
DJ
624AT_CHECK_JAVA_GREP([[ *protected final int parse_param1;]])
625AT_CHECK_JAVA_GREP([[ *protected final long parse_param2;]])
1979121c
DJ
626AT_CHECK_JAVA_GREP([[ *public YYParser (int parse_param1, *long parse_param2) *]])
627AT_CHECK_JAVA_GREP([[ *protected YYParser (Lexer yylexer, *int parse_param1, *long parse_param2) *]])
11707b2b
AD
628AT_CHECK_JAVA_GREP([[ *this.parse_param1 = parse_param1;]], [2])
629AT_CHECK_JAVA_GREP([[ *this.parse_param2 = parse_param2;]], [2])
e254a580
DJ
630
631AT_CHECK_JAVA_MINIMAL_W_LEXER([[%lex-param {char lex_param1}]],
1979121c
DJ
632 [], [[return EOF;]], [[YYLexer (char lex_param1) {}]])
633AT_CHECK_JAVA_GREP([[ *public YYParser (char lex_param1) *]])
e254a580
DJ
634AT_CHECK_JAVA_GREP([[.* = new YYLexer *(lex_param1);]])
635
636AT_CHECK_JAVA_MINIMAL_W_LEXER([[
637%lex-param {char lex_param1}
638%lex-param {short lex_param2}]],
1979121c
DJ
639 [], [[return EOF;]], [[YYLexer (char lex_param1, short lex_param2) {}]])
640AT_CHECK_JAVA_GREP([[ *public YYParser (char lex_param1, *short lex_param2) *]])
e254a580
DJ
641AT_CHECK_JAVA_GREP([[.* = new YYLexer *(lex_param1, *lex_param2);]])
642
643AT_CHECK_JAVA_MINIMAL_W_LEXER([[
644%parse-param {int parse_param1}
645%parse-param {long parse_param2}
646%lex-param {char lex_param1}
647%lex-param {short lex_param2}]],
1979121c 648 [], [[return EOF;]], [[YYLexer (char lex_param1, short lex_param2) {}]])
e254a580
DJ
649AT_CHECK_JAVA_GREP([[ *protected final int parse_param1;]])
650AT_CHECK_JAVA_GREP([[ *protected final long parse_param2;]])
1979121c 651AT_CHECK_JAVA_GREP([[ *public YYParser (char lex_param1, *short lex_param2, *int parse_param1, *long parse_param2) *]])
e254a580 652AT_CHECK_JAVA_GREP([[.* = new YYLexer *(lex_param1, *lex_param2);]])
1979121c 653AT_CHECK_JAVA_GREP([[ *protected YYParser (Lexer yylexer, *int parse_param1, *long parse_param2) *]])
11707b2b
AD
654AT_CHECK_JAVA_GREP([[ *this.parse_param1 = parse_param1;]], [2])
655AT_CHECK_JAVA_GREP([[ *this.parse_param2 = parse_param2;]], [2])
e254a580
DJ
656
657AT_CLEANUP
658
659
660# ------------------------- #
661# Java throw specifications #
662# ------------------------- #
663
664AT_SETUP([Java throws specifications])
665
666# %define throws - 0 1 2
667# %define lex-throws - 0 1 2
668# %code lexer 0 1
669
670m4_define([AT_JT_lex_throws_define], [m4_case(AT_JT_lex_throws,
671 -1, [],
672 0, [[%define lex_throws ""]],
673 1, [[%define lex_throws "InterruptedException"]],
674 2, [[%define lex_throws "InterruptedException, IllegalAccessException"]])])
675
676m4_define([AT_JT_yylex_throws], [m4_case(AT_JT_lex_throws,
677 -1, [[ throws java.io.IOException]],
678 0, [],
679 1, [[ throws InterruptedException]],
680 2, [[ throws InterruptedException, IllegalAccessException]])])
681
682m4_define([AT_JT_yylex_action], [m4_case(AT_JT_lex_throws,
683 -1, [[throw new java.io.IOException();]],
684 0, [[return EOF;]],
685 1, [[throw new InterruptedException();]],
686 2, [[throw new IllegalAccessException();]])])
687
688
689m4_define([AT_JT_throws_define], [m4_case(AT_JT_throws,
690 -1, [],
691 0, [[%define throws ""]],
692 1, [[%define throws "ClassNotFoundException"]],
693 2, [[%define throws "ClassNotFoundException, InstantiationException"]])])
694
695m4_define([AT_JT_yyaction_throws], [m4_case(AT_JT_throws,
696 -1, [],
697 0, [],
698 1, [[ throws ClassNotFoundException]],
699 2, [[ throws ClassNotFoundException, InstantiationException]])])
700
701m4_define([AT_JT_parse_throws_2], [m4_case(AT_JT_throws,
702 -1, [],
703 0, [],
704 1, [[, ClassNotFoundException]],
705 2, [[, ClassNotFoundException, InstantiationException]])])
706
707m4_define([AT_JT_parse_throws],
708 [m4_if(m4_quote(AT_JT_yylex_throws), [],
709 [AT_JT_yyaction_throws],
710 [AT_JT_yylex_throws[]AT_JT_parse_throws_2])])
711
712m4_define([AT_JT_initial_action], [m4_case(AT_JT_throws,
713 -1, [],
714 0, [],
715 1, [[%initial-action {if (true) throw new ClassNotFoundException();}]],
716 2, [[%initial-action {if (true) throw new InstantiationException();}]])])
717
718m4_define([AT_JT_parse_action], [m4_case(AT_JT_throws,
719 -1, [],
720 0, [],
721 1, [[throw new ClassNotFoundException();]],
722 2, [[throw new ClassNotFoundException();]])])
723
724m4_for([AT_JT_lexer], 0, 1, 1,
725 [m4_for([AT_JT_lex_throws], -1, 2, 1,
726 [m4_for([AT_JT_throws], -1, 2, 1,
727 [m4_if(AT_JT_lexer, 0,
728 [AT_CHECK_JAVA_MINIMAL([
729AT_JT_throws_define
730AT_JT_lex_throws_define
731AT_JT_initial_action],
732[AT_JT_parse_action])],
733 [AT_CHECK_JAVA_MINIMAL_W_LEXER([
734AT_JT_throws_define
735AT_JT_lex_throws_define
736AT_JT_initial_action],
737[AT_JT_yylex_throws],
738[AT_JT_yylex_action],
739[],
740[AT_JT_parse_action])])
741AT_CHECK_JAVA_GREP([[ *int yylex ()]AT_JT_yylex_throws *[;]])
742AT_CHECK_JAVA_GREP([[ *private int yyaction ([^)]*)]AT_JT_yyaction_throws[ *]])
743AT_CHECK_JAVA_GREP([[ *public boolean parse ()]AT_JT_parse_throws[ *]])
744])])])
745
746AT_CLEANUP
747
748
1979121c
DJ
749# ------------------------------------- #
750# Java constructor init and init_throws #
751# ------------------------------------- #
752
753AT_SETUP([Java constructor init and init_throws])
754
755AT_CHECK_JAVA_MINIMAL([[
756%define extends "Thread"
757%code init { super("Test Thread"); if (true) throw new InterruptedException(); }
758%define init_throws "InterruptedException"
759%lex-param {int lex_param}]])
760AT_CHECK([[grep -q 'super("Test Thread"); if (true) throw new InterruptedException();' YYParser.java]])
761
762AT_CHECK_JAVA_MINIMAL_W_LEXER([[
763%define extends "Thread"
764%code init { super("Test Thread"); if (true) throw new InterruptedException(); }
765%define init_throws "InterruptedException"]], [], [[return EOF;]])
766AT_CHECK([[grep -q 'super("Test Thread"); if (true) throw new InterruptedException();' YYParser.java]])
767
768AT_CLEANUP
769
770
e254a580
DJ
771# --------------------------------------------- #
772# Java stype, position_class and location_class #
773# --------------------------------------------- #
774
775AT_SETUP([Java stype, position_class and location_class])
776
777AT_CHECK_JAVA_MINIMAL([[
778%define stype "java.awt.Color"
779%type<java.awt.Color> start;
780%define location_type "MyLoc"
781%define position_type "MyPos"
782%code { class MyPos {} }]], [[$$ = $<java.awt.Color>1;]], [[MyPos]])
74553c98
AD
783AT_CHECK([[grep 'java.awt.Color' YYParser.java]], [0], [ignore])
784AT_CHECK([[$EGREP -v ' */?\*' YYParser.java | grep 'Position']], [1], [ignore])
785AT_CHECK([[$EGREP -v ' */?\*' YYParser.java | grep 'Location']], [1], [ignore])
e254a580
DJ
786
787AT_CHECK_JAVA_MINIMAL_W_LEXER([[
788%define stype "java.awt.Color"
789%type<java.awt.Color> start;
790%define location_type "MyLoc"
791%define position_type "MyPos"
792%code { class MyPos {} }]], [], [[return EOF;]], [],
793[[$$ = $<java.awt.Color>1;]],
794[[java.awt.Color]], [[MyPos]], [[MyLoc]])
74553c98
AD
795AT_CHECK([[grep 'java.awt.Color' YYParser.java]], [0], [ignore])
796AT_CHECK([[$EGREP -v ' */?\*' YYParser.java | grep 'Position']], [1], [ignore])
797AT_CHECK([[$EGREP -v ' */?\*' YYParser.java | grep 'Location']], [1], [ignore])
e254a580
DJ
798
799AT_CLEANUP