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