X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/02975b9aade52df362645b82a81ac2134290e221..432ac57aaae89de7a4305dc72c5a5b716c6defc4:/tests/calc.at?ds=sidebyside diff --git a/tests/calc.at b/tests/calc.at index 694327e5..26249088 100644 --- a/tests/calc.at +++ b/tests/calc.at @@ -1,22 +1,20 @@ # Simple calculator. -*- Autotest -*- -# Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software +# Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 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 . ## ---------------------------------------------------- ## ## Compile the grammar described in the documentation. ## @@ -41,7 +39,7 @@ AT_DATA_GRAMMAR([calc.y], [[/* Infix notation calculator--calc */ ]$4 AT_SKEL_CC_IF( -[%define "global_tokens_and_yystype"])[ +[%define global_tokens_and_yystype])[ %{ #include @@ -141,7 +139,7 @@ exp: | '-' exp %prec NEG { $$ = -$2; } | exp '^' exp { $$ = power ($1, $3); } | '(' exp ')' { $$ = $2; } -| '(' error ')' { $$ = 1111; } +| '(' error ')' { $$ = 1111; yyerrok; } | '!' { $$ = 0; YYERROR; } | '-' error { $$ = 0; YYERROR; } ; @@ -336,7 +334,7 @@ main (int argc, const char **argv) ]AT_SKEL_CC_IF([], [m4_bmatch([$4], [%debug], [ yydebug = 1;])])[ - status = yyparse (]AT_PARAM_IF([&result, &count])[); + status = yyparse (]AT_PARAM_IF([[&result, &count]])[); fclose (input); if (global_result != result) abort (); @@ -457,9 +455,9 @@ AT_BISON_OPTION_PUSHDEFS([$1]) AT_DATA_CALC_Y([$1]) AT_SKEL_CC_IF( - [AT_CHECK([bison -o calc.cc calc.y]) + [AT_BISON_CHECK([-o calc.cc calc.y]) AT_COMPILE_CXX([calc])], - [AT_CHECK([bison -o calc.c calc.y]) + [AT_BISON_CHECK([-o calc.c calc.y]) AT_COMPILE([calc])]) # Test the priorities. @@ -531,6 +529,14 @@ _AT_CHECK_CALC_ERROR([$1], [0], [(- *) + (0 0) = 1], [113], [1.4: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 1.12: syntax error, unexpected number calc: error: 2222 != 1]) + +# Check that yyerrok works properly: second error is not reported, +# third and fourth are. Parse status is succesfull. +_AT_CHECK_CALC_ERROR([$1], [0], [(* *) + (*) + (*)], [113], +[1.2: syntax error, unexpected '*', expecting number or '-' or '(' or '!' +1.10: syntax error, unexpected '*', expecting number or '-' or '(' or '!' +1.16: syntax error, unexpected '*', expecting number or '-' or '(' or '!']) + AT_BISON_OPTION_POPDEFS AT_CLEANUP @@ -561,8 +567,8 @@ AT_CHECK_CALC_LALR([%verbose]) AT_CHECK_CALC_LALR([%yacc]) AT_CHECK_CALC_LALR([%error-verbose]) -AT_CHECK_CALC_LALR([%pure-parser %locations]) -AT_CHECK_CALC_LALR([%push-parser %locations]) +AT_CHECK_CALC_LALR([%define api.pure %locations]) +AT_CHECK_CALC_LALR([%define api.push_pull "both" %define api.pure %locations]) AT_CHECK_CALC_LALR([%error-verbose %locations]) AT_CHECK_CALC_LALR([%error-verbose %locations %defines %name-prefix "calc" %verbose %yacc]) @@ -570,10 +576,10 @@ AT_CHECK_CALC_LALR([%error-verbose %locations %defines %name-prefix "calc" %verb AT_CHECK_CALC_LALR([%debug]) AT_CHECK_CALC_LALR([%error-verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc]) -AT_CHECK_CALC_LALR([%pure-parser %error-verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc]) -AT_CHECK_CALC_LALR([%push-parser %error-verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc]) +AT_CHECK_CALC_LALR([%define api.pure %error-verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc]) +AT_CHECK_CALC_LALR([%define api.push_pull "both" %define api.pure %error-verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc]) -AT_CHECK_CALC_LALR([%pure-parser %error-verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}]) +AT_CHECK_CALC_LALR([%define api.pure %error-verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}]) # ----------------------- # @@ -599,7 +605,7 @@ AT_CHECK_CALC_GLR([%verbose]) AT_CHECK_CALC_GLR([%yacc]) AT_CHECK_CALC_GLR([%error-verbose]) -AT_CHECK_CALC_GLR([%pure-parser %locations]) +AT_CHECK_CALC_GLR([%define api.pure %locations]) AT_CHECK_CALC_GLR([%error-verbose %locations]) AT_CHECK_CALC_GLR([%error-verbose %locations %defines %name-prefix "calc" %verbose %yacc]) @@ -607,9 +613,9 @@ AT_CHECK_CALC_GLR([%error-verbose %locations %defines %name-prefix "calc" %verbo AT_CHECK_CALC_GLR([%debug]) AT_CHECK_CALC_GLR([%error-verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc]) -AT_CHECK_CALC_GLR([%pure-parser %error-verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc]) +AT_CHECK_CALC_GLR([%define api.pure %error-verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc]) -AT_CHECK_CALC_GLR([%pure-parser %error-verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}]) +AT_CHECK_CALC_GLR([%define api.pure %error-verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}]) # ----------------------------- # @@ -618,12 +624,15 @@ AT_CHECK_CALC_GLR([%pure-parser %error-verbose %debug %locations %defines %name- AT_BANNER([[Simple LALR(1) C++ Calculator.]]) +# First let's try using %skeleton +AT_CHECK_CALC([%skeleton "lalr1.cc" %defines %locations]) + # AT_CHECK_CALC_LALR1_CC([BISON-OPTIONS]) # --------------------------------------- # Start a testing chunk which compiles `calc' grammar with # the C++ skeleton, and performs several tests over the parser. m4_define([AT_CHECK_CALC_LALR1_CC], -[AT_CHECK_CALC([%skeleton "lalr1.cc" %defines %locations] $@)]) +[AT_CHECK_CALC([%language "C++" %defines %locations] $@)]) AT_CHECK_CALC_LALR1_CC([]) AT_CHECK_CALC_LALR1_CC([%error-verbose %name-prefix "calc" %verbose %yacc]) @@ -642,12 +651,15 @@ AT_CHECK_CALC_LALR1_CC([%pure-parser %error-verbose %debug %name-prefix "calc" % AT_BANNER([[Simple GLR C++ Calculator.]]) +# Again, we try also using %skeleton. +AT_CHECK_CALC([%skeleton "glr.cc" %defines %locations]) + # AT_CHECK_CALC_GLR_CC([BISON-OPTIONS]) # ------------------------------------- # Start a testing chunk which compiles `calc' grammar with # the GLR C++ skeleton, and performs several tests over the parser. m4_define([AT_CHECK_CALC_GLR_CC], -[AT_CHECK_CALC([%skeleton "glr.cc" %defines %locations] $@)]) +[AT_CHECK_CALC([%language "C++" %glr-parser %defines %locations] $@)]) AT_CHECK_CALC_GLR_CC([]) AT_CHECK_CALC_GLR_CC([%error-verbose %name-prefix "calc" %verbose %yacc])