]> git.saurik.com Git - bison.git/blobdiff - tests/actions.at
djgpp/config.sed: Adjust config.sed for the use of autoconf 2.60.
[bison.git] / tests / actions.at
index d0cb12f97c134220abc6b5be18f2b829948aecb7..7d401baf6a523230f3319ae9d2aafe612a8fd0fc 100644 (file)
@@ -55,8 +55,11 @@ exp:     { putchar ('0'); }
 static int
 yylex (void)
 {
-  static const char *input = "123456789";
-  return *input++;
+  static char const input[] = "123456789";
+  static size_t toknum;
+  if (! (toknum < sizeof input))
+    abort ();
+  return input[toknum++];
 }
 
 static void
@@ -131,6 +134,9 @@ sum_of_the_five_previous_values:
 static int
 yylex (void)
 {
+  static int called;
+  if (called++)
+    abort ();
   return EOF;
 }
 
@@ -172,9 +178,10 @@ m4_if([$1$2$3], $[1]$[2]$[3], [],
 # helping macros.  So don't put any directly in the Bison file.
 AT_BISON_OPTION_PUSHDEFS([$5])
 AT_DATA_GRAMMAR([[input.y]],
-[[%start-header {
+[[%requires {
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <assert.h>
 
 #define YYINITDEPTH 10
@@ -190,9 +197,8 @@ m4_ifval([$6], [%union
   int ival;
 }])
 AT_LALR1_CC_IF([%define "global_tokens_and_yystype"])
-m4_ifval([$6], [[%end-header {]], [[%start-header {]])
-AT_LALR1_CC_IF([typedef yy::location YYLTYPE;
-                m4_ifval([$6], , [#define YYSTYPE int])])
+m4_ifval([$6], [[%provides {]], [[%code {]])
+AT_LALR1_CC_IF([typedef yy::location YYLTYPE;])
 [static int yylex (]AT_LEX_FORMALS[);
 ]AT_LALR1_CC_IF([], [static void yyerror (const char *msg);])
 [}
@@ -311,6 +317,8 @@ yylex (]AT_LEX_FORMALS[)
   AT_LOC.last_line = AT_LOC.last_column = AT_LOC.first_line + 9;
 ])[
 
+  if (! (0 <= c && c <= strlen (source)))
+    abort ();
   if (source[c])
     printf ("sending: '%c'", source[c]);
   else
@@ -567,9 +575,6 @@ AT_CLEANUP
 AT_CHECK_PRINTER_AND_DESTRUCTOR([])
 AT_CHECK_PRINTER_AND_DESTRUCTOR([], [with union])
 
-# These tests currently fail on a Debian GNU/Linux 3.0r2 x86 host,
-# but the 2nd test succeeds on a Solaris 9 sparc hosts (Forte 7 cc).
-# Skip them until we figure out what the problem is.
 AT_CHECK_PRINTER_AND_DESTRUCTOR([%defines %skeleton "lalr1.cc"])
 AT_CHECK_PRINTER_AND_DESTRUCTOR([%defines %skeleton "lalr1.cc"], [with union])
 
@@ -627,11 +632,13 @@ start: 'a' 'b' 'c' 'd' 'e' { $$ = 'S'; USE(($1, $2, $3, $4, $5)); } ;
 static int
 yylex (void)
 {
-  static const char *input = "abcd";
-  static int column = 1;
-  yylval = *input++;
+  static char const input[] = "abcd";
+  static size_t toknum;
+  if (! (toknum < sizeof input))
+    abort ();
+  yylval = input[toknum++];
   yylloc.first_line = yylloc.last_line = 1;
-  yylloc.first_column = yylloc.last_column = column++;
+  yylloc.first_column = yylloc.last_column = toknum;
   return yylval;
 }
 
@@ -689,6 +696,135 @@ AT_CLEANUP
 
 
 
+## ----------------------------------- ##
+## Per-type %printer and %destructor.  ##
+## ----------------------------------- ##
+
+AT_SETUP([Per-type %printer and %destructor])
+
+AT_DATA_GRAMMAR([[input.y]],
+[[%error-verbose
+%debug
+
+%{
+# include <stdio.h>
+# include <stdlib.h>
+  static void yyerror (const char *msg);
+  static int yylex (void);
+# define USE(SYM)
+%}
+
+%union { int field0; int field1; int field2; }
+%type <field0> start 'a' 'g'
+%type <field1> 'e'
+%type <field2> 'f'
+%printer {
+  fprintf (yyoutput, "%%symbol-default/<field2>/e printer");
+} %symbol-default 'e' <field2>
+%destructor {
+  fprintf (stdout, "%%symbol-default/<field2>/e destructor.\n");
+} %symbol-default 'e' <field2>
+
+%type <field1> 'b'
+%printer { fprintf (yyoutput, "<field1> printer"); } <field1>
+%destructor { fprintf (stdout, "<field1> destructor.\n"); } <field1>
+
+%type <field0> 'c'
+%printer { fprintf (yyoutput, "'c' printer"); } 'c'
+%destructor { fprintf (stdout, "'c' destructor.\n"); } 'c'
+
+%type <field1> 'd'
+%printer { fprintf (yyoutput, "'d' printer"); } 'd'
+%destructor { fprintf (stdout, "'d' destructor.\n"); } 'd'
+
+%%
+
+start:
+  'a' 'b' 'c' 'd' 'e' 'f' 'g'
+    {
+      USE(($1, $2, $3, $4, $5, $6, $7));
+      $$ = 'S';
+    }
+  ;
+
+%%
+
+static int
+yylex (void)
+{
+  static char const input[] = "abcdef";
+  static size_t toknum;
+  if (! (toknum < sizeof input))
+    abort ();
+  return input[toknum++];
+}
+
+static void
+yyerror (const char *msg)
+{
+  fprintf (stderr, "%s\n", msg);
+}
+
+int
+main (void)
+{
+  yydebug = 1;
+  return yyparse ();
+}
+]])
+
+AT_CHECK([bison -o input.c input.y])
+AT_COMPILE([input])
+AT_PARSER_CHECK([./input], 1,
+[[%symbol-default/<field2>/e destructor.
+%symbol-default/<field2>/e destructor.
+'d' destructor.
+'c' destructor.
+<field1> destructor.
+%symbol-default/<field2>/e destructor.
+]],
+[[Starting parse
+Entering state 0
+Reading a token: Next token is token 'a' (%symbol-default/<field2>/e printer)
+Shifting token 'a' (%symbol-default/<field2>/e printer)
+Entering state 1
+Reading a token: Next token is token 'b' (<field1> printer)
+Shifting token 'b' (<field1> printer)
+Entering state 3
+Reading a token: Next token is token 'c' ('c' printer)
+Shifting token 'c' ('c' printer)
+Entering state 5
+Reading a token: Next token is token 'd' ('d' printer)
+Shifting token 'd' ('d' printer)
+Entering state 6
+Reading a token: Next token is token 'e' (%symbol-default/<field2>/e printer)
+Shifting token 'e' (%symbol-default/<field2>/e printer)
+Entering state 7
+Reading a token: Next token is token 'f' (%symbol-default/<field2>/e printer)
+Shifting token 'f' (%symbol-default/<field2>/e printer)
+Entering state 8
+Reading a token: Now at end of input.
+syntax error, unexpected $end, expecting 'g'
+Error: popping token 'f' (%symbol-default/<field2>/e printer)
+Stack now 0 1 3 5 6 7
+Error: popping token 'e' (%symbol-default/<field2>/e printer)
+Stack now 0 1 3 5 6
+Error: popping token 'd' ('d' printer)
+Stack now 0 1 3 5
+Error: popping token 'c' ('c' printer)
+Stack now 0 1 3
+Error: popping token 'b' (<field1> printer)
+Stack now 0 1
+Error: popping token 'a' (%symbol-default/<field2>/e printer)
+Stack now 0
+Cleanup: discarding lookahead token $end ()
+Stack now 0
+]])
+
+AT_CLEANUP
+
+
+
 ## ------------------------------------------------------------- ##
 ## Default %printer and %destructor for user-defined end token. ##
 ## ------------------------------------------------------------- ##
@@ -729,6 +865,9 @@ start: { $$ = 'S'; } ;
 static int
 yylex (void)
 {
+  static int called;
+  if (called++)
+    abort ();
   yylval = 'E';
   yylloc.first_line = yylloc.last_line = 1;
   yylloc.first_column = yylloc.last_column = 1;
@@ -757,7 +896,7 @@ Default destructor for 'S' @ 1.
 ]],
 [[Starting parse
 Entering state 0
-Reducing stack by rule 1 (line 37):
+Reducing stack by rule 1 (line 35):
 -> $$ = nterm start (1.1-1.1: Default printer for 'S' @ 1)
 Stack now 0
 Entering state 1
@@ -793,6 +932,7 @@ AT_DATA_GRAMMAR([[input.y]],
 
 %{
 # include <stdio.h>
+# include <stdlib.h>
   static void yyerror (const char *msg);
   static int yylex (void);
 # define USE(SYM)
@@ -819,8 +959,11 @@ start:
 static int
 yylex (void)
 {
-  static const char *input = "abd";
-  yylval = *input++;
+  static char const input[] = "abd";
+  static size_t toknum;
+  if (! (toknum < sizeof input))
+    abort ();
+  yylval = input[toknum++];
   return yylval;
 }
 
@@ -903,6 +1046,7 @@ AT_DATA_GRAMMAR([[input.y]],
 
 %{
 # include <stdio.h>
+# include <stdlib.h>
   static void yyerror (const char *msg);
   static int yylex (void);
 # define USE(SYM)
@@ -929,6 +1073,9 @@ start: { USE($$); } ;
 static int
 yylex (void)
 {
+  static int called;
+  if (called++)
+    abort ();
   return 0;
 }