]>
Commit | Line | Data |
---|---|---|
0049ec86 | 1 | # Java tests for simple calculator. -*- Autotest -*- |
8405b70c | 2 | |
ea0a7676 | 3 | # Copyright (C) 2007-2011 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 | |
18 | AT_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]) |
8405b70c PB |
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" | |
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 | %% | |
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 | ; | |
01b477c6 PB |
95 | |
96 | ]AT_LEXPARAM_IF([[ | |
97 | %code lexer { | |
98 | ]], | |
99 | [[ | |
8405b70c | 100 | %% |
01b477c6 PB |
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); | |
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 | { | |
8defe11b | 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) | |
151 | return Calc.EOF; | |
152 | ||
153 | else if (ttype == st.TT_EOL) | |
154 | { | |
155 | ]AT_LOCATION_IF([[yyendpos = new Position (yyendpos.lineno () + 1);]])[ | |
156 | return (int) '\n'; | |
157 | } | |
158 | ||
159 | else if (ttype == st.TT_WORD) | |
160 | { | |
161 | yylval = new Integer (st.sval); | |
162 | return Calc.NUM; | |
163 | } | |
164 | ||
165 | else | |
166 | return st.ttype; | |
167 | } | |
168 | ||
169 | ||
170 | ]AT_LEXPARAM_IF([[ | |
171 | }; | |
172 | %%]], [[ | |
173 | }]]) | |
174 | ||
175 | [ | |
176 | class Position { | |
177 | public int line; | |
178 | ||
179 | public Position () | |
180 | { | |
181 | line = 0; | |
182 | } | |
183 | ||
184 | public Position (int l) | |
185 | { | |
186 | line = l; | |
187 | } | |
188 | ||
189 | public long getHashCode () | |
190 | { | |
191 | return line; | |
192 | } | |
193 | ||
194 | public boolean equals (Position l) | |
195 | { | |
196 | return l.line == line; | |
197 | } | |
198 | ||
199 | public String toString () | |
200 | { | |
201 | return Integer.toString (line); | |
202 | } | |
203 | ||
204 | public int lineno () | |
205 | { | |
206 | return line; | |
207 | } | |
208 | } | |
209 | ||
210 | ]]) | |
8405b70c PB |
211 | ])# _AT_DATA_JAVA_CALC_Y |
212 | ||
213 | ||
01b477c6 | 214 | # AT_DATA_CALC_Y([BISON-OPTIONS]) |
8405b70c PB |
215 | # ------------------------------------------------- |
216 | # Produce `calc.y'. | |
217 | m4_define([AT_DATA_JAVA_CALC_Y], | |
01b477c6 | 218 | [_AT_DATA_JAVA_CALC_Y($[1], $[2], $[3], [$1]) |
8405b70c PB |
219 | ]) |
220 | ||
221 | ||
8405b70c PB |
222 | # _AT_CHECK_JAVA_CALC_ERROR(BISON-OPTIONS, INPUT, |
223 | # [VERBOSE-AND-LOCATED-ERROR-MESSAGE]) | |
224 | # --------------------------------------------------------- | |
225 | # Run `calc' on INPUT, and expect a `syntax error' message. | |
226 | # | |
227 | # If INPUT starts with a slash, it is used as absolute input file name, | |
228 | # otherwise as contents. | |
229 | # | |
230 | # The VERBOSE-AND-LOCATED-ERROR-MESSAGE is stripped of locations | |
231 | # and expected tokens if necessary, and compared with the output. | |
232 | m4_define([_AT_CHECK_JAVA_CALC_ERROR], | |
233 | [m4_bmatch([$2], [^/], | |
234 | [AT_JAVA_PARSER_CHECK([Calc < $2], 0, [], [stderr])], | |
235 | [AT_DATA([[input]], | |
236 | [[$2 | |
237 | ]]) | |
238 | AT_JAVA_PARSER_CHECK([Calc < input], 0, [], [stderr])]) | |
239 | ||
240 | # Normalize the observed and expected error messages, depending upon the | |
241 | # options. | |
242 | # 1. Create the reference error message. | |
243 | AT_DATA([[expout]], | |
244 | [$3 | |
245 | ]) | |
246 | # 2. If locations are not used, remove them. | |
247 | AT_YYERROR_SEES_LOC_IF([], | |
248 | [[sed 's/^[-0-9.]*: //' expout >at-expout | |
249 | mv at-expout expout]]) | |
250 | # 3. If error-verbose is not used, strip the`, unexpected....' part. | |
251 | m4_bmatch([$1], [%error-verbose], [], | |
252 | [[sed 's/syntax error, .*$/syntax error/' expout >at-expout | |
253 | mv at-expout expout]]) | |
254 | # 4. Check | |
255 | AT_CHECK([cat stderr], 0, [expout]) | |
256 | ]) | |
257 | ||
01b477c6 | 258 | # _AT_CHECK_JAVA_CALC([BISON-DIRECTIVES], [BISON-CODE]) |
8405b70c PB |
259 | # ----------------------------------------------------------------------- |
260 | # Start a testing chunk which compiles `calc' grammar with | |
261 | # BISON-DIRECTIVES, and performs several tests over the parser. | |
262 | m4_define([_AT_CHECK_JAVA_CALC], | |
263 | [# We use integers to avoid dependencies upon the precision of doubles. | |
264 | AT_SETUP([Calculator $1]) | |
265 | ||
266 | AT_BISON_OPTION_PUSHDEFS([$1]) | |
267 | ||
268 | AT_DATA_JAVA_CALC_Y([$1 | |
269 | %code { | |
270 | $2 | |
01b477c6 | 271 | }]) |
8405b70c | 272 | |
da730230 | 273 | AT_BISON_CHECK([-o Calc.java Calc.y]) |
8405b70c PB |
274 | AT_JAVA_COMPILE([Calc.java]) |
275 | ||
276 | # Test the priorities. | |
277 | AT_DATA([[input]], | |
278 | [[1 + 2 * 3 = 7 | |
279 | 1 + 2 * -3 = -5 | |
280 | ||
281 | -1^2 = -1 | |
282 | (-1)^2 = 1 | |
283 | ||
284 | ---1 = -1 | |
285 | ||
286 | 1 - 2 - 3 = -4 | |
287 | 1 - (2 - 3) = 2 | |
288 | ||
289 | 2^2^3 = 256 | |
290 | (2^2)^3 = 64 | |
291 | ]]) | |
292 | AT_JAVA_PARSER_CHECK([Calc < input], 0, [], [stderr]) | |
293 | ||
294 | ||
295 | # Some syntax errors. | |
296 | _AT_CHECK_JAVA_CALC_ERROR([$1], [0 0], | |
297 | [1: syntax error, unexpected number]) | |
298 | _AT_CHECK_JAVA_CALC_ERROR([$1], [1//2], | |
299 | [1: syntax error, unexpected '/', expecting number or '-' or '(' or '!']) | |
300 | _AT_CHECK_JAVA_CALC_ERROR([$1], [error], | |
301 | [1: syntax error, unexpected $undefined]) | |
302 | _AT_CHECK_JAVA_CALC_ERROR([$1], [1 = 2 = 3], | |
303 | [1: syntax error, unexpected '=']) | |
304 | _AT_CHECK_JAVA_CALC_ERROR([$1], [ | |
305 | +1], | |
306 | [2: syntax error, unexpected '+']) | |
307 | # Exercise error messages with EOF: work on an empty file. | |
308 | _AT_CHECK_JAVA_CALC_ERROR([$1], [/dev/null], | |
309 | [1: syntax error, unexpected end of input]) | |
310 | ||
311 | # Exercise the error token: without it, we die at the first error, | |
312 | # hence be sure to | |
313 | # | |
314 | # - have several errors which exercise different shift/discardings | |
315 | # - (): nothing to pop, nothing to discard | |
316 | # - (1 + 1 + 1 +): a lot to pop, nothing to discard | |
317 | # - (* * *): nothing to pop, a lot to discard | |
318 | # - (1 + 2 * *): some to pop and discard | |
319 | # | |
320 | # - test the action associated to `error' | |
321 | # | |
322 | # - check the lookahead that triggers an error is not discarded | |
323 | # when we enter error recovery. Below, the lookahead causing the | |
324 | # first error is ")", which is needed to recover from the error and | |
325 | # produce the "0" that triggers the "0 != 1" error. | |
326 | # | |
8defe11b | 327 | _AT_CHECK_JAVA_CALC_ERROR([$1], |
8405b70c PB |
328 | [() + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1], |
329 | [1: syntax error, unexpected ')', expecting number or '-' or '(' or '!' | |
330 | 1: syntax error, unexpected ')', expecting number or '-' or '(' or '!' | |
331 | 1: syntax error, unexpected '*', expecting number or '-' or '(' or '!' | |
332 | 1: syntax error, unexpected '*', expecting number or '-' or '(' or '!' | |
333 | calc: error: 4444 != 1]) | |
334 | ||
335 | # The same, but this time exercising explicitly triggered syntax errors. | |
336 | # POSIX says the lookahead causing the error should not be discarded. | |
337 | _AT_CHECK_JAVA_CALC_ERROR([$1], [(!) + (0 0) = 1], | |
338 | [1: syntax error, unexpected number | |
339 | calc: error: 2222 != 1]) | |
340 | _AT_CHECK_JAVA_CALC_ERROR([$1], [(- *) + (0 0) = 1], | |
341 | [1: syntax error, unexpected '*', expecting number or '-' or '(' or '!' | |
342 | 1: syntax error, unexpected number | |
343 | calc: error: 2222 != 1]) | |
344 | AT_BISON_OPTION_POPDEFS | |
345 | ||
346 | AT_CLEANUP | |
347 | ])# _AT_CHECK_JAVA_CALC | |
348 | ||
349 | ||
01b477c6 | 350 | # AT_CHECK_JAVA_CALC([BISON-DIRECTIVES]) |
8405b70c PB |
351 | # -------------------------------------------------------- |
352 | # Start a testing chunk which compiles `calc' grammar with | |
353 | # BISON-DIRECTIVES, and performs several tests over the parser. | |
354 | # Run the test with and without %error-verbose. | |
355 | m4_define([AT_CHECK_JAVA_CALC], | |
01b477c6 PB |
356 | [_AT_CHECK_JAVA_CALC([$1], [$2]) |
357 | _AT_CHECK_JAVA_CALC([%error-verbose $1], [$2]) | |
358 | _AT_CHECK_JAVA_CALC([%locations $1], [$2]) | |
359 | _AT_CHECK_JAVA_CALC([%error-verbose %locations $1], [$2]) | |
8405b70c PB |
360 | ])# AT_CHECK_JAVA_CALC |
361 | ||
362 | ||
363 | # ------------------------ # | |
364 | # Simple LALR Calculator. # | |
365 | # ------------------------ # | |
366 | ||
01b477c6 | 367 | AT_CHECK_JAVA_CALC([], [[ |
8405b70c PB |
368 | public static void main (String args[]) throws IOException |
369 | { | |
370 | CalcLexer l = new CalcLexer (System.in); | |
371 | Calc p = new Calc (l); | |
372 | p.parse (); | |
373 | } | |
01b477c6 | 374 | ]]) |
8405b70c | 375 | |
01b477c6 PB |
376 | AT_CHECK_JAVA_CALC([%lex-param { InputStream is } ], [[ |
377 | public static void main (String args[]) throws IOException | |
8405b70c | 378 | { |
01b477c6 | 379 | new Calc (System.in).parse (); |
8405b70c | 380 | } |
8405b70c | 381 | ]]) |
e254a580 DJ |
382 | |
383 | ||
384 | ||
385 | # -----------------# | |
386 | # Java Directives. # | |
387 | # -----------------# | |
388 | ||
389 | AT_BANNER([Java Parameters.]) | |
390 | ||
391 | ||
392 | # AT_CHECK_JAVA_MINIMAL([DIRECTIVES], [PARSER_ACTION], [POSITION_CLASS]) | |
393 | # ---------------------------------------------------------------------- | |
394 | # Check that a mininal parser with DIRECTIVES compiles in Java. | |
395 | # Put the Java code in YYParser.java. | |
396 | m4_define([AT_CHECK_JAVA_MINIMAL], | |
397 | [ | |
398 | AT_DATA([[YYParser.y]], [ | |
399 | %language "Java" | |
400 | %locations | |
401 | %debug | |
402 | %error-verbose | |
403 | %token-table | |
404 | $1 | |
405 | %% | |
406 | start: "end" {$2}; | |
407 | %% | |
408 | class m4_default([$3], [Position]) {} | |
409 | ]) | |
410 | AT_BISON_CHECK([[YYParser.y]]) | |
8defe11b | 411 | AT_CHECK([[grep '[mb]4_' YYParser.y]], [1], [ignore]) |
e254a580 DJ |
412 | AT_JAVA_COMPILE([[YYParser.java]]) |
413 | ]) | |
414 | ||
415 | ||
416 | # AT_CHECK_JAVA_MINIMAL_W_LEXER([1:DIRECTIVES], [2:LEX_THROWS], | |
417 | # [3:YYLEX_ACTION], [4:LEXER_BODY], [5:PARSER_ACTION], [6:STYPE], | |
418 | # [7:POSITION_TYPE], [8:LOCATION_TYPE]) | |
419 | # --------------------------------------------------------------------- | |
420 | # Check that a mininal parser with DIRECTIVES and a "%code lexer". | |
421 | # YYLEX is the body of yylex () which throws LEX_THROW. | |
422 | # compiles in Java. | |
423 | m4_define([AT_CHECK_JAVA_MINIMAL_W_LEXER], | |
424 | [AT_CHECK_JAVA_MINIMAL([$1 | |
425 | ||
426 | %code lexer | |
427 | { | |
428 | m4_default([$6], [Object]) yylval; | |
429 | public m4_default([$6], [Object]) getLVal() { return yylval; } | |
430 | ||
431 | public m4_default([$7], [Position]) getStartPos() { return null; } | |
432 | public m4_default([$7], [Position]) getEndPos() { return null; } | |
433 | ||
434 | public void yyerror (m4_default([$8], [Location]) loc, String s) | |
435 | { | |
436 | System.err.println (loc + ": " + s); | |
437 | } | |
438 | ||
439 | public int yylex ()$2 | |
440 | { | |
441 | $3 | |
442 | } | |
8defe11b | 443 | |
e254a580 DJ |
444 | $4 |
445 | }], [$5], [$7])]) | |
446 | ||
447 | ||
448 | # AT_CHECK_JAVA_GREP([LINE], [COUNT=1]) | |
449 | # ------------------------------------- | |
450 | # Check that YYParser.java contains exactly COUNT lines matching ^LINE$ | |
451 | # with grep. | |
452 | m4_define([AT_CHECK_JAVA_GREP], | |
453 | [AT_CHECK([grep -c '^$1$' YYParser.java], [], [m4_default([$2], [1]) | |
454 | ]) | |
455 | ]) | |
456 | ||
457 | ||
458 | # ----------------------------------- # | |
459 | # Java parser class and package names # | |
460 | # ----------------------------------- # | |
461 | ||
462 | AT_SETUP([Java parser class and package names]) | |
463 | ||
464 | AT_CHECK_JAVA_MINIMAL([]) | |
465 | AT_CHECK_JAVA_GREP([[class YYParser]]) | |
466 | ||
467 | AT_CHECK_JAVA_MINIMAL([[%name-prefix "Prefix"]]) | |
468 | AT_CHECK_JAVA_GREP([[class PrefixParser]]) | |
469 | ||
470 | AT_CHECK_JAVA_MINIMAL([[%define parser_class_name "ParserClassName"]]) | |
471 | AT_CHECK_JAVA_GREP([[class ParserClassName]]) | |
472 | ||
473 | AT_CHECK_JAVA_MINIMAL([[%define package "user_java_package"]]) | |
474 | AT_CHECK_JAVA_GREP([[package user_java_package;]]) | |
475 | ||
476 | AT_CLEANUP | |
477 | ||
478 | ||
479 | # --------------------------- # | |
480 | # Java parser class modifiers # | |
481 | # --------------------------- # | |
482 | ||
483 | AT_SETUP([Java parser class modifiers]) | |
484 | ||
485 | AT_CHECK_JAVA_MINIMAL([[%define abstract]]) | |
486 | AT_CHECK_JAVA_GREP([[abstract class YYParser]]) | |
487 | ||
488 | AT_CHECK_JAVA_MINIMAL([[%define final]]) | |
489 | AT_CHECK_JAVA_GREP([[final class YYParser]]) | |
490 | ||
491 | AT_CHECK_JAVA_MINIMAL([[%define strictfp]]) | |
492 | AT_CHECK_JAVA_GREP([[strictfp class YYParser]]) | |
493 | ||
494 | AT_CHECK_JAVA_MINIMAL([[ | |
495 | %define abstract | |
496 | %define strictfp]]) | |
497 | AT_CHECK_JAVA_GREP([[abstract strictfp class YYParser]]) | |
498 | ||
499 | AT_CHECK_JAVA_MINIMAL([[ | |
500 | %define final | |
501 | %define strictfp]]) | |
502 | AT_CHECK_JAVA_GREP([[final strictfp class YYParser]]) | |
503 | ||
504 | AT_CHECK_JAVA_MINIMAL([[%define public]]) | |
505 | AT_CHECK_JAVA_GREP([[public class YYParser]]) | |
506 | ||
507 | AT_CHECK_JAVA_MINIMAL([[ | |
508 | %define public | |
509 | %define abstract]]) | |
510 | AT_CHECK_JAVA_GREP([[public abstract class YYParser]]) | |
511 | ||
512 | AT_CHECK_JAVA_MINIMAL([[ | |
513 | %define public | |
514 | %define final]]) | |
515 | AT_CHECK_JAVA_GREP([[public final class YYParser]]) | |
516 | ||
517 | AT_CHECK_JAVA_MINIMAL([[ | |
518 | %define public | |
519 | %define strictfp]]) | |
520 | AT_CHECK_JAVA_GREP([[public strictfp class YYParser]]) | |
521 | ||
522 | AT_CHECK_JAVA_MINIMAL([[ | |
523 | %define public | |
524 | %define abstract | |
525 | %define strictfp]]) | |
526 | AT_CHECK_JAVA_GREP([[public abstract strictfp class YYParser]]) | |
527 | ||
528 | AT_CHECK_JAVA_MINIMAL([[ | |
529 | %define public | |
530 | %define final | |
531 | %define strictfp]]) | |
532 | AT_CHECK_JAVA_GREP([[public final strictfp class YYParser]]) | |
533 | ||
534 | AT_CLEANUP | |
535 | ||
536 | ||
537 | # ---------------------------------------- # | |
538 | # Java parser class extends and implements # | |
539 | # ---------------------------------------- # | |
540 | ||
541 | AT_SETUP([Java parser class extends and implements]) | |
542 | ||
543 | AT_CHECK_JAVA_MINIMAL([[%define extends "Thread"]]) | |
544 | AT_CHECK_JAVA_GREP([[class YYParser extends Thread]]) | |
545 | ||
546 | AT_CHECK_JAVA_MINIMAL([[%define implements "Cloneable"]]) | |
547 | AT_CHECK_JAVA_GREP([[class YYParser implements Cloneable]]) | |
548 | ||
549 | AT_CHECK_JAVA_MINIMAL([[ | |
550 | %define extends "Thread" | |
551 | %define implements "Cloneable"]]) | |
552 | AT_CHECK_JAVA_GREP([[class YYParser extends Thread implements Cloneable]]) | |
553 | ||
554 | AT_CLEANUP | |
555 | ||
556 | ||
557 | # -------------------------------- # | |
558 | # Java %parse-param and %lex-param # | |
559 | # -------------------------------- # | |
560 | ||
561 | AT_SETUP([Java %parse-param and %lex-param]) | |
562 | ||
563 | AT_CHECK_JAVA_MINIMAL([]) | |
564 | AT_CHECK_JAVA_GREP([[ *public YYParser (Lexer yylexer) {]]) | |
565 | ||
566 | AT_CHECK_JAVA_MINIMAL([[%parse-param {int parse_param1}]]) | |
567 | AT_CHECK_JAVA_GREP([[ *protected final int parse_param1;]]) | |
568 | AT_CHECK_JAVA_GREP([[ *public YYParser (Lexer yylexer, *int parse_param1) {]]) | |
569 | AT_CHECK_JAVA_GREP([[[ ]*this.parse_param1 = parse_param1;]]) | |
570 | ||
571 | AT_CHECK_JAVA_MINIMAL([[ | |
572 | %parse-param {int parse_param1} | |
573 | %parse-param {long parse_param2}]]) | |
574 | AT_CHECK_JAVA_GREP([[ *protected final int parse_param1;]]) | |
575 | AT_CHECK_JAVA_GREP([[ *protected final long parse_param2;]]) | |
576 | AT_CHECK_JAVA_GREP([[ *public YYParser (Lexer yylexer, *int parse_param1, *long parse_param2) {]]) | |
577 | AT_CHECK_JAVA_GREP([[[ ]*this.parse_param1 = parse_param1;]]) | |
578 | AT_CHECK_JAVA_GREP([[[ ]*this.parse_param2 = parse_param2;]]) | |
579 | ||
580 | AT_CHECK_JAVA_MINIMAL_W_LEXER([], [], [[return EOF;]]) | |
581 | AT_CHECK_JAVA_GREP([[ *public YYParser () {]]) | |
582 | AT_CHECK_JAVA_GREP([[ *protected YYParser (Lexer yylexer) {]]) | |
583 | ||
584 | AT_CHECK_JAVA_MINIMAL_W_LEXER([[%parse-param {int parse_param1}]], | |
585 | [], [[return EOF;]]) | |
586 | AT_CHECK_JAVA_GREP([[ *protected final int parse_param1;]]) | |
587 | AT_CHECK_JAVA_GREP([[ *public YYParser (int parse_param1) {]]) | |
588 | AT_CHECK_JAVA_GREP([[ *protected YYParser (Lexer yylexer, *int parse_param1) {]]) | |
589 | AT_CHECK_JAVA_GREP([[[ ]*this.parse_param1 = parse_param1;]], [2]) | |
590 | ||
591 | AT_CHECK_JAVA_MINIMAL_W_LEXER([[ | |
592 | %parse-param {int parse_param1} | |
593 | %parse-param {long parse_param2}]], | |
594 | [], [[return EOF;]]) | |
595 | AT_CHECK_JAVA_GREP([[ *protected final int parse_param1;]]) | |
596 | AT_CHECK_JAVA_GREP([[ *protected final long parse_param2;]]) | |
597 | AT_CHECK_JAVA_GREP([[ *public YYParser (int parse_param1, *long parse_param2) {]]) | |
598 | AT_CHECK_JAVA_GREP([[ *protected YYParser (Lexer yylexer, *int parse_param1, *long parse_param2) {]]) | |
599 | AT_CHECK_JAVA_GREP([[[ ]*this.parse_param1 = parse_param1;]], [2]) | |
600 | AT_CHECK_JAVA_GREP([[[ ]*this.parse_param2 = parse_param2;]], [2]) | |
601 | ||
602 | AT_CHECK_JAVA_MINIMAL_W_LEXER([[%lex-param {char lex_param1}]], | |
603 | [], [[return EOF;]], [[YYLexer (char lex_param1) {}]]) | |
604 | AT_CHECK_JAVA_GREP([[ *public YYParser (char lex_param1) {]]) | |
605 | AT_CHECK_JAVA_GREP([[.* = new YYLexer *(lex_param1);]]) | |
606 | ||
607 | AT_CHECK_JAVA_MINIMAL_W_LEXER([[ | |
608 | %lex-param {char lex_param1} | |
609 | %lex-param {short lex_param2}]], | |
610 | [], [[return EOF;]], [[YYLexer (char lex_param1, short lex_param2) {}]]) | |
611 | AT_CHECK_JAVA_GREP([[ *public YYParser (char lex_param1, *short lex_param2) {]]) | |
612 | AT_CHECK_JAVA_GREP([[.* = new YYLexer *(lex_param1, *lex_param2);]]) | |
613 | ||
614 | AT_CHECK_JAVA_MINIMAL_W_LEXER([[ | |
615 | %parse-param {int parse_param1} | |
616 | %parse-param {long parse_param2} | |
617 | %lex-param {char lex_param1} | |
618 | %lex-param {short lex_param2}]], | |
619 | [], [[return EOF;]], [[YYLexer (char lex_param1, short lex_param2) {}]]) | |
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 (char lex_param1, *short lex_param2, *int parse_param1, *long parse_param2) {]]) | |
623 | AT_CHECK_JAVA_GREP([[.* = new YYLexer *(lex_param1, *lex_param2);]]) | |
624 | AT_CHECK_JAVA_GREP([[ *protected YYParser (Lexer yylexer, *int parse_param1, *long parse_param2) {]]) | |
625 | AT_CHECK_JAVA_GREP([[[ ]*this.parse_param1 = parse_param1;]], [2]) | |
626 | AT_CHECK_JAVA_GREP([[[ ]*this.parse_param2 = parse_param2;]], [2]) | |
627 | ||
628 | AT_CLEANUP | |
629 | ||
630 | ||
631 | # ------------------------- # | |
632 | # Java throw specifications # | |
633 | # ------------------------- # | |
634 | ||
635 | AT_SETUP([Java throws specifications]) | |
636 | ||
637 | # %define throws - 0 1 2 | |
638 | # %define lex-throws - 0 1 2 | |
639 | # %code lexer 0 1 | |
640 | ||
641 | m4_define([AT_JT_lex_throws_define], [m4_case(AT_JT_lex_throws, | |
642 | -1, [], | |
643 | 0, [[%define lex_throws ""]], | |
644 | 1, [[%define lex_throws "InterruptedException"]], | |
645 | 2, [[%define lex_throws "InterruptedException, IllegalAccessException"]])]) | |
646 | ||
647 | m4_define([AT_JT_yylex_throws], [m4_case(AT_JT_lex_throws, | |
648 | -1, [[ throws java.io.IOException]], | |
649 | 0, [], | |
650 | 1, [[ throws InterruptedException]], | |
651 | 2, [[ throws InterruptedException, IllegalAccessException]])]) | |
652 | ||
653 | m4_define([AT_JT_yylex_action], [m4_case(AT_JT_lex_throws, | |
654 | -1, [[throw new java.io.IOException();]], | |
655 | 0, [[return EOF;]], | |
656 | 1, [[throw new InterruptedException();]], | |
657 | 2, [[throw new IllegalAccessException();]])]) | |
658 | ||
659 | ||
660 | m4_define([AT_JT_throws_define], [m4_case(AT_JT_throws, | |
661 | -1, [], | |
662 | 0, [[%define throws ""]], | |
663 | 1, [[%define throws "ClassNotFoundException"]], | |
664 | 2, [[%define throws "ClassNotFoundException, InstantiationException"]])]) | |
665 | ||
666 | m4_define([AT_JT_yyaction_throws], [m4_case(AT_JT_throws, | |
667 | -1, [], | |
668 | 0, [], | |
669 | 1, [[ throws ClassNotFoundException]], | |
670 | 2, [[ throws ClassNotFoundException, InstantiationException]])]) | |
671 | ||
672 | m4_define([AT_JT_parse_throws_2], [m4_case(AT_JT_throws, | |
673 | -1, [], | |
674 | 0, [], | |
675 | 1, [[, ClassNotFoundException]], | |
676 | 2, [[, ClassNotFoundException, InstantiationException]])]) | |
677 | ||
678 | m4_define([AT_JT_parse_throws], | |
679 | [m4_if(m4_quote(AT_JT_yylex_throws), [], | |
680 | [AT_JT_yyaction_throws], | |
681 | [AT_JT_yylex_throws[]AT_JT_parse_throws_2])]) | |
682 | ||
683 | m4_define([AT_JT_initial_action], [m4_case(AT_JT_throws, | |
684 | -1, [], | |
685 | 0, [], | |
686 | 1, [[%initial-action {if (true) throw new ClassNotFoundException();}]], | |
687 | 2, [[%initial-action {if (true) throw new InstantiationException();}]])]) | |
688 | ||
689 | m4_define([AT_JT_parse_action], [m4_case(AT_JT_throws, | |
690 | -1, [], | |
691 | 0, [], | |
692 | 1, [[throw new ClassNotFoundException();]], | |
693 | 2, [[throw new ClassNotFoundException();]])]) | |
694 | ||
695 | m4_for([AT_JT_lexer], 0, 1, 1, | |
696 | [m4_for([AT_JT_lex_throws], -1, 2, 1, | |
697 | [m4_for([AT_JT_throws], -1, 2, 1, | |
698 | [m4_if(AT_JT_lexer, 0, | |
699 | [AT_CHECK_JAVA_MINIMAL([ | |
700 | AT_JT_throws_define | |
701 | AT_JT_lex_throws_define | |
702 | AT_JT_initial_action], | |
703 | [AT_JT_parse_action])], | |
704 | [AT_CHECK_JAVA_MINIMAL_W_LEXER([ | |
705 | AT_JT_throws_define | |
706 | AT_JT_lex_throws_define | |
707 | AT_JT_initial_action], | |
708 | [AT_JT_yylex_throws], | |
709 | [AT_JT_yylex_action], | |
710 | [], | |
711 | [AT_JT_parse_action])]) | |
712 | AT_CHECK_JAVA_GREP([[ *int yylex ()]AT_JT_yylex_throws *[;]]) | |
713 | AT_CHECK_JAVA_GREP([[ *private int yyaction ([^)]*)]AT_JT_yyaction_throws[ *]]) | |
714 | AT_CHECK_JAVA_GREP([[ *public boolean parse ()]AT_JT_parse_throws[ *]]) | |
715 | ])])]) | |
716 | ||
717 | AT_CLEANUP | |
718 | ||
719 | ||
720 | # --------------------------------------------- # | |
721 | # Java stype, position_class and location_class # | |
722 | # --------------------------------------------- # | |
723 | ||
724 | AT_SETUP([Java stype, position_class and location_class]) | |
725 | ||
726 | AT_CHECK_JAVA_MINIMAL([[ | |
727 | %define stype "java.awt.Color" | |
728 | %type<java.awt.Color> start; | |
729 | %define location_type "MyLoc" | |
730 | %define position_type "MyPos" | |
731 | %code { class MyPos {} }]], [[$$ = $<java.awt.Color>1;]], [[MyPos]]) | |
8defe11b AD |
732 | AT_CHECK([[grep 'java.awt.Color' YYParser.java]], [0], [ignore]) |
733 | AT_CHECK([[$EGREP -v ' */?\*' YYParser.java | grep 'Position']], [1], [ignore]) | |
734 | AT_CHECK([[$EGREP -v ' */?\*' YYParser.java | grep 'Location']], [1], [ignore]) | |
e254a580 DJ |
735 | |
736 | AT_CHECK_JAVA_MINIMAL_W_LEXER([[ | |
737 | %define stype "java.awt.Color" | |
738 | %type<java.awt.Color> start; | |
739 | %define location_type "MyLoc" | |
740 | %define position_type "MyPos" | |
741 | %code { class MyPos {} }]], [], [[return EOF;]], [], | |
742 | [[$$ = $<java.awt.Color>1;]], | |
743 | [[java.awt.Color]], [[MyPos]], [[MyLoc]]) | |
8defe11b AD |
744 | AT_CHECK([[grep 'java.awt.Color' YYParser.java]], [0], [ignore]) |
745 | AT_CHECK([[$EGREP -v ' */?\*' YYParser.java | grep 'Position']], [1], [ignore]) | |
746 | AT_CHECK([[$EGREP -v ' */?\*' YYParser.java | grep 'Location']], [1], [ignore]) | |
e254a580 DJ |
747 | |
748 | AT_CLEANUP |