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