44 |
typed access to it. */ |
typed access to it. */ |
45 |
#define yycontrol ((skel_control_t *) skel_control) |
#define yycontrol ((skel_control_t *) skel_control) |
46 |
|
|
|
char* prefix = NULL; |
|
47 |
FILE* parser = NULL; |
FILE* parser = NULL; |
48 |
|
|
49 |
size_t output_line; |
size_t output_line; |
86 |
%token LINE |
%token LINE |
87 |
%token SLINE |
%token SLINE |
88 |
|
|
|
%token YACC |
|
89 |
%token SECTION |
%token SECTION |
90 |
|
|
91 |
%token GUARDS |
%token GUARDS |
92 |
%token TOKENS |
%token TOKENS |
93 |
%token ACTIONS |
%token ACTIONS |
94 |
|
|
95 |
%type <boolean> section.yacc |
%type <string> string.1 string |
96 |
|
|
97 |
%start input |
%start input |
98 |
|
|
108 |
section : section.header section.body { } |
section : section.header section.body { } |
109 |
; |
; |
110 |
|
|
111 |
section.header : SECTION BLANKS MUSCLE BLANKS STRING BLANKS section.yacc '\n' |
section.header : SECTION BLANKS string '\n' |
112 |
{ |
{ |
113 |
char *name = 0; |
char *name = $3; |
|
char *limit = 0; |
|
|
char *suffix = $5; |
|
114 |
|
|
115 |
/* Close the previous parser. */ |
/* Close the previous parser. */ |
116 |
if (parser) |
if (parser) |
117 |
parser = (xfclose (parser), NULL); |
parser = (xfclose (parser), NULL); |
118 |
|
|
|
/* If the following section should be named with the yacc-style, and it's |
|
|
suffix is of the form 'something.h' or 'something.c', then add '.tab' in |
|
|
the middle of the suffix. */ |
|
|
if (tab_extension && $7 && (strsuffix (suffix, ".h") || |
|
|
strsuffix (suffix, ".c"))) |
|
|
{ |
|
|
size_t prefix_len = strlen (prefix); |
|
|
size_t suffix_len = strlen (suffix); |
|
|
|
|
|
/* Allocate enough space to insert '.tab'. */ |
|
|
name = XMALLOC (char, prefix_len + suffix_len + 5); |
|
|
limit = strrchr (suffix, '.'); |
|
|
if (!limit) |
|
|
limit = suffix; |
|
|
|
|
|
/* Prefix is 'X', suffix is 'Y.Z'. Name will be 'XY.tab.Z'. */ |
|
|
{ |
|
|
char* cp = 0; |
|
|
cp = stpcpy (name, prefix); |
|
|
cp = stpncpy (cp, suffix, limit - suffix); |
|
|
cp = stpcpy (cp, ".tab"); |
|
|
cp = stpcpy (cp, limit); |
|
|
} |
|
|
} |
|
|
else |
|
|
name = stringappend (prefix, suffix); |
|
|
|
|
119 |
/* Prepare the next parser to be output. */ |
/* Prepare the next parser to be output. */ |
120 |
parser = xfopen (name, "w"); |
parser = xfopen (name, "w"); |
121 |
MUSCLE_INSERT_STRING ("parser-file-name", name); |
MUSCLE_INSERT_STRING ("parser-file-name", name); |
125 |
} |
} |
126 |
; |
; |
127 |
|
|
128 |
section.yacc : /* Empty. */ { $$ = 0; } |
/* Either a literal string, or a muscle value. */ |
129 |
| YACC { $$ = 1; } |
string.1: |
130 |
; |
STRING { $$ = $1; } |
131 |
|
| MUSCLE { $$ = xstrdup (muscle_find ($1)); } |
132 |
|
; |
133 |
|
|
134 |
|
/* Either a literal string, or a muscle value, or the concatenation of |
135 |
|
them. */ |
136 |
|
string: |
137 |
|
string.1 |
138 |
|
{ $$ = $1; } |
139 |
|
| string BLANKS string.1 |
140 |
|
{ $$ = stringappend ($1, $3); free ($1); free ($3); } |
141 |
|
; |
142 |
|
|
143 |
section.body |
section.body |
144 |
: /* Empty. */ { } |
: /* Empty. */ { } |
190 |
case CHARACTER: |
case CHARACTER: |
191 |
fprintf (file, " = '%c'", value->character); |
fprintf (file, " = '%c'", value->character); |
192 |
break; |
break; |
|
|
|
|
case YACC: |
|
|
fprintf (file, " = %s", value->boolean ? "true" : "false"); |
|
|
break; |
|
193 |
} |
} |
194 |
} |
} |
195 |
|
|
214 |
void |
void |
215 |
process_skeleton (const char* skel) |
process_skeleton (const char* skel) |
216 |
{ |
{ |
|
/* Compute prefix. Actually, it seems that the processing I need here is |
|
|
done in compute_base_names, and the result stored in short_base_name. */ |
|
|
prefix = short_base_name; |
|
|
|
|
217 |
/* Prepare a few things. */ |
/* Prepare a few things. */ |
218 |
output_line = 1; |
output_line = 1; |
219 |
skeleton_line = 1; |
skeleton_line = 1; |