Command files can nest, -f is an alias for -c and better error messages.
[iverilog.git] / driver / cfparse.y
blob67d85db94c9b8864fde4d112d69c3f7a6b9257ae
1 %{
2 /*
3 * Copyright (c) 20001 Stephen Williams (steve@icarus.com)
5 * This source code is free software; you can redistribute it
6 * and/or modify it in source code form under the terms of the GNU
7 * General Public License as published by the Free Software
8 * Foundation; either version 2 of the License, or (at your option)
9 * any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
20 #ifdef HAVE_CVS_IDENT
21 #ident "$Id: cfparse.y,v 1.12 2007/04/19 02:52:53 steve Exp $"
22 #endif
25 # include "globals.h"
26 # include "cfparse_misc.h"
27 # include <ctype.h>
28 # include <stdlib.h>
29 # include <string.h>
33 * This flag is set to 0, 1 or 2 if file names are to be translated to
34 * uppercase(1) or lowercase(2).
36 static int setcase_filename_flag = 0;
37 static void translate_file_name(char*text)
39 switch (setcase_filename_flag) {
40 case 0:
41 break;
42 case 1:
43 while (*text) {
44 *text = toupper(*text);
45 text += 1;
47 break;
48 case 2:
49 while (*text) {
50 *text = tolower(*text);
51 text += 1;
53 break;
59 %union {
60 char*text;
63 %token TOK_Da TOK_Dc TOK_Dv TOK_Dy
64 %token TOK_DEFINE TOK_INCDIR TOK_LIBDIR TOK_LIBDIR_NOCASE TOK_LIBEXT
65 %token TOK_INTEGER_WIDTH
66 %token <text> TOK_PLUSARG TOK_PLUSWORD TOK_STRING
70 start
72 | item_list
75 item_list
76 : item_list item
77 | item
80 item
81 /* Absent any other matching, a token string is taken to be the name
82 of a source file. Add the file to the file list. */
84 : TOK_STRING
85 { char*tmp = substitutions($1);
86 translate_file_name(tmp);
87 process_file_name(tmp, 0);
88 free($1);
89 free(tmp);
92 /* The -a flag is completely ignored. */
94 | TOK_Da { }
96 /* Match a -c <cmdfile> or -f <cmdfile> */
98 | TOK_Dc TOK_STRING
99 { char*tmp = substitutions($2);
100 translate_file_name(tmp);
101 switch_to_command_file(tmp);
102 free($2);
103 free(tmp);
106 /* The -v <libfile> flag is ignored, and the <libfile> is processed
107 as an ordinary source file. */
109 | TOK_Dv TOK_STRING
110 { char*tmp = substitutions($2);
111 translate_file_name(tmp);
112 process_file_name(tmp, 1);
113 free($2);
114 free(tmp);
117 /* This rule matches "-y <path>" sequences. This does the same thing
118 as -y on the command line, so add the path to the library
119 directory list. */
121 | TOK_Dy TOK_STRING
122 { char*tmp = substitutions($2);
123 process_library_switch(tmp);
124 free($2);
125 free(tmp);
128 | TOK_LIBDIR TOK_PLUSARG
129 { char*tmp = substitutions($2);
130 process_library_switch(tmp);
131 free($2);
132 free(tmp);
135 | TOK_LIBDIR_NOCASE TOK_PLUSARG
136 { char*tmp = substitutions($2);
137 process_library_nocase_switch(tmp);
138 free($2);
139 free(tmp);
142 | TOK_DEFINE TOK_PLUSARG
143 { process_define($2);
144 free($2);
147 /* The +incdir token introduces a list of +<path> arguments that are
148 the include directories to search. */
150 | TOK_INCDIR inc_args
152 /* The +libext token introduces a list of +<ext> arguments that
153 become individual -Y flags to ivl. */
155 | TOK_LIBEXT libext_args
157 /* These are various misc flags that are supported. */
159 | TOK_INTEGER_WIDTH TOK_PLUSARG
160 { char*tmp = substitutions($2);
161 free($2);
162 integer_width = strtoul(tmp,0,10);
163 free(tmp);
166 /* The +<word> tokens that are not otherwise matched, are
167 ignored. The skip_args rule arranges for all the argument words
168 to be consumed. */
170 | TOK_PLUSWORD skip_args
171 { fprintf(stderr, "%s:%u: Ignoring %s\n",
172 @1.text, @1.first_line, $1);
173 free($1);
175 | TOK_PLUSWORD
176 { if (strcmp($1, "+toupper-filenames") == 0) {
177 setcase_filename_flag = 1;
178 } else if (strcmp($1, "+tolower-filenames") == 0) {
179 setcase_filename_flag = 2;
180 } else {
181 fprintf(stderr, "%s:%u: Ignoring %s\n",
182 @1.text, @1.first_line, $1);
184 free($1);
187 | error
188 { fprintf(stderr, "Error: unable to parse line %d in "
189 "%s.\n", cflloc.first_line, current_file);
190 return 1;
194 /* inc_args are +incdir+ arguments in order. */
195 inc_args
196 : inc_args inc_arg
197 | inc_arg
200 inc_arg : TOK_PLUSARG
201 { char*tmp = substitutions($1);
202 process_include_dir(tmp);
203 free($1);
204 free(tmp);
208 /* inc_args are +incdir+ arguments in order. */
209 libext_args
210 : libext_args libext_arg
211 | libext_arg
214 libext_arg : TOK_PLUSARG
215 { process_library2_switch($1);
216 free($1);
220 /* skip_args are arguments to a +word flag that is not otherwise
221 parsed. This rule matches them and releases the strings, so that
222 they can be safely ignored. */
223 skip_args
224 : skip_args skip_arg
225 | skip_arg
228 skip_arg : TOK_PLUSARG
229 { free($1);
235 int yyerror(const char*msg)
237 return 0;