]> git.saurik.com Git - bison.git/blame - tests/javapush.at
gnulib: update
[bison.git] / tests / javapush.at
CommitLineData
aa94def1
DH
1# Checking Java Push Parsing. -*- Autotest -*-
2
3209eb1c 3# Copyright (C) 2013-2015 Free Software Foundation, Inc.
aa94def1
DH
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
29m4_define([PUSHPULLFLAG],[-Dapi.push-pull=both])
30
d116722c
AD
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.
aa94def1 35m4_define([AT_CHECK_JAVA_GREP],
d116722c
AD
36[AT_CHECK_UNQUOTED([grep -c '^$2$' $1], [ignore], [m4_default([$3], [1])
37])])
aa94def1
DH
38
39##################################################
40
41AT_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.
46m4_define([AT_TRIVIAL_GRAMMAR],[
47%define parser_class_name {YYParser}
48%error-verbose
49
50%code imports {
51import java.io.*;
52import java.util.*;
53}
54
55%%
56
57start: 'a' 'b' 'c' ;
58
59%%
60])
61
62# Define comon code across to be includede in
63# class Main for the trivial parser tests.
64m4_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
45c64fa6 86 = new String[[]]{"YYACCEPT","YYABORT","YYERROR","UNKNOWN","YYPUSH_MORE"};
aa94def1
DH
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
99m4_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);
45c64fa6 113 check(teststate,YYParser.YYPUSH_MORE,"push_parse('a', null)");
aa94def1
DH
114
115 setup();
116
117 teststate = parser.push_parse('a', null);
45c64fa6 118 check(teststate,YYParser.YYPUSH_MORE,"push_parse('a', null)");
aa94def1 119 teststate = parser.push_parse('b', null);
45c64fa6 120 check(teststate,YYParser.YYPUSH_MORE,"push_parse('b', null)");
aa94def1 121 teststate = parser.push_parse('c', null);
45c64fa6 122 check(teststate,YYParser.YYPUSH_MORE,"push_parse('c', null)");
aa94def1
DH
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
136m4_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);
45c64fa6 150 check(teststate,YYParser.YYPUSH_MORE,"push_parse('a', null)");
aa94def1 151 teststate = parser.push_parse('b', null);
45c64fa6 152 check(teststate,YYParser.YYPUSH_MORE,"push_parse('b', null)");
aa94def1 153 teststate = parser.push_parse('c', null);
45c64fa6 154 check(teststate,YYParser.YYPUSH_MORE,"push_parse('c', null)");
aa94def1
DH
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
58b465ae
AD
164## ----------------------------------------------------- ##
165## Trivial Push Parser with api.push-pull verification. ##
166## ----------------------------------------------------- ##
167
aa94def1
DH
168AT_SETUP([Trivial Push Parser with api.push-pull verification])
169AT_BISON_OPTION_PUSHDEFS
58b465ae
AD
170
171AT_DATA([[input.y]],
172[[%language "Java"
aa94def1
DH
173]AT_TRIVIAL_PARSER[
174]])
aa94def1
DH
175
176# Verify that the proper procedure(s) are generated for each case.
177AT_BISON_CHECK([[-Dapi.push-pull=pull -o Main.java input.y]])
178AT_CHECK_JAVA_GREP([[Main.java]],
179 [[.*public boolean parse ().*]],
180 [1])
58b465ae
AD
181# If BISON_USE_PUSH_FOR_PULL is set, then we have one occurrence of
182# this function, otherwise it should not be there.
d116722c 183AT_CHECK_JAVA_GREP([[Main.java]],
aa94def1 184 [[.*public int push_parse (int yylextoken, Object yylexval).*]],
58b465ae
AD
185 [${BISON_USE_PUSH_FOR_PULL-0}])
186
aa94def1
DH
187AT_BISON_CHECK([[-Dapi.push-pull=both -o Main.java input.y]])
188AT_CHECK_JAVA_GREP([[Main.java]],
189 [[.*public boolean parse ().*]],
190 [1])
d116722c 191AT_CHECK_JAVA_GREP([[Main.java]],
aa94def1
DH
192 [[.*public int push_parse (int yylextoken, Object yylexval).*]],
193 [1])
58b465ae 194
aa94def1
DH
195AT_BISON_CHECK([[-Dapi.push-pull=push -o Main.java input.y]])
196AT_CHECK_JAVA_GREP([[Main.java]],
197 [[.*public boolean parse ().*]],
198 [0])
d116722c 199AT_CHECK_JAVA_GREP([[Main.java]],
aa94def1
DH
200 [[.*public int push_parse (int yylextoken, Object yylexval).*]],
201 [1])
202
203AT_JAVA_COMPILE([[Main.java]])
204AT_JAVA_PARSER_CHECK([Main], 0, [], [stderr-nolog])
58b465ae 205AT_BISON_OPTION_POPDEFS
aa94def1
DH
206AT_CLEANUP
207
58b465ae
AD
208
209## ------------------------------------------ ##
210## Trivial Push Parser with %initial-action. ##
211## ------------------------------------------ ##
212
aa94def1
DH
213AT_SETUP([Trivial Push Parser with %initial-action])
214AT_BISON_OPTION_PUSHDEFS
215AT_DATA([[input.y]],[[%language "Java"
216%initial-action {
217System.err.println("Initial action invoked");
218}
219]AT_TRIVIAL_PARSER_INITIAL_ACTION[
220]])
221AT_BISON_OPTION_POPDEFS
222AT_BISON_CHECK([[-Dapi.push-pull=push -o Main.java input.y]])
223AT_CHECK_JAVA_GREP([[Main.java]],
224 [[System.err.println("Initial action invoked");]])
225AT_JAVA_COMPILE([[Main.java]])
226AT_JAVA_PARSER_CHECK([Main], 0, [], [stderr-nolog])
227# Verify that initial action is called exactly once.
228AT_CHECK_JAVA_GREP(
229 [[stderr]],
230 [[Initial action invoked]],
231 [1])
232AT_CLEANUP
233
234# Define a single copy of the Calculator grammar.
235m4_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 {
3d75e7de
AD
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();
aa94def1
DH
248 FileReader file = new FileReader(filename);
249 int c;
3d75e7de 250 while (0 < (c = file.read()))
aa94def1
DH
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%%
269input:
270 line
271| input line
272;
273
274line:
275 '\n'
276| exp '\n'
277 {System.out.println("total = "+$[]1);}
278| error '\n'
279;
280
281exp:
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
3d75e7de
AD
308
309
310## ------------------------------------- ##
311## Calc parser with api.push-pull both. ##
312## ------------------------------------- ##
313
314
aa94def1
DH
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
321AT_SETUP([Calc parser with api.push-pull both])
322AT_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
330AT_DATA([input],[[1 + 2 * 3 = 7
3311 + 2 * -3 = -5
332
333-1^2 = -1
334(-1)^2 = 1
335
336---1 = -1
337
3381 - 2 - 3 = -4
3391 - (2 - 3) = 2
340
3412^2^3 = 256
342(2^2)^3 = 64
343]])
344
345# Compose pieces to build the actual .y file.
346AT_DATA([Calc.y],[[/* Infix notation calculator--calc */
347%language "Java"
348%name-prefix "Calc"
349%define parser_class_name {Calc}
350
351%code {
352static 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 {
390public 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.
407AT_DATA([[expout]],[[Stack now 0
408Stack now 0 2
409Stack now 0 9
410Stack now 0 9 19
411Stack now 0 9 19 2
412Stack now 0 9 19 28
413Stack now 0 9 19 28 20
414Stack now 0 9 19 28 20 2
415Stack now 0 9 19 28 20 29
416Stack now 0 9 19 28
417Stack now 0 9
418Stack now 0 9 17
419Stack now 0 9 17 2
420Stack now 0 9 17 26
421Stack now 0 9
422Stack now 0 9 23
423Stack now 0 8
424Stack now 0 7
425Stack now 0 7 2
426Stack now 0 7 9
427Stack now 0 7 9 19
428Stack now 0 7 9 19 2
429Stack now 0 7 9 19 28
430Stack now 0 7 9 19 28 20
431Stack now 0 7 9 19 28 20 3
432Stack now 0 7 9 19 28 20 3 2
433Stack now 0 7 9 19 28 20 3 12
434Stack now 0 7 9 19 28 20 29
435Stack now 0 7 9 19 28
436Stack now 0 7 9
437Stack now 0 7 9 17
438Stack now 0 7 9 17 3
439Stack now 0 7 9 17 3 2
440Stack now 0 7 9 17 3 12
441Stack now 0 7 9 17 26
442Stack now 0 7 9
443Stack now 0 7 9 23
444Stack now 0 7 16
445Stack now 0 7
446Stack now 0 7 4
447Stack now 0 7 16
448Stack now 0 7
449Stack now 0 7 3
450Stack now 0 7 3 2
451Stack now 0 7 3 12
452Stack now 0 7 3 12 22
453Stack now 0 7 3 12 22 2
454Stack now 0 7 3 12 22 31
455Stack now 0 7 3 12
456Stack now 0 7 9
457Stack now 0 7 9 17
458Stack now 0 7 9 17 3
459Stack now 0 7 9 17 3 2
460Stack now 0 7 9 17 3 12
461Stack now 0 7 9 17 26
462Stack now 0 7 9
463Stack now 0 7 9 23
464Stack now 0 7 16
465Stack now 0 7
466Stack now 0 7 5
467Stack now 0 7 5 3
468Stack now 0 7 5 3 2
469Stack now 0 7 5 3 12
470Stack now 0 7 5 14
471Stack now 0 7 5 14 25
472Stack now 0 7 9
473Stack now 0 7 9 22
474Stack now 0 7 9 22 2
475Stack now 0 7 9 22 31
476Stack now 0 7 9
477Stack now 0 7 9 17
478Stack now 0 7 9 17 2
479Stack now 0 7 9 17 26
480Stack now 0 7 9
481Stack now 0 7 9 23
482Stack now 0 7 16
483Stack now 0 7
484Stack now 0 7 4
485Stack now 0 7 16
486Stack now 0 7
487Stack now 0 7 3
488Stack now 0 7 3 3
489Stack now 0 7 3 3 3
490Stack now 0 7 3 3 3 2
491Stack now 0 7 3 3 3 12
492Stack now 0 7 3 3 12
493Stack now 0 7 3 12
494Stack now 0 7 9
495Stack now 0 7 9 17
496Stack now 0 7 9 17 3
497Stack now 0 7 9 17 3 2
498Stack now 0 7 9 17 3 12
499Stack now 0 7 9 17 26
500Stack now 0 7 9
501Stack now 0 7 9 23
502Stack now 0 7 16
503Stack now 0 7
504Stack now 0 7 4
505Stack now 0 7 16
506Stack now 0 7
507Stack now 0 7 2
508Stack now 0 7 9
509Stack now 0 7 9 18
510Stack now 0 7 9 18 2
511Stack now 0 7 9 18 27
512Stack now 0 7 9
513Stack now 0 7 9 18
514Stack now 0 7 9 18 2
515Stack now 0 7 9 18 27
516Stack now 0 7 9
517Stack now 0 7 9 17
518Stack now 0 7 9 17 3
519Stack now 0 7 9 17 3 2
520Stack now 0 7 9 17 3 12
521Stack now 0 7 9 17 26
522Stack now 0 7 9
523Stack now 0 7 9 23
524Stack now 0 7 16
525Stack now 0 7
526Stack now 0 7 2
527Stack now 0 7 9
528Stack now 0 7 9 18
529Stack now 0 7 9 18 5
530Stack now 0 7 9 18 5 2
531Stack now 0 7 9 18 5 14
532Stack now 0 7 9 18 5 14 18
533Stack now 0 7 9 18 5 14 18 2
534Stack now 0 7 9 18 5 14 18 27
535Stack now 0 7 9 18 5 14
536Stack now 0 7 9 18 5 14 25
537Stack now 0 7 9 18 27
538Stack now 0 7 9
539Stack now 0 7 9 17
540Stack now 0 7 9 17 2
541Stack now 0 7 9 17 26
542Stack now 0 7 9
543Stack now 0 7 9 23
544Stack now 0 7 16
545Stack now 0 7
546Stack now 0 7 4
547Stack now 0 7 16
548Stack now 0 7
549Stack now 0 7 2
550Stack now 0 7 9
551Stack now 0 7 9 22
552Stack now 0 7 9 22 2
553Stack now 0 7 9 22 31
554Stack now 0 7 9 22 31 22
555Stack now 0 7 9 22 31 22 2
556Stack now 0 7 9 22 31 22 31
557Stack now 0 7 9 22 31
558Stack now 0 7 9
559Stack now 0 7 9 17
560Stack now 0 7 9 17 2
561Stack now 0 7 9 17 26
562Stack now 0 7 9
563Stack now 0 7 9 23
564Stack now 0 7 16
565Stack now 0 7
566Stack now 0 7 5
567Stack now 0 7 5 2
568Stack now 0 7 5 14
569Stack now 0 7 5 14 22
570Stack now 0 7 5 14 22 2
571Stack now 0 7 5 14 22 31
572Stack now 0 7 5 14
573Stack now 0 7 5 14 25
574Stack now 0 7 9
575Stack now 0 7 9 22
576Stack now 0 7 9 22 2
577Stack now 0 7 9 22 31
578Stack now 0 7 9
579Stack now 0 7 9 17
580Stack now 0 7 9 17 2
581Stack now 0 7 9 17 26
582Stack now 0 7 9
583Stack now 0 7 9 23
584Stack now 0 7 16
585Stack now 0 7
586Stack now 0 7 15
587]])
588
589AT_BISON_CHECK([PUSHPULLFLAG [-o Calc.java Calc.y]])
3d75e7de 590
aa94def1 591AT_JAVA_COMPILE([[Calc.java]])
3d75e7de 592# Verify that this is a push parser.
aa94def1
DH
593AT_CHECK_JAVA_GREP([[Calc.java]],
594 [[.*public void push_parse_initialize().*]])
595# Capture stderr output for comparison purposes.
596AT_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).
d116722c
AD
602AT_CHECK([[sed -e '/^Stack now.*$/p' -e d ./stderr]],
603 [ignore], [expout], [ignore-nolog])
aa94def1
DH
604AT_BISON_OPTION_POPDEFS
605AT_CLEANUP
606
3d75e7de
AD
607
608
609## ---------------------------------------------------------------- ##
610## Calc parser with %locations %code lexer and api.push-pull both. ##
611## ---------------------------------------------------------------- ##
612
613
aa94def1
DH
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.
617AT_SETUP([Calc parser with %locations %code lexer and api.push-pull both])
618AT_BISON_OPTION_PUSHDEFS
619
620AT_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 {
677class 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 {
702public 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.
718AT_DATA([output],[[total = 7
719total = -5
720total = -1
721total = 1
722total = -1
723total = -4
724total = 2
725total = 256
726total = 64
727]])
728
729AT_DATA([locations],[[Next token is token "number" (1.1: 1)
730Next token is token '+' (1.2: 1)
731Next token is token "number" (1.3: 2)
732Next token is token '*' (1.4: 2)
733Next token is token "number" (1.5: 3)
734Next token is token '=' (1.6: 3)
735Next token is token '=' (1.6: 3)
736Next token is token '=' (1.6: 3)
737Next token is token "number" (1.7: 7)
738Next token is token '\n' (2.0: 7)
739Next token is token '\n' (2.0: 7)
740Next token is token "number" (2.1: 1)
741Next token is token '+' (2.2: 1)
742Next token is token "number" (2.3: 2)
743Next token is token '*' (2.4: 2)
744Next token is token '-' (2.5: 2)
745Next token is token "number" (2.6: 3)
746Next token is token '=' (2.7: 3)
747Next token is token '=' (2.7: 3)
748Next token is token '=' (2.7: 3)
749Next token is token '=' (2.7: 3)
750Next token is token '-' (2.8: 3)
751Next token is token "number" (2.9: 5)
752Next token is token '\n' (3.0: 5)
753Next token is token '\n' (3.0: 5)
754Next token is token '\n' (3.0: 5)
755Next token is token '\n' (4.0: 5)
756Next token is token '-' (4.1: 5)
757Next token is token "number" (4.2: 1)
758Next token is token '^' (4.3: 1)
759Next token is token "number" (4.4: 2)
760Next token is token '=' (4.5: 2)
761Next token is token '=' (4.5: 2)
762Next token is token '=' (4.5: 2)
763Next token is token '-' (4.6: 2)
764Next token is token "number" (4.7: 1)
765Next token is token '\n' (5.0: 1)
766Next token is token '\n' (5.0: 1)
767Next token is token '\n' (5.0: 1)
768Next token is token '(' (5.1: 1)
769Next token is token '-' (5.2: 1)
770Next token is token "number" (5.3: 1)
771Next token is token ')' (5.4: 1)
772Next token is token ')' (5.4: 1)
773Next token is token '^' (5.5: 1)
774Next token is token "number" (5.6: 2)
775Next token is token '=' (5.7: 2)
776Next token is token '=' (5.7: 2)
777Next token is token "number" (5.8: 1)
778Next token is token '\n' (6.0: 1)
779Next token is token '\n' (6.0: 1)
780Next token is token '\n' (7.0: 1)
781Next token is token '-' (7.1: 1)
782Next token is token '-' (7.2: 1)
783Next token is token '-' (7.3: 1)
784Next token is token "number" (7.4: 1)
785Next token is token '=' (7.5: 1)
786Next token is token '=' (7.5: 1)
787Next token is token '=' (7.5: 1)
788Next token is token '=' (7.5: 1)
789Next token is token '-' (7.6: 1)
790Next token is token "number" (7.7: 1)
791Next token is token '\n' (8.0: 1)
792Next token is token '\n' (8.0: 1)
793Next token is token '\n' (8.0: 1)
794Next token is token '\n' (9.0: 1)
795Next token is token "number" (9.1: 1)
796Next token is token '-' (9.2: 1)
797Next token is token "number" (9.3: 2)
798Next token is token '-' (9.4: 2)
799Next token is token '-' (9.4: 2)
800Next token is token "number" (9.5: 3)
801Next token is token '=' (9.6: 3)
802Next token is token '=' (9.6: 3)
803Next token is token '-' (9.7: 3)
804Next token is token "number" (9.8: 4)
805Next token is token '\n' (10.0: 4)
806Next token is token '\n' (10.0: 4)
807Next token is token '\n' (10.0: 4)
808Next token is token "number" (10.1: 1)
809Next token is token '-' (10.2: 1)
810Next token is token '(' (10.3: 1)
811Next token is token "number" (10.4: 2)
812Next token is token '-' (10.5: 2)
813Next token is token "number" (10.6: 3)
814Next token is token ')' (10.7: 3)
815Next token is token ')' (10.7: 3)
816Next token is token '=' (10.8: 3)
817Next token is token '=' (10.8: 3)
818Next token is token "number" (10.9: 2)
819Next token is token '\n' (11.0: 2)
820Next token is token '\n' (11.0: 2)
821Next token is token '\n' (12.0: 2)
822Next token is token "number" (12.1: 2)
823Next token is token '^' (12.2: 2)
824Next token is token "number" (12.3: 2)
825Next token is token '^' (12.4: 2)
826Next token is token "number" (12.5: 3)
827Next token is token '=' (12.6: 3)
828Next token is token '=' (12.6: 3)
829Next token is token '=' (12.6: 3)
830Next token is token "number" (12.7: 256)
831Next token is token '\n' (13.0: 256)
832Next token is token '\n' (13.0: 256)
833Next token is token '(' (13.1: 256)
834Next token is token "number" (13.2: 2)
835Next token is token '^' (13.3: 2)
836Next token is token "number" (13.4: 2)
837Next token is token ')' (13.5: 2)
838Next token is token ')' (13.5: 2)
839Next token is token '^' (13.6: 2)
840Next token is token "number" (13.7: 3)
841Next token is token '=' (13.8: 3)
842Next token is token '=' (13.8: 3)
843Next token is token "number" (13.9: 64)
844Next token is token '\n' (14.0: 64)
845Next 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
854AT_DATA([input],[[1 + 2 * 3 = 7
8551 + 2 * -3 = -5
856
857-1^2 = -1
858(-1)^2 = 1
859
860---1 = -1
861
8621 - 2 - 3 = -4
8631 - (2 - 3) = 2
864
8652^2^3 = 256
866(2^2)^3 = 64
867]])
868
869AT_BISON_CHECK([PUSHPULLFLAG [-o Calc.java Calc.y]])
870AT_JAVA_COMPILE([[Calc.java]])
871# Verify that this is a push parser
872AT_CHECK_JAVA_GREP([[Calc.java]],
873 [[.*public void push_parse_initialize().*]])
874# Capture the stdout and stderr output for comparison purposes.
875AT_JAVA_PARSER_CHECK([Calc input], 0, [stdout-nolog], [stderr-nolog])
876# 1. Check that the token locations are correct
877AT_CHECK([[cp -f ./locations ./expout]],[ignore],[ignore-nolog],[ignore-nolog])
878AT_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
880AT_CHECK([[rm -f ./expout; cp -f ./output ./expout]],[ignore],[ignore-nolog],[ignore-nolog])
881AT_CHECK([[cat ./stdout]],[ignore],[expout],[ignore-nolog])
882AT_CLEANUP