]> git.saurik.com Git - bison.git/blame - tests/javapush.at
java: add push-parser support
[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
31# Modify the grep tester from java.at
32# to ignore status so we can test for zero matching lines
33m4_define([AT_CHECK_JAVA_GREP],
34 [AT_CHECK([grep -c '^$2$' $1], [ignore], [m4_default([$3], [1])
35])
36])
37
38##################################################
39
40AT_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.
45m4_define([AT_TRIVIAL_GRAMMAR],[
46%define parser_class_name {YYParser}
47%error-verbose
48
49%code imports {
50import java.io.*;
51import java.util.*;
52}
53
54%%
55
56start: 'a' 'b' 'c' ;
57
58%%
59])
60
61# Define comon code across to be includede in
62# class Main for the trivial parser tests.
63m4_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
98m4_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
135m4_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
163AT_SETUP([Trivial Push Parser with api.push-pull verification])
164AT_BISON_OPTION_PUSHDEFS
165AT_DATA([[input.y]],[[%language "Java"
166]AT_TRIVIAL_PARSER[
167]])
168AT_BISON_OPTION_POPDEFS
169
170# Verify that the proper procedure(s) are generated for each case.
171AT_BISON_CHECK([[-Dapi.push-pull=pull -o Main.java input.y]])
172AT_CHECK_JAVA_GREP([[Main.java]],
173 [[.*public boolean parse ().*]],
174 [1])
175AT_CHECK_JAVA_GREP(
176 [[Main.java]],
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])
183AT_CHECK_JAVA_GREP(
184 [[Main.java]],
185 [[.*public int push_parse (int yylextoken, Object yylexval).*]],
186 [1])
187AT_BISON_CHECK([[-Dapi.push-pull=push -o Main.java input.y]])
188AT_CHECK_JAVA_GREP([[Main.java]],
189 [[.*public boolean parse ().*]],
190 [0])
191AT_CHECK_JAVA_GREP(
192 [[Main.java]],
193 [[.*public int push_parse (int yylextoken, Object yylexval).*]],
194 [1])
195
196AT_JAVA_COMPILE([[Main.java]])
197AT_JAVA_PARSER_CHECK([Main], 0, [], [stderr-nolog])
198AT_CLEANUP
199
200AT_SETUP([Trivial Push Parser with %initial-action])
201AT_BISON_OPTION_PUSHDEFS
202AT_DATA([[input.y]],[[%language "Java"
203%initial-action {
204System.err.println("Initial action invoked");
205}
206]AT_TRIVIAL_PARSER_INITIAL_ACTION[
207]])
208AT_BISON_OPTION_POPDEFS
209AT_BISON_CHECK([[-Dapi.push-pull=push -o Main.java input.y]])
210AT_CHECK_JAVA_GREP([[Main.java]],
211 [[System.err.println("Initial action invoked");]])
212AT_JAVA_COMPILE([[Main.java]])
213AT_JAVA_PARSER_CHECK([Main], 0, [], [stderr-nolog])
214# Verify that initial action is called exactly once.
215AT_CHECK_JAVA_GREP(
216 [[stderr]],
217 [[Initial action invoked]],
218 [1])
219AT_CLEANUP
220
221# Define a single copy of the Calculator grammar.
222m4_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%%
253input:
254 line
255| input line
256;
257
258line:
259 '\n'
260| exp '\n'
261 {System.out.println("total = "+$[]1);}
262| error '\n'
263;
264
265exp:
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
298AT_SETUP([Calc parser with api.push-pull both])
299AT_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
307AT_DATA([input],[[1 + 2 * 3 = 7
3081 + 2 * -3 = -5
309
310-1^2 = -1
311(-1)^2 = 1
312
313---1 = -1
314
3151 - 2 - 3 = -4
3161 - (2 - 3) = 2
317
3182^2^3 = 256
319(2^2)^3 = 64
320]])
321
322# Compose pieces to build the actual .y file.
323AT_DATA([Calc.y],[[/* Infix notation calculator--calc */
324%language "Java"
325%name-prefix "Calc"
326%define parser_class_name {Calc}
327
328%code {
329static 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 {
367public 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.
384AT_DATA([[expout]],[[Stack now 0
385Stack now 0 2
386Stack now 0 9
387Stack now 0 9 19
388Stack now 0 9 19 2
389Stack now 0 9 19 28
390Stack now 0 9 19 28 20
391Stack now 0 9 19 28 20 2
392Stack now 0 9 19 28 20 29
393Stack now 0 9 19 28
394Stack now 0 9
395Stack now 0 9 17
396Stack now 0 9 17 2
397Stack now 0 9 17 26
398Stack now 0 9
399Stack now 0 9 23
400Stack now 0 8
401Stack now 0 7
402Stack now 0 7 2
403Stack now 0 7 9
404Stack now 0 7 9 19
405Stack now 0 7 9 19 2
406Stack now 0 7 9 19 28
407Stack now 0 7 9 19 28 20
408Stack now 0 7 9 19 28 20 3
409Stack now 0 7 9 19 28 20 3 2
410Stack now 0 7 9 19 28 20 3 12
411Stack now 0 7 9 19 28 20 29
412Stack now 0 7 9 19 28
413Stack now 0 7 9
414Stack now 0 7 9 17
415Stack now 0 7 9 17 3
416Stack now 0 7 9 17 3 2
417Stack now 0 7 9 17 3 12
418Stack now 0 7 9 17 26
419Stack now 0 7 9
420Stack now 0 7 9 23
421Stack now 0 7 16
422Stack now 0 7
423Stack now 0 7 4
424Stack now 0 7 16
425Stack now 0 7
426Stack now 0 7 3
427Stack now 0 7 3 2
428Stack now 0 7 3 12
429Stack now 0 7 3 12 22
430Stack now 0 7 3 12 22 2
431Stack now 0 7 3 12 22 31
432Stack now 0 7 3 12
433Stack now 0 7 9
434Stack now 0 7 9 17
435Stack now 0 7 9 17 3
436Stack now 0 7 9 17 3 2
437Stack now 0 7 9 17 3 12
438Stack now 0 7 9 17 26
439Stack now 0 7 9
440Stack now 0 7 9 23
441Stack now 0 7 16
442Stack now 0 7
443Stack now 0 7 5
444Stack now 0 7 5 3
445Stack now 0 7 5 3 2
446Stack now 0 7 5 3 12
447Stack now 0 7 5 14
448Stack now 0 7 5 14 25
449Stack now 0 7 9
450Stack now 0 7 9 22
451Stack now 0 7 9 22 2
452Stack now 0 7 9 22 31
453Stack now 0 7 9
454Stack now 0 7 9 17
455Stack now 0 7 9 17 2
456Stack now 0 7 9 17 26
457Stack now 0 7 9
458Stack now 0 7 9 23
459Stack now 0 7 16
460Stack now 0 7
461Stack now 0 7 4
462Stack now 0 7 16
463Stack now 0 7
464Stack now 0 7 3
465Stack now 0 7 3 3
466Stack now 0 7 3 3 3
467Stack now 0 7 3 3 3 2
468Stack now 0 7 3 3 3 12
469Stack now 0 7 3 3 12
470Stack now 0 7 3 12
471Stack now 0 7 9
472Stack now 0 7 9 17
473Stack now 0 7 9 17 3
474Stack now 0 7 9 17 3 2
475Stack now 0 7 9 17 3 12
476Stack now 0 7 9 17 26
477Stack now 0 7 9
478Stack now 0 7 9 23
479Stack now 0 7 16
480Stack now 0 7
481Stack now 0 7 4
482Stack now 0 7 16
483Stack now 0 7
484Stack now 0 7 2
485Stack now 0 7 9
486Stack now 0 7 9 18
487Stack now 0 7 9 18 2
488Stack now 0 7 9 18 27
489Stack now 0 7 9
490Stack now 0 7 9 18
491Stack now 0 7 9 18 2
492Stack now 0 7 9 18 27
493Stack now 0 7 9
494Stack now 0 7 9 17
495Stack now 0 7 9 17 3
496Stack now 0 7 9 17 3 2
497Stack now 0 7 9 17 3 12
498Stack now 0 7 9 17 26
499Stack now 0 7 9
500Stack now 0 7 9 23
501Stack now 0 7 16
502Stack now 0 7
503Stack now 0 7 2
504Stack now 0 7 9
505Stack now 0 7 9 18
506Stack now 0 7 9 18 5
507Stack now 0 7 9 18 5 2
508Stack now 0 7 9 18 5 14
509Stack now 0 7 9 18 5 14 18
510Stack now 0 7 9 18 5 14 18 2
511Stack now 0 7 9 18 5 14 18 27
512Stack now 0 7 9 18 5 14
513Stack now 0 7 9 18 5 14 25
514Stack now 0 7 9 18 27
515Stack now 0 7 9
516Stack now 0 7 9 17
517Stack now 0 7 9 17 2
518Stack now 0 7 9 17 26
519Stack now 0 7 9
520Stack now 0 7 9 23
521Stack now 0 7 16
522Stack now 0 7
523Stack now 0 7 4
524Stack now 0 7 16
525Stack now 0 7
526Stack now 0 7 2
527Stack now 0 7 9
528Stack now 0 7 9 22
529Stack now 0 7 9 22 2
530Stack now 0 7 9 22 31
531Stack now 0 7 9 22 31 22
532Stack now 0 7 9 22 31 22 2
533Stack now 0 7 9 22 31 22 31
534Stack now 0 7 9 22 31
535Stack now 0 7 9
536Stack now 0 7 9 17
537Stack now 0 7 9 17 2
538Stack now 0 7 9 17 26
539Stack now 0 7 9
540Stack now 0 7 9 23
541Stack now 0 7 16
542Stack now 0 7
543Stack now 0 7 5
544Stack now 0 7 5 2
545Stack now 0 7 5 14
546Stack now 0 7 5 14 22
547Stack now 0 7 5 14 22 2
548Stack now 0 7 5 14 22 31
549Stack now 0 7 5 14
550Stack now 0 7 5 14 25
551Stack now 0 7 9
552Stack now 0 7 9 22
553Stack now 0 7 9 22 2
554Stack now 0 7 9 22 31
555Stack now 0 7 9
556Stack now 0 7 9 17
557Stack now 0 7 9 17 2
558Stack now 0 7 9 17 26
559Stack now 0 7 9
560Stack now 0 7 9 23
561Stack now 0 7 16
562Stack now 0 7
563Stack now 0 7 15
564]])
565
566AT_BISON_CHECK([PUSHPULLFLAG [-o Calc.java Calc.y]])
567AT_JAVA_COMPILE([[Calc.java]])
568#Verify that this is a push parser.
569AT_CHECK_JAVA_GREP([[Calc.java]],
570 [[.*public void push_parse_initialize().*]])
571# Capture stderr output for comparison purposes.
572AT_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).
578AT_CHECK([[sed -e '/^Stack now.*$/p' -e d ./stderr|tee jj]],[ignore],[expout],[ignore-nolog])
579AT_BISON_OPTION_POPDEFS
580AT_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.
585AT_SETUP([Calc parser with %locations %code lexer and api.push-pull both])
586AT_BISON_OPTION_PUSHDEFS
587
588AT_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 {
645class 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 {
670public 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.
686AT_DATA([output],[[total = 7
687total = -5
688total = -1
689total = 1
690total = -1
691total = -4
692total = 2
693total = 256
694total = 64
695]])
696
697AT_DATA([locations],[[Next token is token "number" (1.1: 1)
698Next token is token '+' (1.2: 1)
699Next token is token "number" (1.3: 2)
700Next token is token '*' (1.4: 2)
701Next token is token "number" (1.5: 3)
702Next token is token '=' (1.6: 3)
703Next token is token '=' (1.6: 3)
704Next token is token '=' (1.6: 3)
705Next token is token "number" (1.7: 7)
706Next token is token '\n' (2.0: 7)
707Next token is token '\n' (2.0: 7)
708Next token is token "number" (2.1: 1)
709Next token is token '+' (2.2: 1)
710Next token is token "number" (2.3: 2)
711Next token is token '*' (2.4: 2)
712Next token is token '-' (2.5: 2)
713Next token is token "number" (2.6: 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.7: 3)
718Next token is token '-' (2.8: 3)
719Next token is token "number" (2.9: 5)
720Next token is token '\n' (3.0: 5)
721Next token is token '\n' (3.0: 5)
722Next token is token '\n' (3.0: 5)
723Next token is token '\n' (4.0: 5)
724Next token is token '-' (4.1: 5)
725Next token is token "number" (4.2: 1)
726Next token is token '^' (4.3: 1)
727Next token is token "number" (4.4: 2)
728Next token is token '=' (4.5: 2)
729Next token is token '=' (4.5: 2)
730Next token is token '=' (4.5: 2)
731Next token is token '-' (4.6: 2)
732Next token is token "number" (4.7: 1)
733Next token is token '\n' (5.0: 1)
734Next token is token '\n' (5.0: 1)
735Next token is token '\n' (5.0: 1)
736Next token is token '(' (5.1: 1)
737Next token is token '-' (5.2: 1)
738Next token is token "number" (5.3: 1)
739Next token is token ')' (5.4: 1)
740Next token is token ')' (5.4: 1)
741Next token is token '^' (5.5: 1)
742Next token is token "number" (5.6: 2)
743Next token is token '=' (5.7: 2)
744Next token is token '=' (5.7: 2)
745Next token is token "number" (5.8: 1)
746Next token is token '\n' (6.0: 1)
747Next token is token '\n' (6.0: 1)
748Next token is token '\n' (7.0: 1)
749Next token is token '-' (7.1: 1)
750Next token is token '-' (7.2: 1)
751Next token is token '-' (7.3: 1)
752Next token is token "number" (7.4: 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.5: 1)
757Next token is token '-' (7.6: 1)
758Next token is token "number" (7.7: 1)
759Next token is token '\n' (8.0: 1)
760Next token is token '\n' (8.0: 1)
761Next token is token '\n' (8.0: 1)
762Next token is token '\n' (9.0: 1)
763Next token is token "number" (9.1: 1)
764Next token is token '-' (9.2: 1)
765Next token is token "number" (9.3: 2)
766Next token is token '-' (9.4: 2)
767Next token is token '-' (9.4: 2)
768Next token is token "number" (9.5: 3)
769Next token is token '=' (9.6: 3)
770Next token is token '=' (9.6: 3)
771Next token is token '-' (9.7: 3)
772Next token is token "number" (9.8: 4)
773Next token is token '\n' (10.0: 4)
774Next token is token '\n' (10.0: 4)
775Next token is token '\n' (10.0: 4)
776Next token is token "number" (10.1: 1)
777Next token is token '-' (10.2: 1)
778Next token is token '(' (10.3: 1)
779Next token is token "number" (10.4: 2)
780Next token is token '-' (10.5: 2)
781Next token is token "number" (10.6: 3)
782Next token is token ')' (10.7: 3)
783Next token is token ')' (10.7: 3)
784Next token is token '=' (10.8: 3)
785Next token is token '=' (10.8: 3)
786Next token is token "number" (10.9: 2)
787Next token is token '\n' (11.0: 2)
788Next token is token '\n' (11.0: 2)
789Next token is token '\n' (12.0: 2)
790Next token is token "number" (12.1: 2)
791Next token is token '^' (12.2: 2)
792Next token is token "number" (12.3: 2)
793Next token is token '^' (12.4: 2)
794Next token is token "number" (12.5: 3)
795Next token is token '=' (12.6: 3)
796Next token is token '=' (12.6: 3)
797Next token is token '=' (12.6: 3)
798Next token is token "number" (12.7: 256)
799Next token is token '\n' (13.0: 256)
800Next token is token '\n' (13.0: 256)
801Next token is token '(' (13.1: 256)
802Next token is token "number" (13.2: 2)
803Next token is token '^' (13.3: 2)
804Next token is token "number" (13.4: 2)
805Next token is token ')' (13.5: 2)
806Next token is token ')' (13.5: 2)
807Next token is token '^' (13.6: 2)
808Next token is token "number" (13.7: 3)
809Next token is token '=' (13.8: 3)
810Next token is token '=' (13.8: 3)
811Next token is token "number" (13.9: 64)
812Next token is token '\n' (14.0: 64)
813Next 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
822AT_DATA([input],[[1 + 2 * 3 = 7
8231 + 2 * -3 = -5
824
825-1^2 = -1
826(-1)^2 = 1
827
828---1 = -1
829
8301 - 2 - 3 = -4
8311 - (2 - 3) = 2
832
8332^2^3 = 256
834(2^2)^3 = 64
835]])
836
837AT_BISON_CHECK([PUSHPULLFLAG [-o Calc.java Calc.y]])
838AT_JAVA_COMPILE([[Calc.java]])
839# Verify that this is a push parser
840AT_CHECK_JAVA_GREP([[Calc.java]],
841 [[.*public void push_parse_initialize().*]])
842# Capture the stdout and stderr output for comparison purposes.
843AT_JAVA_PARSER_CHECK([Calc input], 0, [stdout-nolog], [stderr-nolog])
844# 1. Check that the token locations are correct
845AT_CHECK([[cp -f ./locations ./expout]],[ignore],[ignore-nolog],[ignore-nolog])
846AT_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
848AT_CHECK([[rm -f ./expout; cp -f ./output ./expout]],[ignore],[ignore-nolog],[ignore-nolog])
849AT_CHECK([[cat ./stdout]],[ignore],[expout],[ignore-nolog])
850AT_CLEANUP