2 %option never-interactive
6 * Copyright (c) 2007 Stephen Williams (steve@icarus.com)
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)
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.
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
24 # include "sdf_priv.h"
25 # include "sdf_parse_priv.h"
26 # include "sdf_parse.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)
41 # define yylval sdflval
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; }
63 [0-9]+(\.[0-9]+)?([Ee][+-]?[0-9]+)? {
64 yylval.real_val = strtod(yytext, 0);
68 [a-zA-Z_][a-zA-Z0-9$_]* {
69 return lookup_keyword(yytext);
73 process_quoted_string();
77 /* The HCHAR (hierarchy separator) is set by the SDF file itself. We
78 recognize here the HCHAR. */
80 if (sdf_use_hchar==yytext[0])
86 . { return yytext[0]; }
94 { "ABSOLUTE", K_ABSOLUTE },
96 { "CELLTYPE", K_CELLTYPE },
99 { "DELAYFILE", K_DELAYFILE },
100 { "DESIGN", K_DESIGN },
101 { "DIVIDER", K_DIVIDER },
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 },
124 static int lookup_keyword(const char*text)
127 for (idx = 0 ; keywords[idx].name ; idx += 1) {
128 if (strcasecmp(text, keywords[idx].name) == 0)
129 return keywords[idx].code;
132 yylval.string_val = strdup(yytext);
137 * Create a string witout the leading and trailing quotes.
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] == '"');
147 extern int sdfparse(void);
148 void sdf_process_file(FILE*fd, const char*path)
152 sdf_parse_path = path;