]> git.saurik.com Git - bison.git/blob - tests/javapush.at
tests: java: avoid recent Java features
[bison.git] / tests / javapush.at
1 # Checking Java Push Parsing. -*- Autotest -*-
2
3 # Copyright (C) 2013-2015 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 # The Java push parser tests are intended primarily
19 # to verify that the sequence of states that the parser
20 # traverses is the same as a pull parser would traverse.
21
22 ##################################################
23 # Provide a way to generate data with and without push parsing
24 # so it is possible to capture the output for comparison
25 # (except the "trivial" tests).
26 # Use "both" rather than "push" so we can also set it to "pull" to
27 # get the "experr" data.
28
29 m4_define([PUSHPULLFLAG],[-Dapi.push-pull=both])
30
31 # AT_CHECK_JAVA_GREP(FILE, [LINE], [COUNT=1])
32 # -------------------------------------------
33 # Check that FILE contains exactly COUNT lines matching ^LINE$
34 # with grep. Unquoted so that COUNT can be a shell expression.
35 m4_define([AT_CHECK_JAVA_GREP],
36 [AT_CHECK_UNQUOTED([grep -c '^$2$' $1], [ignore], [m4_default([$3], [1])
37 ])])
38
39 ##################################################
40
41 AT_BANNER([[Java Push Parsing Tests]])
42
43 # Define a single copy of the trivial parser grammar.
44 # This is missing main(), so two versions
45 # are instantiated with different main() procedures.
46 m4_define([AT_TRIVIAL_GRAMMAR],[
47 %define parser_class_name {YYParser}
48 %error-verbose
49
50 %code imports {
51 import java.io.*;
52 import java.util.*;
53 }
54
55 %%
56
57 start: 'a' 'b' 'c' ;
58
59 %%
60 ])
61
62 # Define comon code across to be includede in
63 # class Main for the trivial parser tests.
64 m4_define([AT_TRIVIAL_COMMON],[
65 static class YYerror implements YYParser.Lexer
66 {
67 public Object getLVal() {return null;}
68 public int yylex () throws java.io.IOException { return 0; }
69 public void yyerror (String msg) { System.err.println(msg); }
70 }
71
72 static YYParser parser = null;
73 static YYerror yyerror = null;
74 static int teststate = -1;
75
76 static void setup()
77 throws IOException
78 {
79 yyerror = new YYerror();
80 parser = new YYParser(yyerror);
81 parser.setDebugLevel(1);
82 teststate = -1;
83 }
84
85 static String[[]] teststatename
86 = new String[[]]{"YYACCEPT","YYABORT","YYERROR","UNKNOWN","YYPUSH_MORE"};
87
88 static void check(int teststate, int expected, String msg)
89 {
90 System.err.println("teststate="+teststatename[[teststate]]
91 +"; expected="+teststatename[[expected]]);
92 if (teststate == expected)
93 return;
94 System.err.println("unexpected state: "+msg);
95 System.exit(1);
96 }
97 ])
98
99 m4_define([AT_TRIVIAL_PARSER],[
100 AT_TRIVIAL_GRAMMAR
101
102 public class Main
103 {
104
105 AT_TRIVIAL_COMMON
106
107 static public void main (String[[]] argv)
108 throws IOException
109 {
110 setup();
111
112 teststate = parser.push_parse('a', null);
113 check(teststate,YYParser.YYPUSH_MORE,"push_parse('a', null)");
114
115 setup();
116
117 teststate = parser.push_parse('a', null);
118 check(teststate,YYParser.YYPUSH_MORE,"push_parse('a', null)");
119 teststate = parser.push_parse('b', null);
120 check(teststate,YYParser.YYPUSH_MORE,"push_parse('b', null)");
121 teststate = parser.push_parse('c', null);
122 check(teststate,YYParser.YYPUSH_MORE,"push_parse('c', null)");
123 teststate = parser.push_parse('\0', null);
124 check(teststate,YYParser.YYACCEPT,"push_parse('\\0', null)");
125
126 /* Reuse the parser instance and cause a failure */
127 teststate = parser.push_parse('b', null);
128 check(teststate,YYParser.YYABORT,"push_parse('b', null)");
129
130 System.exit(0);
131 }
132
133 }
134 ])
135
136 m4_define([AT_TRIVIAL_PARSER_INITIAL_ACTION],[
137 AT_TRIVIAL_GRAMMAR
138
139 public class Main
140 {
141
142 AT_TRIVIAL_COMMON
143
144 static public void main (String[[]] argv)
145 throws IOException
146 {
147 setup();
148
149 teststate = parser.push_parse('a', null);
150 check(teststate,YYParser.YYPUSH_MORE,"push_parse('a', null)");
151 teststate = parser.push_parse('b', null);
152 check(teststate,YYParser.YYPUSH_MORE,"push_parse('b', null)");
153 teststate = parser.push_parse('c', null);
154 check(teststate,YYParser.YYPUSH_MORE,"push_parse('c', null)");
155 teststate = parser.push_parse('\0', null);
156 check(teststate,YYParser.YYACCEPT,"push_parse('\\0', null)");
157
158 System.exit(0);
159 }
160
161 }
162 ])
163
164 ## ----------------------------------------------------- ##
165 ## Trivial Push Parser with api.push-pull verification. ##
166 ## ----------------------------------------------------- ##
167
168 AT_SETUP([Trivial Push Parser with api.push-pull verification])
169 AT_BISON_OPTION_PUSHDEFS
170
171 AT_DATA([[input.y]],
172 [[%language "Java"
173 ]AT_TRIVIAL_PARSER[
174 ]])
175
176 # Verify that the proper procedure(s) are generated for each case.
177 AT_BISON_CHECK([[-Dapi.push-pull=pull -o Main.java input.y]])
178 AT_CHECK_JAVA_GREP([[Main.java]],
179 [[.*public boolean parse ().*]],
180 [1])
181 # If BISON_USE_PUSH_FOR_PULL is set, then we have one occurrence of
182 # this function, otherwise it should not be there.
183 AT_CHECK_JAVA_GREP([[Main.java]],
184 [[.*public int push_parse (int yylextoken, Object yylexval).*]],
185 [${BISON_USE_PUSH_FOR_PULL-0}])
186
187 AT_BISON_CHECK([[-Dapi.push-pull=both -o Main.java input.y]])
188 AT_CHECK_JAVA_GREP([[Main.java]],
189 [[.*public boolean parse ().*]],
190 [1])
191 AT_CHECK_JAVA_GREP([[Main.java]],
192 [[.*public int push_parse (int yylextoken, Object yylexval).*]],
193 [1])
194
195 AT_BISON_CHECK([[-Dapi.push-pull=push -o Main.java input.y]])
196 AT_CHECK_JAVA_GREP([[Main.java]],
197 [[.*public boolean parse ().*]],
198 [0])
199 AT_CHECK_JAVA_GREP([[Main.java]],
200 [[.*public int push_parse (int yylextoken, Object yylexval).*]],
201 [1])
202
203 AT_JAVA_COMPILE([[Main.java]])
204 AT_JAVA_PARSER_CHECK([Main], 0, [], [stderr-nolog])
205 AT_BISON_OPTION_POPDEFS
206 AT_CLEANUP
207
208
209 ## ------------------------------------------ ##
210 ## Trivial Push Parser with %initial-action. ##
211 ## ------------------------------------------ ##
212
213 AT_SETUP([Trivial Push Parser with %initial-action])
214 AT_BISON_OPTION_PUSHDEFS
215 AT_DATA([[input.y]],[[%language "Java"
216 %initial-action {
217 System.err.println("Initial action invoked");
218 }
219 ]AT_TRIVIAL_PARSER_INITIAL_ACTION[
220 ]])
221 AT_BISON_OPTION_POPDEFS
222 AT_BISON_CHECK([[-Dapi.push-pull=push -o Main.java input.y]])
223 AT_CHECK_JAVA_GREP([[Main.java]],
224 [[System.err.println("Initial action invoked");]])
225 AT_JAVA_COMPILE([[Main.java]])
226 AT_JAVA_PARSER_CHECK([Main], 0, [], [stderr-nolog])
227 # Verify that initial action is called exactly once.
228 AT_CHECK_JAVA_GREP(
229 [[stderr]],
230 [[Initial action invoked]],
231 [1])
232 AT_CLEANUP
233
234 # Define a single copy of the Calculator grammar.
235 m4_define([AT_CALC_BODY],[
236 %code imports {
237 import java.io.*;
238 }
239
240 %code {
241 static StringReader
242 getinput(String filename) throws IOException
243 {
244 // Yes, there are better alternatives to StringBuffer. But we
245 // don't really care about performances here, while portability
246 // to older Java matters.
247 StringBuffer buf = new StringBuffer();
248 FileReader file = new FileReader(filename);
249 int c;
250 while (0 < (c = file.read()))
251 buf.append((char)c);
252 file.close();
253 return new StringReader(buf.toString());
254 }
255 }
256
257 /* Bison Declarations */
258 %token <Integer> NUM "number"
259 %type <Integer> exp
260
261 %nonassoc '=' /* comparison */
262 %left '-' '+'
263 %left '*' '/'
264 %left NEG /* negation--unary minus */
265 %right '^' /* exponentiation */
266
267 /* Grammar follows */
268 %%
269 input:
270 line
271 | input line
272 ;
273
274 line:
275 '\n'
276 | exp '\n'
277 {System.out.println("total = "+$[]1);}
278 | error '\n'
279 ;
280
281 exp:
282 NUM { $[]$ = $[]1;}
283 | exp '=' exp
284 {
285 if ($[]1.intValue() != $[]3.intValue())
286 yyerror (]AT_LOCATION_IF([[@$,]])[ "calc: error: " + $[]1 + " != " + $[]3);
287 }
288 | exp '+' exp
289 { $[]$ = new Integer ($[]1.intValue () + $[]3.intValue ()); }
290 | exp '-' exp
291 { $[]$ = new Integer ($[]1.intValue () - $[]3.intValue ()); }
292 | exp '*' exp
293 { $[]$ = new Integer ($[]1.intValue () * $[]3.intValue ()); }
294 | exp '/' exp
295 { $[]$ = new Integer ($[]1.intValue () / $[]3.intValue ()); }
296 | '-' exp %prec NEG
297 { $[]$ = new Integer (-$[]2.intValue ()); }
298 | exp '^' exp
299 { $[]$ = new Integer ((int)Math.pow ($[]1.intValue (),
300 $[]3.intValue ())); }
301 | '(' exp ')' { $[]$ = $[]2;}
302 | '(' error ')' { $[]$ = new Integer (1111);}
303 | '!' { $[]$ = new Integer (0); return YYERROR;}
304 | '-' error { $[]$ = new Integer (0); return YYERROR;}
305 ;
306 ])
307
308
309
310 ## ------------------------------------- ##
311 ## Calc parser with api.push-pull both. ##
312 ## ------------------------------------- ##
313
314
315 # Test that the states transitioned by the push parser are the
316 # same as for the pull parser. This test is assumed to work
317 # if it produces the same partial trace of stack states as is
318 # produced when using pull parsing. The output is verbose,
319 # but seems essential for verifying push parsing.
320
321 AT_SETUP([Calc parser with api.push-pull both])
322 AT_BISON_OPTION_PUSHDEFS
323
324 # Define the calculator input.
325 # Warning: if you changes the input file
326 # then the locations test file position numbers
327 # may be incorrect and you will have
328 # to modify that file as well.
329
330 AT_DATA([input],[[1 + 2 * 3 = 7
331 1 + 2 * -3 = -5
332
333 -1^2 = -1
334 (-1)^2 = 1
335
336 ---1 = -1
337
338 1 - 2 - 3 = -4
339 1 - (2 - 3) = 2
340
341 2^2^3 = 256
342 (2^2)^3 = 64
343 ]])
344
345 # Compose pieces to build the actual .y file.
346 AT_DATA([Calc.y],[[/* Infix notation calculator--calc */
347 %language "Java"
348 %name-prefix "Calc"
349 %define parser_class_name {Calc}
350
351 %code {
352 static class UserLexer implements Calc.Lexer
353 {
354 StreamTokenizer st;
355 StringReader rdr;
356
357 public UserLexer(StringReader reader)
358 {
359 rdr = reader;
360 st = new StreamTokenizer(rdr);
361 st.resetSyntax();
362 st.eolIsSignificant(true);
363 st.whitespaceChars(9, 9);
364 st.whitespaceChars(32, 32);
365 st.wordChars(48, 57);
366 }
367
368 Integer yylval;
369
370 public Object getLVal() { return yylval; }
371
372 public void yyerror(String msg) { System.err.println(msg); }
373
374 public int yylex () throws IOException
375 {
376 switch (st.nextToken()) {
377 case StreamTokenizer.TT_EOF: return EOF;
378 case StreamTokenizer.TT_EOL: return (int) '\n';
379 case StreamTokenizer.TT_WORD:
380 yylval = new Integer (st.sval);
381 return NUM;
382 default: return st.ttype;
383 }
384 }
385 }
386
387 }
388
389 %code {
390 public static void main (String[] argv)
391 throws IOException
392 {
393 StringReader reader = getinput(argv[0]);
394 UserLexer lexer = new UserLexer(reader);
395 Calc calc = new Calc(lexer);
396 calc.setDebugLevel(1);
397 calc.parse();
398 }//main
399
400 }
401
402 ]AT_CALC_BODY[
403
404 ]])
405
406 # This data was captured from running a pull parser.
407 AT_DATA([[expout]],[[Stack now 0
408 Stack now 0 2
409 Stack now 0 9
410 Stack now 0 9 19
411 Stack now 0 9 19 2
412 Stack now 0 9 19 28
413 Stack now 0 9 19 28 20
414 Stack now 0 9 19 28 20 2
415 Stack now 0 9 19 28 20 29
416 Stack now 0 9 19 28
417 Stack now 0 9
418 Stack now 0 9 17
419 Stack now 0 9 17 2
420 Stack now 0 9 17 26
421 Stack now 0 9
422 Stack now 0 9 23
423 Stack now 0 8
424 Stack now 0 7
425 Stack now 0 7 2
426 Stack now 0 7 9
427 Stack now 0 7 9 19
428 Stack now 0 7 9 19 2
429 Stack now 0 7 9 19 28
430 Stack now 0 7 9 19 28 20
431 Stack now 0 7 9 19 28 20 3
432 Stack now 0 7 9 19 28 20 3 2
433 Stack now 0 7 9 19 28 20 3 12
434 Stack now 0 7 9 19 28 20 29
435 Stack now 0 7 9 19 28
436 Stack now 0 7 9
437 Stack now 0 7 9 17
438 Stack now 0 7 9 17 3
439 Stack now 0 7 9 17 3 2
440 Stack now 0 7 9 17 3 12
441 Stack now 0 7 9 17 26
442 Stack now 0 7 9
443 Stack now 0 7 9 23
444 Stack now 0 7 16
445 Stack now 0 7
446 Stack now 0 7 4
447 Stack now 0 7 16
448 Stack now 0 7
449 Stack now 0 7 3
450 Stack now 0 7 3 2
451 Stack now 0 7 3 12
452 Stack now 0 7 3 12 22
453 Stack now 0 7 3 12 22 2
454 Stack now 0 7 3 12 22 31
455 Stack now 0 7 3 12
456 Stack now 0 7 9
457 Stack now 0 7 9 17
458 Stack now 0 7 9 17 3
459 Stack now 0 7 9 17 3 2
460 Stack now 0 7 9 17 3 12
461 Stack now 0 7 9 17 26
462 Stack now 0 7 9
463 Stack now 0 7 9 23
464 Stack now 0 7 16
465 Stack now 0 7
466 Stack now 0 7 5
467 Stack now 0 7 5 3
468 Stack now 0 7 5 3 2
469 Stack now 0 7 5 3 12
470 Stack now 0 7 5 14
471 Stack now 0 7 5 14 25
472 Stack now 0 7 9
473 Stack now 0 7 9 22
474 Stack now 0 7 9 22 2
475 Stack now 0 7 9 22 31
476 Stack now 0 7 9
477 Stack now 0 7 9 17
478 Stack now 0 7 9 17 2
479 Stack now 0 7 9 17 26
480 Stack now 0 7 9
481 Stack now 0 7 9 23
482 Stack now 0 7 16
483 Stack now 0 7
484 Stack now 0 7 4
485 Stack now 0 7 16
486 Stack now 0 7
487 Stack now 0 7 3
488 Stack now 0 7 3 3
489 Stack now 0 7 3 3 3
490 Stack now 0 7 3 3 3 2
491 Stack now 0 7 3 3 3 12
492 Stack now 0 7 3 3 12
493 Stack now 0 7 3 12
494 Stack now 0 7 9
495 Stack now 0 7 9 17
496 Stack now 0 7 9 17 3
497 Stack now 0 7 9 17 3 2
498 Stack now 0 7 9 17 3 12
499 Stack now 0 7 9 17 26
500 Stack now 0 7 9
501 Stack now 0 7 9 23
502 Stack now 0 7 16
503 Stack now 0 7
504 Stack now 0 7 4
505 Stack now 0 7 16
506 Stack now 0 7
507 Stack now 0 7 2
508 Stack now 0 7 9
509 Stack now 0 7 9 18
510 Stack now 0 7 9 18 2
511 Stack now 0 7 9 18 27
512 Stack now 0 7 9
513 Stack now 0 7 9 18
514 Stack now 0 7 9 18 2
515 Stack now 0 7 9 18 27
516 Stack now 0 7 9
517 Stack now 0 7 9 17
518 Stack now 0 7 9 17 3
519 Stack now 0 7 9 17 3 2
520 Stack now 0 7 9 17 3 12
521 Stack now 0 7 9 17 26
522 Stack now 0 7 9
523 Stack now 0 7 9 23
524 Stack now 0 7 16
525 Stack now 0 7
526 Stack now 0 7 2
527 Stack now 0 7 9
528 Stack now 0 7 9 18
529 Stack now 0 7 9 18 5
530 Stack now 0 7 9 18 5 2
531 Stack now 0 7 9 18 5 14
532 Stack now 0 7 9 18 5 14 18
533 Stack now 0 7 9 18 5 14 18 2
534 Stack now 0 7 9 18 5 14 18 27
535 Stack now 0 7 9 18 5 14
536 Stack now 0 7 9 18 5 14 25
537 Stack now 0 7 9 18 27
538 Stack now 0 7 9
539 Stack now 0 7 9 17
540 Stack now 0 7 9 17 2
541 Stack now 0 7 9 17 26
542 Stack now 0 7 9
543 Stack now 0 7 9 23
544 Stack now 0 7 16
545 Stack now 0 7
546 Stack now 0 7 4
547 Stack now 0 7 16
548 Stack now 0 7
549 Stack now 0 7 2
550 Stack now 0 7 9
551 Stack now 0 7 9 22
552 Stack now 0 7 9 22 2
553 Stack now 0 7 9 22 31
554 Stack now 0 7 9 22 31 22
555 Stack now 0 7 9 22 31 22 2
556 Stack now 0 7 9 22 31 22 31
557 Stack now 0 7 9 22 31
558 Stack now 0 7 9
559 Stack now 0 7 9 17
560 Stack now 0 7 9 17 2
561 Stack now 0 7 9 17 26
562 Stack now 0 7 9
563 Stack now 0 7 9 23
564 Stack now 0 7 16
565 Stack now 0 7
566 Stack now 0 7 5
567 Stack now 0 7 5 2
568 Stack now 0 7 5 14
569 Stack now 0 7 5 14 22
570 Stack now 0 7 5 14 22 2
571 Stack now 0 7 5 14 22 31
572 Stack now 0 7 5 14
573 Stack now 0 7 5 14 25
574 Stack now 0 7 9
575 Stack now 0 7 9 22
576 Stack now 0 7 9 22 2
577 Stack now 0 7 9 22 31
578 Stack now 0 7 9
579 Stack now 0 7 9 17
580 Stack now 0 7 9 17 2
581 Stack now 0 7 9 17 26
582 Stack now 0 7 9
583 Stack now 0 7 9 23
584 Stack now 0 7 16
585 Stack now 0 7
586 Stack now 0 7 15
587 ]])
588
589 AT_BISON_CHECK([PUSHPULLFLAG [-o Calc.java Calc.y]])
590
591 AT_JAVA_COMPILE([[Calc.java]])
592 # Verify that this is a push parser.
593 AT_CHECK_JAVA_GREP([[Calc.java]],
594 [[.*public void push_parse_initialize().*]])
595 # Capture stderr output for comparison purposes.
596 AT_JAVA_PARSER_CHECK([Calc input], 0, [ignore-nolog], [stderr-nolog])
597 # Extract the "Stack Now" lines from the error output,
598 # send them to stdout (via the sed command) and compare to expout.
599 # NOTE: because the target is "expout", this macro automatically
600 # compares the output of the sed command with the contents of
601 # the file "expout" (defined above).
602 AT_CHECK([[sed -e '/^Stack now.*$/p' -e d ./stderr]],
603 [ignore], [expout], [ignore-nolog])
604 AT_BISON_OPTION_POPDEFS
605 AT_CLEANUP
606
607
608
609 ## ---------------------------------------------------------------- ##
610 ## Calc parser with %locations %code lexer and api.push-pull both. ##
611 ## ---------------------------------------------------------------- ##
612
613
614 # This test looks for location reporting by looking
615 # at the lexer output with locations enabled.
616 # It defines a lexer that reports location info.
617 AT_SETUP([Calc parser with %locations %code lexer and api.push-pull both])
618 AT_BISON_OPTION_PUSHDEFS
619
620 AT_DATA([Calc.y],[[/* Infix notation calculator--calc. */
621 %language "Java"
622 %name-prefix "Calc"
623 %define parser_class_name {Calc}
624 %lex-param { Reader rdr }
625 %locations
626
627 %code imports {
628 import java.io.*;
629 }
630
631 %code lexer {
632 StreamTokenizer st;
633 Integer yylval;
634
635 public YYLexer(Reader rdr)
636 {
637 st = new StreamTokenizer(rdr);
638 st.resetSyntax();
639 st.eolIsSignificant(true);
640 st.whitespaceChars(9, 9);
641 st.whitespaceChars(32, 32);
642 st.wordChars(48, 57);
643 }
644
645 Position yypos = new Position (1, 0);
646
647 public Position getStartPos() { return yypos; }
648
649 public Position getEndPos() { return yypos; }
650
651 public Object getLVal() { return yylval; }
652
653 public void yyerror(Location loc, String msg)
654 {
655 System.err.println(loc+":"+msg);
656 }
657
658 public int yylex () throws IOException
659 {
660 yypos = new Position (yypos.lineno (),yypos.token () + 1);
661 switch (st.nextToken()) {
662 case StreamTokenizer.TT_EOF:
663 return EOF;
664 case StreamTokenizer.TT_EOL:
665 yypos = new Position (yypos.lineno () + 1, 0);
666 return (int) '\n';
667 case StreamTokenizer.TT_WORD:
668 yylval = new Integer (st.sval);
669 return NUM;
670 default:
671 return st.ttype;
672 }
673 }
674 }
675
676 %code {
677 class Position {
678 public int line;
679 public int token;
680
681 public Position () { line = 0; token = 0; }
682
683 public Position (int l, int t) { line = l; token = t; }
684
685 public boolean equals (Position l)
686 {
687 return l.line == line && l.token == token;
688 }
689
690 public String toString ()
691 {
692 return Integer.toString(line) + "." + Integer.toString(token);
693 }
694
695 public int lineno () { return line; }
696
697 public int token () { return token; }
698 }//Class Position
699 }
700
701 %code {
702 public static void main (String[] argv)
703 throws IOException
704 {
705 StringReader reader = getinput(argv[0]);
706 Calc calc = new Calc(reader);
707 calc.setDebugLevel(1);
708 calc.parse();
709 }
710 }
711
712 ]AT_CALC_BODY[
713
714 ]])
715
716 # Define the expected calculator output.
717 # This should match the output from a pull parser.
718 AT_DATA([output],[[total = 7
719 total = -5
720 total = -1
721 total = 1
722 total = -1
723 total = -4
724 total = 2
725 total = 256
726 total = 64
727 ]])
728
729 AT_DATA([locations],[[Next token is token "number" (1.1: 1)
730 Next token is token '+' (1.2: 1)
731 Next token is token "number" (1.3: 2)
732 Next token is token '*' (1.4: 2)
733 Next token is token "number" (1.5: 3)
734 Next token is token '=' (1.6: 3)
735 Next token is token '=' (1.6: 3)
736 Next token is token '=' (1.6: 3)
737 Next token is token "number" (1.7: 7)
738 Next token is token '\n' (2.0: 7)
739 Next token is token '\n' (2.0: 7)
740 Next token is token "number" (2.1: 1)
741 Next token is token '+' (2.2: 1)
742 Next token is token "number" (2.3: 2)
743 Next token is token '*' (2.4: 2)
744 Next token is token '-' (2.5: 2)
745 Next token is token "number" (2.6: 3)
746 Next token is token '=' (2.7: 3)
747 Next token is token '=' (2.7: 3)
748 Next token is token '=' (2.7: 3)
749 Next token is token '=' (2.7: 3)
750 Next token is token '-' (2.8: 3)
751 Next token is token "number" (2.9: 5)
752 Next token is token '\n' (3.0: 5)
753 Next token is token '\n' (3.0: 5)
754 Next token is token '\n' (3.0: 5)
755 Next token is token '\n' (4.0: 5)
756 Next token is token '-' (4.1: 5)
757 Next token is token "number" (4.2: 1)
758 Next token is token '^' (4.3: 1)
759 Next token is token "number" (4.4: 2)
760 Next token is token '=' (4.5: 2)
761 Next token is token '=' (4.5: 2)
762 Next token is token '=' (4.5: 2)
763 Next token is token '-' (4.6: 2)
764 Next token is token "number" (4.7: 1)
765 Next token is token '\n' (5.0: 1)
766 Next token is token '\n' (5.0: 1)
767 Next token is token '\n' (5.0: 1)
768 Next token is token '(' (5.1: 1)
769 Next token is token '-' (5.2: 1)
770 Next token is token "number" (5.3: 1)
771 Next token is token ')' (5.4: 1)
772 Next token is token ')' (5.4: 1)
773 Next token is token '^' (5.5: 1)
774 Next token is token "number" (5.6: 2)
775 Next token is token '=' (5.7: 2)
776 Next token is token '=' (5.7: 2)
777 Next token is token "number" (5.8: 1)
778 Next token is token '\n' (6.0: 1)
779 Next token is token '\n' (6.0: 1)
780 Next token is token '\n' (7.0: 1)
781 Next token is token '-' (7.1: 1)
782 Next token is token '-' (7.2: 1)
783 Next token is token '-' (7.3: 1)
784 Next token is token "number" (7.4: 1)
785 Next token is token '=' (7.5: 1)
786 Next token is token '=' (7.5: 1)
787 Next token is token '=' (7.5: 1)
788 Next token is token '=' (7.5: 1)
789 Next token is token '-' (7.6: 1)
790 Next token is token "number" (7.7: 1)
791 Next token is token '\n' (8.0: 1)
792 Next token is token '\n' (8.0: 1)
793 Next token is token '\n' (8.0: 1)
794 Next token is token '\n' (9.0: 1)
795 Next token is token "number" (9.1: 1)
796 Next token is token '-' (9.2: 1)
797 Next token is token "number" (9.3: 2)
798 Next token is token '-' (9.4: 2)
799 Next token is token '-' (9.4: 2)
800 Next token is token "number" (9.5: 3)
801 Next token is token '=' (9.6: 3)
802 Next token is token '=' (9.6: 3)
803 Next token is token '-' (9.7: 3)
804 Next token is token "number" (9.8: 4)
805 Next token is token '\n' (10.0: 4)
806 Next token is token '\n' (10.0: 4)
807 Next token is token '\n' (10.0: 4)
808 Next token is token "number" (10.1: 1)
809 Next token is token '-' (10.2: 1)
810 Next token is token '(' (10.3: 1)
811 Next token is token "number" (10.4: 2)
812 Next token is token '-' (10.5: 2)
813 Next token is token "number" (10.6: 3)
814 Next token is token ')' (10.7: 3)
815 Next token is token ')' (10.7: 3)
816 Next token is token '=' (10.8: 3)
817 Next token is token '=' (10.8: 3)
818 Next token is token "number" (10.9: 2)
819 Next token is token '\n' (11.0: 2)
820 Next token is token '\n' (11.0: 2)
821 Next token is token '\n' (12.0: 2)
822 Next token is token "number" (12.1: 2)
823 Next token is token '^' (12.2: 2)
824 Next token is token "number" (12.3: 2)
825 Next token is token '^' (12.4: 2)
826 Next token is token "number" (12.5: 3)
827 Next token is token '=' (12.6: 3)
828 Next token is token '=' (12.6: 3)
829 Next token is token '=' (12.6: 3)
830 Next token is token "number" (12.7: 256)
831 Next token is token '\n' (13.0: 256)
832 Next token is token '\n' (13.0: 256)
833 Next token is token '(' (13.1: 256)
834 Next token is token "number" (13.2: 2)
835 Next token is token '^' (13.3: 2)
836 Next token is token "number" (13.4: 2)
837 Next token is token ')' (13.5: 2)
838 Next token is token ')' (13.5: 2)
839 Next token is token '^' (13.6: 2)
840 Next token is token "number" (13.7: 3)
841 Next token is token '=' (13.8: 3)
842 Next token is token '=' (13.8: 3)
843 Next token is token "number" (13.9: 64)
844 Next token is token '\n' (14.0: 64)
845 Next token is token '\n' (14.0: 64)
846 ]])
847
848 # Define the calculator input.
849 # Warning: if you changes the input file
850 # then the locations test file position numbers
851 # may be incorrect and you will have
852 # to modify that file as well.
853
854 AT_DATA([input],[[1 + 2 * 3 = 7
855 1 + 2 * -3 = -5
856
857 -1^2 = -1
858 (-1)^2 = 1
859
860 ---1 = -1
861
862 1 - 2 - 3 = -4
863 1 - (2 - 3) = 2
864
865 2^2^3 = 256
866 (2^2)^3 = 64
867 ]])
868
869 AT_BISON_CHECK([PUSHPULLFLAG [-o Calc.java Calc.y]])
870 AT_JAVA_COMPILE([[Calc.java]])
871 # Verify that this is a push parser
872 AT_CHECK_JAVA_GREP([[Calc.java]],
873 [[.*public void push_parse_initialize().*]])
874 # Capture the stdout and stderr output for comparison purposes.
875 AT_JAVA_PARSER_CHECK([Calc input], 0, [stdout-nolog], [stderr-nolog])
876 # 1. Check that the token locations are correct
877 AT_CHECK([[cp -f ./locations ./expout]],[ignore],[ignore-nolog],[ignore-nolog])
878 AT_CHECK([[sed -e '/^Next token.*$/p' -e d ./stderr]],[ignore],[expout],[ignore-nolog])
879 # 2. Check that the calculator output matches that of a pull parser
880 AT_CHECK([[rm -f ./expout; cp -f ./output ./expout]],[ignore],[ignore-nolog],[ignore-nolog])
881 AT_CHECK([[cat ./stdout]],[ignore],[expout],[ignore-nolog])
882 AT_CLEANUP