2 /* Parse Bison Skeletons.
3 Copyright (C) 2001 Free Software Foundation, Inc.
5 This file is part of Bison, the GNU Compiler Compiler.
7 Bison is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 Bison is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Bison; see the file COPYING. If not, write to the Free
19 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
37 #include "muscle_tab.h"
39 #define YYERROR_VERBOSE 1
41 /* Pass the control structure to YYPARSE but not YYLEX (yet?). */
42 #define YYPARSE_PARAM skel_control
43 /* YYPARSE receives SKEL_CONTROL as a void *. Provide a correctly
44 typed access to it. */
45 #define yycontrol ((skel_control_t *) skel_control)
52 static void merror PARAMS ((const char* error));
54 /* Request detailed parse error messages, and pass them to
57 #define yyerror(Msg) \
58 skel_error (yycontrol, &yylloc, Msg)
60 /* When debugging our pure parser, we want to see values and locations
62 #define YYPRINT(File, Type, Value) \
63 yyprint (File, &yylloc, Type, &Value)
64 static void yyprint (FILE *file, const yyltype *loc,
65 int type, const yystype *value);
75 /* Name of a muscle. */
76 %token <string> MUSCLE
77 /* A string dedicated to Bison (%%"foo"). */
78 %token <string> STRING
79 /* Raw data, to output directly. */
82 %token <string> BLANKS
83 /* Raw data, but char by char. */
84 %token <character> CHARACTER
95 %type <string> string.1 string
101 { LOCATION_RESET (yylloc) } skeleton
104 skeleton : /* Empty. */ { }
105 | section skeleton { }
108 section : section.header section.body { }
111 section.header : SECTION BLANKS string '\n'
115 /* Close the previous parser. */
117 parser = (xfclose (parser), NULL);
119 /* Prepare the next parser to be output. */
120 parser = xfopen (name, "w");
121 MUSCLE_INSERT_STRING ("parser-file-name", name);
128 /* Either a literal string, or a muscle value. */
131 | MUSCLE { $$ = xstrdup (muscle_find ($1)); }
134 /* Either a literal string, or a muscle value, or the concatenation of
139 | string BLANKS string.1
140 { $$ = stringappend ($1, $3); free ($1); free ($3); }
145 | section.body '\n' { fputc ('\n', parser); ++output_line; ++skeleton_line; }
146 | section.body LINE { fprintf (parser, "%d", output_line); }
147 | section.body SLINE { fprintf (parser, "%d", skeleton_line); }
148 | section.body GUARDS { guards_output (parser, &output_line); }
149 | section.body TOKENS { token_definitions_output (parser, &output_line); }
150 | section.body ACTIONS { actions_output (parser, &output_line); }
151 | section.body CHARACTER { fputc ($2, parser); }
152 | section.body RAW { fputs ($2, parser); }
153 | section.body BLANKS { fputs ($2, parser); }
154 | section.body MUSCLE {
155 const char* value = muscle_find ($2);
158 fputs (value, parser);
159 output_line += get_lines_number (value);
163 fprintf (parser, "%%{%s}", $2);
169 /*------------------------------------------------------------------.
170 | When debugging the parser, display tokens' locations and values. |
171 `------------------------------------------------------------------*/
175 const yyltype *loc, int type, const yystype *value)
178 LOCATION_PRINT (file, *loc);
186 fprintf (file, " = %s", quotearg_style (c_quoting_style,
191 fprintf (file, " = '%c'", value->character);
198 merror (const char* error)
200 printf ("line %d: %%{%s} undeclared.\n", skeleton_line, error);
204 skel_error (skel_control_t *control,
205 const yyltype *loc, const char *msg)
207 /* Neutralize GCC warnings for unused parameters. */
208 skel_control_t *c = control;
210 LOCATION_PRINT (stderr, *loc);
211 fprintf (stderr, "%s\n", msg);
215 process_skeleton (const char* skel)
217 /* Prepare a few things. */
222 skel_in = fopen (skel, "r");
223 /* FIXME: This is not acceptable for a release. */
224 skel__flex_debug = getenv ("BISON_TRACE_SCAN") ? 1 : 0;
225 skel_debug = getenv ("BISON_TRACE_PARSE") ? 1 : 0;
228 /* Close the last parser. */
230 parser = (xfclose (parser), NULL);