]> git.saurik.com Git - bison.git/blame_incremental - tests/javapush.at
package: bump to 2014
[bison.git] / tests / javapush.at
... / ...
CommitLineData
1# Checking Java Push Parsing. -*- Autotest -*-
2
3# Copyright (C) 2013-2014 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
29m4_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.
35m4_define([AT_CHECK_JAVA_GREP],
36[AT_CHECK_UNQUOTED([grep -c '^$2$' $1], [ignore], [m4_default([$3], [1])
37])])
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
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
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);
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
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);
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
168AT_SETUP([Trivial Push Parser with api.push-pull verification])
169AT_BISON_OPTION_PUSHDEFS
170
171AT_DATA([[input.y]],
172[[%language "Java"
173]AT_TRIVIAL_PARSER[
174]])
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])
181# If BISON_USE_PUSH_FOR_PULL is set, then we have one occurrence of
182# this function, otherwise it should not be there.
183AT_CHECK_JAVA_GREP([[Main.java]],
184 [[.*public int push_parse (int yylextoken, Object yylexval).*]],
185 [${BISON_USE_PUSH_FOR_PULL-0}])
186
187AT_BISON_CHECK([[-Dapi.push-pull=both -o Main.java input.y]])
188AT_CHECK_JAVA_GREP([[Main.java]],
189 [[.*public boolean parse ().*]],
190 [1])
191AT_CHECK_JAVA_GREP([[Main.java]],
192 [[.*public int push_parse (int yylextoken, Object yylexval).*]],
193 [1])
194
195AT_BISON_CHECK([[-Dapi.push-pull=push -o Main.java input.y]])
196AT_CHECK_JAVA_GREP([[Main.java]],
197 [[.*public boolean parse ().*]],
198 [0])
199AT_CHECK_JAVA_GREP([[Main.java]],
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])
205AT_BISON_OPTION_POPDEFS
206AT_CLEANUP
207
208
209## ------------------------------------------ ##
210## Trivial Push Parser with %initial-action. ##
211## ------------------------------------------ ##
212
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 {
244 StringBuilder buf = new StringBuilder();
245 FileReader file = new FileReader(filename);
246 int c;
247 while ((c=file.read()) > 0)
248 buf.append((char)c);
249 file.close();
250 return new StringReader(buf.toString());
251 }
252}
253
254/* Bison Declarations */
255%token <Integer> NUM "number"
256%type <Integer> exp
257
258%nonassoc '=' /* comparison */
259%left '-' '+'
260%left '*' '/'
261%left NEG /* negation--unary minus */
262%right '^' /* exponentiation */
263
264/* Grammar follows */
265%%
266input:
267 line
268| input line
269;
270
271line:
272 '\n'
273| exp '\n'
274 {System.out.println("total = "+$[]1);}
275| error '\n'
276;
277
278exp:
279 NUM { $[]$ = $[]1;}
280| exp '=' exp
281 {
282 if ($[]1.intValue() != $[]3.intValue())
283 yyerror (]AT_LOCATION_IF([[@$,]])[ "calc: error: " + $[]1 + " != " + $[]3);
284 }
285| exp '+' exp
286 { $[]$ = new Integer ($[]1.intValue () + $[]3.intValue ()); }
287| exp '-' exp
288 { $[]$ = new Integer ($[]1.intValue () - $[]3.intValue ()); }
289| exp '*' exp
290 { $[]$ = new Integer ($[]1.intValue () * $[]3.intValue ()); }
291| exp '/' exp
292 { $[]$ = new Integer ($[]1.intValue () / $[]3.intValue ()); }
293| '-' exp %prec NEG
294 { $[]$ = new Integer (-$[]2.intValue ()); }
295| exp '^' exp
296 { $[]$ = new Integer ((int)Math.pow ($[]1.intValue (),
297 $[]3.intValue ())); }
298| '(' exp ')' { $[]$ = $[]2;}
299| '(' error ')' { $[]$ = new Integer (1111);}
300| '!' { $[]$ = new Integer (0); return YYERROR;}
301| '-' error { $[]$ = new Integer (0); return YYERROR;}
302;
303])
304
305# Test that the states transitioned by the push parser are the
306# same as for the pull parser. This test is assumed to work
307# if it produces the same partial trace of stack states as is
308# produced when using pull parsing. The output is verbose,
309# but seems essential for verifying push parsing.
310
311AT_SETUP([Calc parser with api.push-pull both])
312AT_BISON_OPTION_PUSHDEFS
313
314# Define the calculator input.
315# Warning: if you changes the input file
316# then the locations test file position numbers
317# may be incorrect and you will have
318# to modify that file as well.
319
320AT_DATA([input],[[1 + 2 * 3 = 7
3211 + 2 * -3 = -5
322
323-1^2 = -1
324(-1)^2 = 1
325
326---1 = -1
327
3281 - 2 - 3 = -4
3291 - (2 - 3) = 2
330
3312^2^3 = 256
332(2^2)^3 = 64
333]])
334
335# Compose pieces to build the actual .y file.
336AT_DATA([Calc.y],[[/* Infix notation calculator--calc */
337%language "Java"
338%name-prefix "Calc"
339%define parser_class_name {Calc}
340
341%code {
342static class UserLexer implements Calc.Lexer
343{
344 StreamTokenizer st;
345 StringReader rdr;
346
347 public UserLexer(StringReader reader)
348 {
349 rdr = reader;
350 st = new StreamTokenizer(rdr);
351 st.resetSyntax();
352 st.eolIsSignificant(true);
353 st.whitespaceChars(9, 9);
354 st.whitespaceChars(32, 32);
355 st.wordChars(48, 57);
356 }
357
358 Integer yylval;
359
360 public Object getLVal() { return yylval; }
361
362 public void yyerror(String msg) { System.err.println(msg); }
363
364 public int yylex () throws IOException
365 {
366 switch (st.nextToken()) {
367 case StreamTokenizer.TT_EOF: return EOF;
368 case StreamTokenizer.TT_EOL: return (int) '\n';
369 case StreamTokenizer.TT_WORD:
370 yylval = new Integer (st.sval);
371 return NUM;
372 default: return st.ttype;
373 }
374 }
375}
376
377}
378
379%code {
380public static void main (String[] argv)
381 throws IOException
382{
383 StringReader reader = getinput(argv[0]);
384 UserLexer lexer = new UserLexer(reader);
385 Calc calc = new Calc(lexer);
386 calc.setDebugLevel(1);
387 calc.parse();
388}//main
389
390}
391
392]AT_CALC_BODY[
393
394]])
395
396# This data was captured from running a pull parser.
397AT_DATA([[expout]],[[Stack now 0
398Stack now 0 2
399Stack now 0 9
400Stack now 0 9 19
401Stack now 0 9 19 2
402Stack now 0 9 19 28
403Stack now 0 9 19 28 20
404Stack now 0 9 19 28 20 2
405Stack now 0 9 19 28 20 29
406Stack now 0 9 19 28
407Stack now 0 9
408Stack now 0 9 17
409Stack now 0 9 17 2
410Stack now 0 9 17 26
411Stack now 0 9
412Stack now 0 9 23
413Stack now 0 8
414Stack now 0 7
415Stack now 0 7 2
416Stack now 0 7 9
417Stack now 0 7 9 19
418Stack now 0 7 9 19 2
419Stack now 0 7 9 19 28
420Stack now 0 7 9 19 28 20
421Stack now 0 7 9 19 28 20 3
422Stack now 0 7 9 19 28 20 3 2
423Stack now 0 7 9 19 28 20 3 12
424Stack now 0 7 9 19 28 20 29
425Stack now 0 7 9 19 28
426Stack now 0 7 9
427Stack now 0 7 9 17
428Stack now 0 7 9 17 3
429Stack now 0 7 9 17 3 2
430Stack now 0 7 9 17 3 12
431Stack now 0 7 9 17 26
432Stack now 0 7 9
433Stack now 0 7 9 23
434Stack now 0 7 16
435Stack now 0 7
436Stack now 0 7 4
437Stack now 0 7 16
438Stack now 0 7
439Stack now 0 7 3
440Stack now 0 7 3 2
441Stack now 0 7 3 12
442Stack now 0 7 3 12 22
443Stack now 0 7 3 12 22 2
444Stack now 0 7 3 12 22 31
445Stack now 0 7 3 12
446Stack now 0 7 9
447Stack now 0 7 9 17
448Stack now 0 7 9 17 3
449Stack now 0 7 9 17 3 2
450Stack now 0 7 9 17 3 12
451Stack now 0 7 9 17 26
452Stack now 0 7 9
453Stack now 0 7 9 23
454Stack now 0 7 16
455Stack now 0 7
456Stack now 0 7 5
457Stack now 0 7 5 3
458Stack now 0 7 5 3 2
459Stack now 0 7 5 3 12
460Stack now 0 7 5 14
461Stack now 0 7 5 14 25
462Stack now 0 7 9
463Stack now 0 7 9 22
464Stack now 0 7 9 22 2
465Stack now 0 7 9 22 31
466Stack now 0 7 9
467Stack now 0 7 9 17
468Stack now 0 7 9 17 2
469Stack now 0 7 9 17 26
470Stack now 0 7 9
471Stack now 0 7 9 23
472Stack now 0 7 16
473Stack now 0 7
474Stack now 0 7 4
475Stack now 0 7 16
476Stack now 0 7
477Stack now 0 7 3
478Stack now 0 7 3 3
479Stack now 0 7 3 3 3
480Stack now 0 7 3 3 3 2
481Stack now 0 7 3 3 3 12
482Stack now 0 7 3 3 12
483Stack now 0 7 3 12
484Stack now 0 7 9
485Stack now 0 7 9 17
486Stack now 0 7 9 17 3
487Stack now 0 7 9 17 3 2
488Stack now 0 7 9 17 3 12
489Stack now 0 7 9 17 26
490Stack now 0 7 9
491Stack now 0 7 9 23
492Stack now 0 7 16
493Stack now 0 7
494Stack now 0 7 4
495Stack now 0 7 16
496Stack now 0 7
497Stack now 0 7 2
498Stack now 0 7 9
499Stack now 0 7 9 18
500Stack now 0 7 9 18 2
501Stack now 0 7 9 18 27
502Stack now 0 7 9
503Stack now 0 7 9 18
504Stack now 0 7 9 18 2
505Stack now 0 7 9 18 27
506Stack now 0 7 9
507Stack now 0 7 9 17
508Stack now 0 7 9 17 3
509Stack now 0 7 9 17 3 2
510Stack now 0 7 9 17 3 12
511Stack now 0 7 9 17 26
512Stack now 0 7 9
513Stack now 0 7 9 23
514Stack now 0 7 16
515Stack now 0 7
516Stack now 0 7 2
517Stack now 0 7 9
518Stack now 0 7 9 18
519Stack now 0 7 9 18 5
520Stack now 0 7 9 18 5 2
521Stack now 0 7 9 18 5 14
522Stack now 0 7 9 18 5 14 18
523Stack now 0 7 9 18 5 14 18 2
524Stack now 0 7 9 18 5 14 18 27
525Stack now 0 7 9 18 5 14
526Stack now 0 7 9 18 5 14 25
527Stack now 0 7 9 18 27
528Stack now 0 7 9
529Stack now 0 7 9 17
530Stack now 0 7 9 17 2
531Stack now 0 7 9 17 26
532Stack now 0 7 9
533Stack now 0 7 9 23
534Stack now 0 7 16
535Stack now 0 7
536Stack now 0 7 4
537Stack now 0 7 16
538Stack now 0 7
539Stack now 0 7 2
540Stack now 0 7 9
541Stack now 0 7 9 22
542Stack now 0 7 9 22 2
543Stack now 0 7 9 22 31
544Stack now 0 7 9 22 31 22
545Stack now 0 7 9 22 31 22 2
546Stack now 0 7 9 22 31 22 31
547Stack now 0 7 9 22 31
548Stack now 0 7 9
549Stack now 0 7 9 17
550Stack now 0 7 9 17 2
551Stack now 0 7 9 17 26
552Stack now 0 7 9
553Stack now 0 7 9 23
554Stack now 0 7 16
555Stack now 0 7
556Stack now 0 7 5
557Stack now 0 7 5 2
558Stack now 0 7 5 14
559Stack now 0 7 5 14 22
560Stack now 0 7 5 14 22 2
561Stack now 0 7 5 14 22 31
562Stack now 0 7 5 14
563Stack now 0 7 5 14 25
564Stack now 0 7 9
565Stack now 0 7 9 22
566Stack now 0 7 9 22 2
567Stack now 0 7 9 22 31
568Stack now 0 7 9
569Stack now 0 7 9 17
570Stack now 0 7 9 17 2
571Stack now 0 7 9 17 26
572Stack now 0 7 9
573Stack now 0 7 9 23
574Stack now 0 7 16
575Stack now 0 7
576Stack now 0 7 15
577]])
578
579AT_BISON_CHECK([PUSHPULLFLAG [-o Calc.java Calc.y]])
580AT_JAVA_COMPILE([[Calc.java]])
581#Verify that this is a push parser.
582AT_CHECK_JAVA_GREP([[Calc.java]],
583 [[.*public void push_parse_initialize().*]])
584# Capture stderr output for comparison purposes.
585AT_JAVA_PARSER_CHECK([Calc input], 0, [ignore-nolog], [stderr-nolog])
586# Extract the "Stack Now" lines from the error output,
587# send them to stdout (via the sed command) and compare to expout.
588# NOTE: because the target is "expout", this macro automatically
589# compares the output of the sed command with the contents of
590# the file "expout" (defined above).
591AT_CHECK([[sed -e '/^Stack now.*$/p' -e d ./stderr]],
592 [ignore], [expout], [ignore-nolog])
593AT_BISON_OPTION_POPDEFS
594AT_CLEANUP
595
596# This test looks for location reporting by looking
597# at the lexer output with locations enabled.
598# It defines a lexer that reports location info.
599AT_SETUP([Calc parser with %locations %code lexer and api.push-pull both])
600AT_BISON_OPTION_PUSHDEFS
601
602AT_DATA([Calc.y],[[/* Infix notation calculator--calc. */
603%language "Java"
604%name-prefix "Calc"
605%define parser_class_name {Calc}
606%lex-param { Reader rdr }
607%locations
608
609%code imports {
610 import java.io.*;
611}
612
613%code lexer {
614 StreamTokenizer st;
615 Integer yylval;
616
617 public YYLexer(Reader rdr)
618 {
619 st = new StreamTokenizer(rdr);
620 st.resetSyntax();
621 st.eolIsSignificant(true);
622 st.whitespaceChars(9, 9);
623 st.whitespaceChars(32, 32);
624 st.wordChars(48, 57);
625 }
626
627 Position yypos = new Position (1, 0);
628
629 public Position getStartPos() { return yypos; }
630
631 public Position getEndPos() { return yypos; }
632
633 public Object getLVal() { return yylval; }
634
635 public void yyerror(Location loc, String msg)
636 {
637 System.err.println(loc+":"+msg);
638 }
639
640 public int yylex () throws IOException
641 {
642 yypos = new Position (yypos.lineno (),yypos.token () + 1);
643 switch (st.nextToken()) {
644 case StreamTokenizer.TT_EOF:
645 return EOF;
646 case StreamTokenizer.TT_EOL:
647 yypos = new Position (yypos.lineno () + 1, 0);
648 return (int) '\n';
649 case StreamTokenizer.TT_WORD:
650 yylval = new Integer (st.sval);
651 return NUM;
652 default:
653 return st.ttype;
654 }
655 }
656}
657
658%code {
659class Position {
660 public int line;
661 public int token;
662
663 public Position () { line = 0; token = 0; }
664
665 public Position (int l, int t) { line = l; token = t; }
666
667 public boolean equals (Position l)
668 {
669 return l.line == line && l.token == token;
670 }
671
672 public String toString ()
673 {
674 return Integer.toString(line) + "." + Integer.toString(token);
675 }
676
677 public int lineno () { return line; }
678
679 public int token () { return token; }
680}//Class Position
681}
682
683%code {
684public static void main (String[] argv)
685 throws IOException
686{
687 StringReader reader = getinput(argv[0]);
688 Calc calc = new Calc(reader);
689 calc.setDebugLevel(1);
690 calc.parse();
691}
692}
693
694]AT_CALC_BODY[
695
696]])
697
698# Define the expected calculator output.
699# This should match the output from a pull parser.
700AT_DATA([output],[[total = 7
701total = -5
702total = -1
703total = 1
704total = -1
705total = -4
706total = 2
707total = 256
708total = 64
709]])
710
711AT_DATA([locations],[[Next token is token "number" (1.1: 1)
712Next token is token '+' (1.2: 1)
713Next token is token "number" (1.3: 2)
714Next token is token '*' (1.4: 2)
715Next token is token "number" (1.5: 3)
716Next token is token '=' (1.6: 3)
717Next token is token '=' (1.6: 3)
718Next token is token '=' (1.6: 3)
719Next token is token "number" (1.7: 7)
720Next token is token '\n' (2.0: 7)
721Next token is token '\n' (2.0: 7)
722Next token is token "number" (2.1: 1)
723Next token is token '+' (2.2: 1)
724Next token is token "number" (2.3: 2)
725Next token is token '*' (2.4: 2)
726Next token is token '-' (2.5: 2)
727Next token is token "number" (2.6: 3)
728Next token is token '=' (2.7: 3)
729Next token is token '=' (2.7: 3)
730Next token is token '=' (2.7: 3)
731Next token is token '=' (2.7: 3)
732Next token is token '-' (2.8: 3)
733Next token is token "number" (2.9: 5)
734Next token is token '\n' (3.0: 5)
735Next token is token '\n' (3.0: 5)
736Next token is token '\n' (3.0: 5)
737Next token is token '\n' (4.0: 5)
738Next token is token '-' (4.1: 5)
739Next token is token "number" (4.2: 1)
740Next token is token '^' (4.3: 1)
741Next token is token "number" (4.4: 2)
742Next token is token '=' (4.5: 2)
743Next token is token '=' (4.5: 2)
744Next token is token '=' (4.5: 2)
745Next token is token '-' (4.6: 2)
746Next token is token "number" (4.7: 1)
747Next token is token '\n' (5.0: 1)
748Next token is token '\n' (5.0: 1)
749Next token is token '\n' (5.0: 1)
750Next token is token '(' (5.1: 1)
751Next token is token '-' (5.2: 1)
752Next token is token "number" (5.3: 1)
753Next token is token ')' (5.4: 1)
754Next token is token ')' (5.4: 1)
755Next token is token '^' (5.5: 1)
756Next token is token "number" (5.6: 2)
757Next token is token '=' (5.7: 2)
758Next token is token '=' (5.7: 2)
759Next token is token "number" (5.8: 1)
760Next token is token '\n' (6.0: 1)
761Next token is token '\n' (6.0: 1)
762Next token is token '\n' (7.0: 1)
763Next token is token '-' (7.1: 1)
764Next token is token '-' (7.2: 1)
765Next token is token '-' (7.3: 1)
766Next token is token "number" (7.4: 1)
767Next token is token '=' (7.5: 1)
768Next token is token '=' (7.5: 1)
769Next token is token '=' (7.5: 1)
770Next token is token '=' (7.5: 1)
771Next token is token '-' (7.6: 1)
772Next token is token "number" (7.7: 1)
773Next token is token '\n' (8.0: 1)
774Next token is token '\n' (8.0: 1)
775Next token is token '\n' (8.0: 1)
776Next token is token '\n' (9.0: 1)
777Next token is token "number" (9.1: 1)
778Next token is token '-' (9.2: 1)
779Next token is token "number" (9.3: 2)
780Next token is token '-' (9.4: 2)
781Next token is token '-' (9.4: 2)
782Next token is token "number" (9.5: 3)
783Next token is token '=' (9.6: 3)
784Next token is token '=' (9.6: 3)
785Next token is token '-' (9.7: 3)
786Next token is token "number" (9.8: 4)
787Next token is token '\n' (10.0: 4)
788Next token is token '\n' (10.0: 4)
789Next token is token '\n' (10.0: 4)
790Next token is token "number" (10.1: 1)
791Next token is token '-' (10.2: 1)
792Next token is token '(' (10.3: 1)
793Next token is token "number" (10.4: 2)
794Next token is token '-' (10.5: 2)
795Next token is token "number" (10.6: 3)
796Next token is token ')' (10.7: 3)
797Next token is token ')' (10.7: 3)
798Next token is token '=' (10.8: 3)
799Next token is token '=' (10.8: 3)
800Next token is token "number" (10.9: 2)
801Next token is token '\n' (11.0: 2)
802Next token is token '\n' (11.0: 2)
803Next token is token '\n' (12.0: 2)
804Next token is token "number" (12.1: 2)
805Next token is token '^' (12.2: 2)
806Next token is token "number" (12.3: 2)
807Next token is token '^' (12.4: 2)
808Next token is token "number" (12.5: 3)
809Next token is token '=' (12.6: 3)
810Next token is token '=' (12.6: 3)
811Next token is token '=' (12.6: 3)
812Next token is token "number" (12.7: 256)
813Next token is token '\n' (13.0: 256)
814Next token is token '\n' (13.0: 256)
815Next token is token '(' (13.1: 256)
816Next token is token "number" (13.2: 2)
817Next token is token '^' (13.3: 2)
818Next token is token "number" (13.4: 2)
819Next token is token ')' (13.5: 2)
820Next token is token ')' (13.5: 2)
821Next token is token '^' (13.6: 2)
822Next token is token "number" (13.7: 3)
823Next token is token '=' (13.8: 3)
824Next token is token '=' (13.8: 3)
825Next token is token "number" (13.9: 64)
826Next token is token '\n' (14.0: 64)
827Next token is token '\n' (14.0: 64)
828]])
829
830# Define the calculator input.
831# Warning: if you changes the input file
832# then the locations test file position numbers
833# may be incorrect and you will have
834# to modify that file as well.
835
836AT_DATA([input],[[1 + 2 * 3 = 7
8371 + 2 * -3 = -5
838
839-1^2 = -1
840(-1)^2 = 1
841
842---1 = -1
843
8441 - 2 - 3 = -4
8451 - (2 - 3) = 2
846
8472^2^3 = 256
848(2^2)^3 = 64
849]])
850
851AT_BISON_CHECK([PUSHPULLFLAG [-o Calc.java Calc.y]])
852AT_JAVA_COMPILE([[Calc.java]])
853# Verify that this is a push parser
854AT_CHECK_JAVA_GREP([[Calc.java]],
855 [[.*public void push_parse_initialize().*]])
856# Capture the stdout and stderr output for comparison purposes.
857AT_JAVA_PARSER_CHECK([Calc input], 0, [stdout-nolog], [stderr-nolog])
858# 1. Check that the token locations are correct
859AT_CHECK([[cp -f ./locations ./expout]],[ignore],[ignore-nolog],[ignore-nolog])
860AT_CHECK([[sed -e '/^Next token.*$/p' -e d ./stderr]],[ignore],[expout],[ignore-nolog])
861# 2. Check that the calculator output matches that of a pull parser
862AT_CHECK([[rm -f ./expout; cp -f ./output ./expout]],[ignore],[ignore-nolog],[ignore-nolog])
863AT_CHECK([[cat ./stdout]],[ignore],[expout],[ignore-nolog])
864AT_CLEANUP