%debug
%defines
-%error-verbose
+%verbose
+%locations
+%name-prefix="skel_"
+%pure-parser
%{
#include "system.h"
#include "obstack.h"
+#include "quotearg.h"
#include "files.h"
+#include "getargs.h"
#include "output.h"
#include "skeleton.h"
#include "muscle_tab.h"
-extern FILE* yyin;
-extern int yylineno;
+#define YYERROR_VERBOSE 1
+
+/* Pass the control structure to YYPARSE but not YYLEX (yet?). */
+#define YYPARSE_PARAM skel_control
+/* YYPARSE receives SKEL_CONTROL as a void *. Provide a correctly
+ typed access to it. */
+#define yycontrol ((skel_control_t *) skel_control)
char* prefix = NULL;
FILE* parser = NULL;
size_t output_line;
size_t skeleton_line;
-static int merror PARAMS ((const char* error));
-static int yyerror PARAMS ((const char* error));
+static void merror PARAMS ((const char* error));
+
+/* Request detailed parse error messages, and pass them to
+ YLEVAL_ERROR. */
+#undef yyerror
+#define yyerror(Msg) \
+ skel_error (yycontrol, &yylloc, Msg)
+/* When debugging our pure parser, we want to see values and locations
+ of the tokens. */
+#define YYPRINT(File, Type, Value) \
+ yyprint (File, &yylloc, Type, &Value)
+static void yyprint (FILE *file, const yyltype *loc,
+ int type, const yystype *value);
%}
%union
{
- char* muscle;
- char* string;
+ char *string;
char character;
- int yacc;
+ int boolean;
}
-%token <muscle> MUSCLE
+/* Name of a muscle. */
+%token <string> MUSCLE
+/* A string dedicated to Bison (%%"foo"). */
%token <string> STRING
+/* Raw data, to output directly. */
+%token <string> RAW
+/* Spaces. */
+%token <string> BLANKS
+/* Raw data, but char by char. */
%token <character> CHARACTER
%token LINE
%token TOKENS
%token ACTIONS
-%type <yacc> section.yacc
+%type <boolean> section.yacc
-%start skeleton
+%start input
%%
+input:
+ { LOCATION_RESET (yylloc) } skeleton
+ ;
skeleton : /* Empty. */ { }
| section skeleton { }
section : section.header section.body { }
;
-section.header : SECTION gb MUSCLE gb STRING gb section.yacc gb '\n'
+section.header : SECTION BLANKS MUSCLE BLANKS STRING BLANKS section.yacc '\n'
{
char *name = 0;
char *limit = 0;
| section.body TOKENS { token_definitions_output (parser, &output_line); }
| section.body ACTIONS { actions_output (parser, &output_line); }
| section.body CHARACTER { fputc ($2, parser); }
+| section.body RAW { fputs ($2, parser); }
+| section.body BLANKS { fputs ($2, parser); }
| section.body MUSCLE {
const char* value = muscle_find ($2);
if (value)
}
}
;
+%%
+/*------------------------------------------------------------------.
+| When debugging the parser, display tokens' locations and values. |
+`------------------------------------------------------------------*/
-gb : /* Empty. */ { }
- | gb CHARACTER { /* Do not echo garbage characters. */ }
-;
+static void
+yyprint (FILE *file,
+ const yyltype *loc, int type, const yystype *value)
+{
+ fputs (" (", file);
+ LOCATION_PRINT (file, *loc);
+ fputs (")", file);
+ switch (type)
+ {
+ case MUSCLE:
+ case STRING:
+ case RAW:
+ case BLANKS:
+ fprintf (file, " = %s", quotearg_style (c_quoting_style,
+ value->string));
+ break;
+
+ case CHARACTER:
+ fprintf (file, " = '%c'", value->character);
+ break;
+
+ case YACC:
+ fprintf (file, " = %s", value->boolean ? "true" : "false");
+ break;
+ }
+}
-%%
-static int
+static void
merror (const char* error)
{
printf ("line %d: %%{%s} undeclared.\n", skeleton_line, error);
- return 0;
}
-static int
-yyerror (const char* error)
+void
+skel_error (skel_control_t *control,
+ const yyltype *loc, const char *msg)
{
- fprintf (stderr, "%s\n", error);
- return 0;
+ /* Neutralize GCC warnings for unused parameters. */
+ skel_control_t *c = control;
+ c++;
+ LOCATION_PRINT (stderr, *loc);
+ fprintf (stderr, "%s\n", msg);
}
void
skeleton_line = 1;
/* Output. */
- yyin = fopen (skel, "r");
- yydebug = 0;
- yyparse ();
+ skel_in = fopen (skel, "r");
+ /* FIXME: This is not acceptable for a release. */
+ skel__flex_debug = getenv ("BISON_TRACE_SCAN") ? 1 : 0;
+ skel_debug = getenv ("BISON_TRACE_PARSE") ? 1 : 0;
+ skel_parse (NULL);
/* Close the last parser. */
if (parser)