7 #include "muscle_tab.h"
10 #define YYERROR_VERBOSE 1
21 extern struct obstack muscle_obstack;
33 %token< muscle > MUSCLE
34 %token< string > STRING
35 %token< character > CHARACTER
47 %type< yacc > section.yacc
53 skeleton : /* Empty. */ { }
54 | section skeleton { }
57 section : section.header section.body { }
60 section.header : SECTION gb MUSCLE gb STRING gb section.yacc gb '\n'
66 /* Close the previous parser. */
68 parser = (xfclose (parser), NULL);
70 /* If the following section should be named with the yacc-style, and it's
71 suffix is of the form 'something.h' or 'something.c', then add '.tab' in
72 the middle of the suffix. */
73 if (tab_extension && $7 && (strsuffix (suffix, ".h") ||
74 strsuffix (suffix, ".c")))
76 size_t prefix_len = strlen (prefix);
77 size_t suffix_len = strlen (suffix);
79 /* Allocate enough space to insert '.tab'. */
80 name = XMALLOC (char, prefix_len + suffix_len + 5);
81 limit = strrchr (suffix, '.');
85 /* Prefix is 'X', suffix is 'Y.Z'. Name will be 'XY.tab.Z'. */
88 cp = stpcpy (name, prefix);
89 cp = stpncpy (cp, suffix, limit - suffix);
90 cp = stpcpy (cp, ".tab");
91 cp = stpcpy (cp, limit);
95 name = stringappend (prefix, suffix);
97 /* Prepare the next parser to be output. */
98 parser = xfopen (name, "w");
99 MUSCLE_INSERT_STRING ("parser-file-name", name);
106 section.yacc : /* Empty. */ { $$ = 0; }
112 | section.body '\n' { fputc ('\n', parser); ++output_line; ++skeleton_line; }
113 | section.body LINE { fprintf (parser, "%d", output_line); }
114 | section.body SLINE { fprintf (parser, "%d", skeleton_line); }
115 | section.body GUARDS { guards_output (parser, &output_line); }
116 | section.body TOKENS { token_definitions_output (parser, &output_line); }
117 | section.body ACTIONS { actions_output (parser, &output_line); }
118 | section.body CHARACTER { fputc ($2, parser); }
119 | section.body MUSCLE {
120 const char* value = muscle_find ($2);
123 fputs (value, parser);
124 output_line += get_lines_number (value);
128 fprintf (parser, "%%{%s}", $2);
134 gb : /* Empty. */ { }
135 | gb CHARACTER { /* Do not echo garbage characters. */ }
141 merror (const char* error)
143 printf ("line %d: %%{%s} undeclared.\n", skeleton_line, error);
148 yyerror (const char* error)
150 printf ("line %d: %s.\n", yylineno, error);
155 process_skeleton (const char* grammar,
156 const char* skeleton)
158 const char* limit = 0;
160 /* Compute prefix. Actually, it seems that the processing I need here is
161 done in compute_base_names, and the result stored in short_base_name. */
162 prefix = short_base_name;
164 /* Prepare a few things. */
169 yyin = fopen (skeleton, "r");
173 /* Close the last parser. */
175 parser = (xfclose (parser), NULL);