Fix for assertion error when expanding macro.
[iverilog.git] / vpi / sdf_lexor.lex
blobfe11a8343d14778ae75f4a4a3b5649605b41b33b
2 %option never-interactive
4 %{
5 /*
6  * Copyright (c) 2007 Stephen Williams (steve@icarus.com)
7  *
8  *    This source code is free software; you can redistribute it
9  *    and/or modify it in source code form under the terms of the GNU
10  *    General Public License as published by the Free Software
11  *    Foundation; either version 2 of the License, or (at your option)
12  *    any later version.
13  *
14  *    This program is distributed in the hope that it will be useful,
15  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *    GNU General Public License for more details.
18  *
19  *    You should have received a copy of the GNU General Public License
20  *    along with this program; if not, write to the Free Software
21  *    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
22  */
24 # include  "sdf_priv.h"
25 # include  "sdf_parse_priv.h"
26 # include  "sdf_parse.h"
27 # include  <stdlib.h>
28 # include  <strings.h>
29 # include  <assert.h>
31 static void process_quoted_string(void);
32 static int lookup_keyword(const char*text);
33 const char*sdf_parse_path = 0;
35 static int yywrap(void)
37       return 1;
41 # define yylval sdflval
44 %x CCOMMENT
48   /* Skip C++-style comments. */
49 "//".* { sdflloc.first_line += 1; }
51   /* Skip C-style comments. */
52 "/*"           { BEGIN(CCOMMENT); }
53 <CCOMMENT>.    { yymore(); }
54 <CCOMMENT>\n   { sdflloc.first_line += 1; yymore(); }
55 <CCOMMENT>"*/" { BEGIN(0); }
57 [ \m\t] { /* Skip white space. */; }
59   /* Count lines so that the parser can assign line numbers. */
60 \n { sdflloc.first_line += 1; }
62   /* Real values */
63 [0-9]+(\.[0-9]+)?([Ee][+-]?[0-9]+)? {
64       yylval.real_val = strtod(yytext, 0);
65       return REAL_NUMBER;
68 [a-zA-Z_][a-zA-Z0-9$_]* {
69       return lookup_keyword(yytext);
72 \"[^\"]*\" {
73       process_quoted_string();
74       return QSTRING;
77   /* The HCHAR (hierarchy separator) is set by the SDF file itself. We
78      recognize here the HCHAR. */
79 [./] {
80       if (sdf_use_hchar==yytext[0])
81             return HCHAR;
82       else
83             return yytext[0];
86 . { return yytext[0]; }
90 static struct {
91       const char*name;
92       int code;
93 } keywords[] = {
94       { "ABSOLUTE",   K_ABSOLUTE },
95       { "CELL",       K_CELL },
96       { "CELLTYPE",   K_CELLTYPE },
97       { "DATE",       K_DATE },
98       { "DELAY",      K_DELAY },
99       { "DELAYFILE",  K_DELAYFILE },
100       { "DESIGN",     K_DESIGN },
101       { "DIVIDER",    K_DIVIDER },
102       { "HOLD",       K_HOLD },
103       { "INCREMENT",  K_INCREMENT },
104       { "INTERCONNECT",K_INTERCONNECT },
105       { "INSTANCE",   K_INSTANCE },
106       { "IOPATH",     K_IOPATH },
107       { "PROCESS",    K_PROCESS },
108       { "PROGRAM",    K_PROGRAM },
109       { "RECOVERY",   K_RECOVERY },
110       { "REMOVAL",    K_REMOVAL },
111       { "SDFVERSION", K_SDFVERSION },
112       { "SETUP",      K_SETUP },
113       { "SETUPHOLD",  K_SETUPHOLD },
114       { "TEMPERATURE",K_TEMPERATURE },
115       { "TIMESCALE",  K_TIMESCALE },
116       { "TIMINGCHECK",K_TIMINGCHECK },
117       { "VENDOR",     K_VENDOR },
118       { "VERSION",    K_VERSION },
119       { "VOLTAGE",    K_VOLTAGE },
120       { "WIDTH",      K_WIDTH },
121       { 0, IDENTIFIER }
124 static int lookup_keyword(const char*text)
126       int idx;
127       for (idx = 0 ;  keywords[idx].name ;  idx += 1) {
128             if (strcasecmp(text, keywords[idx].name) == 0)
129                   return keywords[idx].code;
130       }
132       yylval.string_val = strdup(yytext);
133       return IDENTIFIER;
137  * Create a string witout the leading and trailing quotes.
138  */
139 static void process_quoted_string(void)
141       yylval.string_val = strdup(yytext+1);
142       char*endp = yylval.string_val+strlen(yylval.string_val);
143       assert(endp[-1] == '"');
144       endp[-1] = 0;
147 extern int sdfparse(void);
148 void sdf_process_file(FILE*fd, const char*path)
150       yyrestart(fd);
152       sdf_parse_path = path;
153       sdfparse();
154       sdf_parse_path = 0;