X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/8405b70c057cf1e117e81a77114b055d7c9b59f1..34cdeddfa54df8c85b20bf013a0b82053a5148f2:/tests/java.at?ds=sidebyside diff --git a/tests/java.at b/tests/java.at index 6d991c1b..b6348810 100644 --- a/tests/java.at +++ b/tests/java.at @@ -1,22 +1,19 @@ -# Simple calculator. -*- Autotest -*- +# Java tests for simple calculator. -*- Autotest -*- -# Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software -# Foundation, Inc. +# Copyright (C) 2007 Free Software Foundation, Inc. -# This program is free software; you can redistribute it and/or modify +# This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2, or (at your option) -# any later version. - +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -# 02110-1301, USA. +# along with this program. If not, see . AT_BANNER([[Java Calculator.]]) @@ -26,7 +23,7 @@ AT_BANNER([[Java Calculator.]]) # ------------------------- # -# _AT_DATA_JAVA_CALC_Y($1, $2, $3, [BISON-DIRECTIVES], [BISON-EPILOGUE]) +# _AT_DATA_JAVA_CALC_Y($1, $2, $3, [BISON-DIRECTIVES]) # ---------------------------------------------------------------------- # Produce `calc.y'. Don't call this macro directly, because it contains # some occurrences of `$1' etc. which will be interpreted by m4. So @@ -38,11 +35,12 @@ m4_define([_AT_DATA_JAVA_CALC_Y], AT_DATA([Calc.y], [[/* Infix notation calculator--calc */ %language "Java" -%name-prefix "Calc"] +%name-prefix "Calc" %define parser_class_name "Calc" %define public -$4[ +]$4[ + %code imports { import java.io.StreamTokenizer; import java.io.InputStream; @@ -94,52 +92,130 @@ exp: | '!' { $$ = new Integer (0); return YYERROR; } | '-' error { $$ = new Integer (0); return YYERROR; } ; + +]AT_LEXPARAM_IF([[ +%code lexer { +]], +[[ %% +class CalcLexer implements Calc.Lexer { +]])[ + StreamTokenizer st; + + public ]AT_LEXPARAM_IF([[YYLexer]], [[CalcLexer]]) (InputStream is) + { + st = new StreamTokenizer (new InputStreamReader (is)); + st.resetSyntax (); + st.eolIsSignificant (true); + st.whitespaceChars (9, 9); + st.whitespaceChars (32, 32); + st.wordChars (48, 57); + } + +AT_LOCATION_IF([[ + Position yystartpos; + Position yyendpos = new Position (1); - class Position { - public int line; - - public Position () - { - line = 0; - } - - public Position (int l) - { - line = l; - } - - public long getHashCode () - { - return line; - } - - public boolean equals (Position l) - { - return l.line == line; - } - - public String toString () - { - return Integer.toString (line); - } - - public int lineno () - { - return line; - } + public Position getStartPos() { + return yystartpos; } -]$5 -]) + public Position getEndPos() { + return yyendpos; + } + + public void yyerror (Calc.Location l, String s) + { + if (l == null) + System.err.println (s); + else + System.err.println (l.begin + ": " + s); + } +]], [[ + public void yyerror (String s) + { + System.err.println (s); + } +]])[ + + Integer yylval; + + public Object getLVal() { + return yylval; + } + + public int yylex () throws IOException { + int ttype = st.nextToken (); + ]AT_LOCATION_IF([[yystartpos = yyendpos;]])[ + if (ttype == st.TT_EOF) + return Calc.EOF; + + else if (ttype == st.TT_EOL) + { + ]AT_LOCATION_IF([[yyendpos = new Position (yyendpos.lineno () + 1);]])[ + return (int) '\n'; + } + + else if (ttype == st.TT_WORD) + { + yylval = new Integer (st.sval); + return Calc.NUM; + } + + else + return st.ttype; + } + + +]AT_LEXPARAM_IF([[ +}; +%%]], [[ +}]]) + +[ +class Position { + public int line; + + public Position () + { + line = 0; + } + + public Position (int l) + { + line = l; + } + + public long getHashCode () + { + return line; + } + + public boolean equals (Position l) + { + return l.line == line; + } + + public String toString () + { + return Integer.toString (line); + } + + public int lineno () + { + return line; + } +} + +]]) ])# _AT_DATA_JAVA_CALC_Y -# AT_DATA_CALC_Y([BISON-OPTIONS], [BISON-EPILOGUE]) +# AT_DATA_CALC_Y([BISON-OPTIONS]) # ------------------------------------------------- # Produce `calc.y'. m4_define([AT_DATA_JAVA_CALC_Y], -[_AT_DATA_JAVA_CALC_Y($[1], $[2], $[3], [$1], [$2]) +[_AT_DATA_JAVA_CALC_Y($[1], $[2], $[3], [$1]) ]) @@ -149,7 +225,8 @@ m4_define([AT_DATA_JAVA_CALC_Y], # Compile SOURCES into Java class files. Skip the test if java or javac is # not installed. m4_define([AT_JAVA_COMPILE], -[AT_CHECK([test -n "$CONF_JAVA$CONF_JAVAC" || exit 77]) +[AT_CHECK([test -n "$CONF_JAVA" || exit 77 +test -n "$CONF_JAVAC" || exit 77]) AT_CHECK([$SHELL ../../../javacomp.sh $1], 0, [ignore], [ignore])]) @@ -196,7 +273,7 @@ mv at-expout expout]]) AT_CHECK([cat stderr], 0, [expout]) ]) -# _AT_CHECK_JAVA_CALC([BISON-DIRECTIVES], [BISON-CODE], [BISON-EPILOGUE]) +# _AT_CHECK_JAVA_CALC([BISON-DIRECTIVES], [BISON-CODE]) # ----------------------------------------------------------------------- # Start a testing chunk which compiles `calc' grammar with # BISON-DIRECTIVES, and performs several tests over the parser. @@ -209,7 +286,7 @@ AT_BISON_OPTION_PUSHDEFS([$1]) AT_DATA_JAVA_CALC_Y([$1 %code { $2 -}], [$3]) +}]) AT_CHECK([bison -o Calc.java Calc.y]) AT_JAVA_COMPILE([Calc.java]) @@ -288,14 +365,16 @@ AT_CLEANUP ])# _AT_CHECK_JAVA_CALC -# AT_CHECK_JAVA_CALC([BISON-DIRECTIVES], [BISON-EPILOGUE]) +# AT_CHECK_JAVA_CALC([BISON-DIRECTIVES]) # -------------------------------------------------------- # Start a testing chunk which compiles `calc' grammar with # BISON-DIRECTIVES, and performs several tests over the parser. # Run the test with and without %error-verbose. m4_define([AT_CHECK_JAVA_CALC], -[_AT_CHECK_JAVA_CALC([$1], [$2], [$3]) -_AT_CHECK_JAVA_CALC([%error-verbose $1], [$2], [$3]) +[_AT_CHECK_JAVA_CALC([$1], [$2]) +_AT_CHECK_JAVA_CALC([%error-verbose $1], [$2]) +_AT_CHECK_JAVA_CALC([%locations $1], [$2]) +_AT_CHECK_JAVA_CALC([%error-verbose %locations $1], [$2]) ])# AT_CHECK_JAVA_CALC @@ -303,113 +382,18 @@ _AT_CHECK_JAVA_CALC([%error-verbose $1], [$2], [$3]) # Simple LALR Calculator. # # ------------------------ # -dnl AT_CHECK_JAVA_CALC([], []) - -AT_CHECK_JAVA_CALC([%define single_class %locations], [[ - StreamTokenizer st; - - public Calc (InputStream is) - { - Reader r = new InputStreamReader (is); - st = new StreamTokenizer(r); - st.resetSyntax (); - st.eolIsSignificant (true); - st.whitespaceChars (9, 9); - st.whitespaceChars (32, 32); - st.wordChars (48, 57); - - yyendpos = new Position (1); - } - - public int yylex () throws IOException { - int ttype = st.nextToken (); - yystartpos = yyendpos; - if (ttype == st.TT_EOF) - return EOF; - - else if (ttype == st.TT_EOL) - { - yyendpos = new Position (yyendpos.lineno () + 1); - return (int) '\n'; - } - - else if (ttype == st.TT_WORD) - { - yylval = new Integer (st.sval); - return NUM; - } - - else - return st.ttype; - } - - public void yyerror (Location l, String s) - { - if (l == null) - System.err.println (s); - else - System.err.println (l.begin + ": " + s); - } - - public static void main (String args[]) throws IOException - { - new Calc (System.in).parse (); - } -]]) - -AT_CHECK_JAVA_CALC([%pure-parser], [[ +AT_CHECK_JAVA_CALC([], [[ public static void main (String args[]) throws IOException { CalcLexer l = new CalcLexer (System.in); Calc p = new Calc (l); p.parse (); } -]], [[ -class CalcLexer implements Calc.Lexer { - Integer yylval; - - StreamTokenizer st; - - public Object getLVal () - { - return yylval; - } - - public CalcLexer (InputStream is) - { - Reader r = new InputStreamReader (is); - st = new StreamTokenizer(r); - st.resetSyntax (); - st.eolIsSignificant (true); - st.whitespaceChars (9, 9); - st.whitespaceChars (32, 32); - st.wordChars (48, 57); - } - - public int yylex () throws IOException { - int ttype = st.nextToken (); - if (ttype == st.TT_EOF) - return Calc.EOF; - - else if (ttype == st.TT_EOL) - return (int) '\n'; - - else if (ttype == st.TT_WORD) - { - yylval = new Integer (st.sval); - return Calc.NUM; - } - - else - return st.ttype; - } +]]) - - public void yyerror (String s) +AT_CHECK_JAVA_CALC([%lex-param { InputStream is } ], [[ + public static void main (String args[]) throws IOException { - System.err.println (s); + new Calc (System.in).parse (); } -} ]]) - -dnl AT_CHECK_JAVA_CALC([%pure-parser %locations], [])