]> git.saurik.com Git - bison.git/blobdiff - tests/calc.at
tests: fix bison wrapper.
[bison.git] / tests / calc.at
index b3955ca5cbacc62bdcc4025e2296c0c4b693d3a1..477c92d3759f5fe90bb5784c645498db6c796156 100644 (file)
@@ -1,6 +1,6 @@
 # Simple calculator.                         -*- Autotest -*-
 
-# Copyright (C) 2000-2010 Free Software Foundation, Inc.
+# Copyright (C) 2000-2012 Free Software Foundation, Inc.
 
 # 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
@@ -137,12 +137,12 @@ int
     {
       unget_char (]AT_LEX_PRE_ARGS[ c);
       ]AT_VAL[.ival = read_signed_integer (]AT_LEX_ARGS[);
-      return NUM;
+      return ]AT_TOKEN_PREFIX[NUM;
     }
 
   /* Return end-of-file.  */
   if (c == EOF)
-    return CALC_EOF;
+    return ]AT_TOKEN_PREFIX[CALC_EOF;
 
   /* Return single chars. */
   return c;
@@ -170,18 +170,18 @@ AT_SKEL_CC_IF(
     Point last;
   };
 
-# define YYLLOC_DEFAULT(Current, Rhs, N)                \
-do {                                                    \
-  if (N)                                                \
-    {                                                   \
-      (Current).first = (Rhs)[1].first;                        \
-      (Current).last  = (Rhs)[N].last;                  \
-    }                                                   \
-  else                                                  \
-    {                                                   \
-      (Current).first = (Current).last = (Rhs)[0].last;        \
-    }                                                   \
-} while (false)
+# define YYLLOC_DEFAULT(Current, Rhs, N)                                \
+  do                                                                    \
+    if (N)                                                              \
+      {                                                                 \
+        (Current).first = YYRHSLOC (Rhs, 1).first;                      \
+        (Current).last  = YYRHSLOC (Rhs, N).last;                       \
+      }                                                                 \
+    else                                                                \
+      {                                                                 \
+        (Current).first = (Current).last = YYRHSLOC (Rhs, 0).last;      \
+      }                                                                 \
+  while (false)
 
 ]])[
   /* Exercise pre-prologue dependency to %union.  */
@@ -207,6 +207,7 @@ extern FILE *input;]AT_SKEL_CC_IF([[
 
 %code
 {
+#include <assert.h>
 #include <stdlib.h>
 #include <string.h>
 #if HAVE_UNISTD_H
@@ -233,27 +234,27 @@ static void yyerror (AT_YYERROR_ARG_LOC_IF([YYLTYPE *llocp, ])
 int yylex (]AT_LEX_FORMALS[);
 }
 
-]AT_SKEL_CC_IF([AT_LOCATION_TYPE_IF([], [
+]AT_SKEL_CC_IF([AT_LOCATION_IF([AT_LOCATION_TYPE_IF([], [
 /* The lalr1.cc skeleton, for backward compatibility, defines
    a constructor for position that initializes the filename.  The
    glr.cc skeleton does not (and in fact cannot: location/position
    are stored in a union, from which objects with constructors are
-   excluded in C++. */
+   excluded in C++). */
 %initial-action {
-  @$.initialize (0);
+  @$.initialize ();
 }
-])])[
+])])])[
 
 /* Bison Declarations */
 %token CALC_EOF 0 "end of input"
 %token <ival> NUM "number"
 %type  <ival> exp
 
-%nonassoc '=' /* comparison           */
+%nonassoc '='   /* comparison          */
 %left '-' '+'
 %left '*' '/'
-%left NEG     /* negation--unary minus */
-%right '^'    /* exponentiation        */
+%precedence NEG /* negation--unary minus */
+%right '^'      /* exponentiation        */
 
 /* Grammar follows */
 %%
@@ -304,9 +305,8 @@ exp:
 
 /* A C++ error reporting function.  */
 void
-AT_NAME_PREFIX::parser::error (const location_type& l, const std::string& m)
+AT_NAME_PREFIX::parser::error (AT_LOCATION_IF([const location_type& l, ])const std::string& m)
 {
-  (void) l;
   std::cerr << AT_LOCATION_IF([l << ": " << ])m << std::endl;
 }
 
@@ -333,10 +333,10 @@ AT_YYERROR_SEES_LOC_IF([
            AT_LOC_FIRST_LINE, AT_LOC_FIRST_COLUMN);
   if (AT_LOC_FIRST_LINE != AT_LOC_LAST_LINE)
     fprintf (stderr, "-%d.%d",
-            AT_LOC_LAST_LINE,  AT_LOC_LAST_COLUMN - 1);
+             AT_LOC_LAST_LINE,  AT_LOC_LAST_COLUMN - 1);
   else if (AT_LOC_FIRST_COLUMN != AT_LOC_LAST_COLUMN - 1)
     fprintf (stderr, "-%d",
-            AT_LOC_LAST_COLUMN - 1);
+             AT_LOC_LAST_COLUMN - 1);
   fprintf (stderr, ": ");])
   fprintf (stderr, "%s\n", s);
 }])[
@@ -347,8 +347,7 @@ static int
 power (int base, int exponent)
 {
   int res = 1;
-  if (exponent < 0)
-    exit (3);
+  assert (0 <= exponent);
   for (/* Niente */; exponent; --exponent)
     res *= base;
   return res;
@@ -443,7 +442,7 @@ AT_PARSER_CHECK([./calc input], 0, [], [stderr])
 # If BISON-OPTIONS contains `%location', then make sure the ERROR-LOCATION
 # is correctly output on stderr.
 #
-# If BISON-OPTIONS contains `%error-verbose', then make sure the
+# If BISON-OPTIONS contains `%define parse.error verbose', then make sure the
 # IF-YYERROR-VERBOSE message is properly output after `syntax error, '
 # on STDERR.
 #
@@ -485,7 +484,7 @@ AT_YYERROR_SEES_LOC_IF([],
 [[sed 's/^[-0-9.]*: //' expout >at-expout
 mv at-expout expout]])
 # 4. If error-verbose is not used, strip the`, unexpected....' part.
-m4_bmatch([$1], [%error-verbose], [],
+m4_bmatch([$1], [%define parse.error verbose], [],
 [[sed 's/syntax error, .*$/syntax error/' expout >at-expout
 mv at-expout expout]])
 # 5. Check
@@ -615,21 +614,22 @@ AT_CHECK_CALC_LALR([%locations])
 AT_CHECK_CALC_LALR([%name-prefix="calc"]) dnl test deprecated `='
 AT_CHECK_CALC_LALR([%verbose])
 AT_CHECK_CALC_LALR([%yacc])
-AT_CHECK_CALC_LALR([%error-verbose])
+AT_CHECK_CALC_LALR([%define parse.error verbose])
 
 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([%define parse.error verbose %locations])
 
-AT_CHECK_CALC_LALR([%error-verbose %locations %defines %name-prefix "calc" %verbose %yacc])
+AT_CHECK_CALC_LALR([%define parse.error verbose %locations %defines %name-prefix "calc" %verbose %yacc])
+AT_CHECK_CALC_LALR([%define parse.error verbose %locations %defines %name-prefix "calc" %define api.tokens.prefix "TOK_" %verbose %yacc])
 
 AT_CHECK_CALC_LALR([%debug])
-AT_CHECK_CALC_LALR([%error-verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc])
+AT_CHECK_CALC_LALR([%define parse.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([%define api.pure %define parse.error verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc])
+AT_CHECK_CALC_LALR([%define api.push-pull both %define api.pure %define parse.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 %parse-param {semantic_value *result} %parse-param {int *count}])
+AT_CHECK_CALC_LALR([%define api.pure %define parse.error verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
 
 
 # ----------------------- #
@@ -653,19 +653,20 @@ AT_CHECK_CALC_GLR([%locations])
 AT_CHECK_CALC_GLR([%name-prefix "calc"])
 AT_CHECK_CALC_GLR([%verbose])
 AT_CHECK_CALC_GLR([%yacc])
-AT_CHECK_CALC_GLR([%error-verbose])
+AT_CHECK_CALC_GLR([%define parse.error verbose])
 
 AT_CHECK_CALC_GLR([%define api.pure %locations])
-AT_CHECK_CALC_GLR([%error-verbose %locations])
+AT_CHECK_CALC_GLR([%define parse.error verbose %locations])
 
-AT_CHECK_CALC_GLR([%error-verbose %locations %defines %name-prefix "calc" %verbose %yacc])
+AT_CHECK_CALC_GLR([%define parse.error verbose %locations %defines %name-prefix "calc" %verbose %yacc])
 
 AT_CHECK_CALC_GLR([%debug])
-AT_CHECK_CALC_GLR([%error-verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc])
+AT_CHECK_CALC_GLR([%define parse.error verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc])
+AT_CHECK_CALC_GLR([%define parse.error verbose %debug %locations %defines %name-prefix "calc" %define api.tokens.prefix "TOK_" %verbose %yacc])
 
-AT_CHECK_CALC_GLR([%define api.pure %error-verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc])
+AT_CHECK_CALC_GLR([%define api.pure %define parse.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 %parse-param {semantic_value *result} %parse-param {int *count}])
+AT_CHECK_CALC_GLR([%define api.pure %define parse.error verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
 
 
 # ----------------------------- #
@@ -682,16 +683,19 @@ AT_CHECK_CALC([%skeleton "lalr1.cc" %defines %locations])
 # 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([%language "C++" %defines %locations] $@)])
+[AT_CHECK_CALC([%language "C++" %defines] $@)])
 
 AT_CHECK_CALC_LALR1_CC([])
-AT_CHECK_CALC_LALR1_CC([%define location_type Span])
-AT_CHECK_CALC_LALR1_CC([%error-verbose %name-prefix "calc" %verbose %yacc])
-AT_CHECK_CALC_LALR1_CC([%error-verbose %debug %name-prefix "calc" %verbose %yacc])
+AT_CHECK_CALC_LALR1_CC([%locations])
+AT_CHECK_CALC_LALR1_CC([%locations %define location_type Span])
+AT_CHECK_CALC_LALR1_CC([%locations %define parse.error verbose %name-prefix "calc" %verbose %yacc])
 
-AT_CHECK_CALC_LALR1_CC([%pure-parser %error-verbose %debug %name-prefix "calc" %verbose %yacc])
+AT_CHECK_CALC_LALR1_CC([%locations %define parse.error verbose %debug %name-prefix "calc" %verbose %yacc])
 
-AT_CHECK_CALC_LALR1_CC([%pure-parser %error-verbose %debug %name-prefix "calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
+AT_CHECK_CALC_LALR1_CC([%locations %pure-parser %define parse.error verbose %debug %name-prefix "calc" %verbose %yacc])
+AT_CHECK_CALC_LALR1_CC([%locations %pure-parser %define parse.error verbose %debug %name-prefix "calc" %define api.tokens.prefix "TOK_" %verbose %yacc])
+
+AT_CHECK_CALC_LALR1_CC([%locations %pure-parser %define parse.error verbose %debug %name-prefix "calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
 
 
 
@@ -712,11 +716,13 @@ m4_define([AT_CHECK_CALC_GLR_CC],
 [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])
+AT_CHECK_CALC_GLR_CC([%define location_type Span])
+AT_CHECK_CALC_GLR_CC([%define parse.error verbose %name-prefix "calc" %verbose %yacc])
 
 AT_CHECK_CALC_GLR_CC([%debug])
-AT_CHECK_CALC_GLR_CC([%error-verbose %debug %name-prefix "calc" %verbose %yacc])
+AT_CHECK_CALC_GLR_CC([%define parse.error verbose %debug %name-prefix "calc" %verbose %yacc])
 
-AT_CHECK_CALC_GLR_CC([%pure-parser %error-verbose %debug %name-prefix "calc" %verbose %yacc])
+AT_CHECK_CALC_GLR_CC([%pure-parser %define parse.error verbose %debug %name-prefix "calc" %verbose %yacc])
+AT_CHECK_CALC_GLR_CC([%pure-parser %define parse.error verbose %debug %name-prefix "calc" %define api.tokens.prefix "TOK_" %verbose %yacc])
 
-AT_CHECK_CALC_GLR_CC([%pure-parser %error-verbose %debug %name-prefix "calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
+AT_CHECK_CALC_GLR_CC([%pure-parser %define parse.error verbose %debug %name-prefix "calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])