Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
scan_vcd.l
Go to the documentation of this file.
1 /* -*-c-*- */
2 
3 %{
4 /*
5  * scan_vcd.l - scanner for a VCD data file
6  *
7  * Copyright (C) 2005 Raimund Jacob <raimi@lkcc.org>
8  * Copyright (C) 2006, 2007, 2008 Stefan Jahn <stefan@lkcc.org>
9  *
10  * This is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2, or (at your option)
13  * any later version.
14  *
15  * This software is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this package; see the file COPYING. If not, write to
22  * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
23  * Boston, MA 02110-1301, USA.
24  *
25  * $Id$
26  *
27  */
28 
29 #if HAVE_CONFIG_H
30 # include <config.h>
31 #endif
32 
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <string.h>
36 #include <ctype.h>
37 
38 #ifdef __MINGW32__
39 #include <io.h>
40 #endif
41 
42 #ifdef HAVE_UNISTD_H
43 #include <unistd.h>
44 #endif
45 
46 #include "check_vcd.h"
47 #include "tokens_vcd.h"
48 
49 #if !HAVE_STRCHR
50 # define strchr index
51 # define strrchr rindex
52 #endif
53 
54 %}
55 
56 WS [ \t\n\r]
57 DIGIT [0-9]
58 EXPONENT [Ee][+-]?{DIGIT}+
59 INT [+-]?{DIGIT}+
60 REAL [+-]?{DIGIT}+("."{DIGIT}+)?{EXPONENT}?
61 BINARY [01xXzZ]+
62 DECIMAL {DIGIT}+
63 SCALAR [01xXzZ]
64 CODE [!-~]+
65 IDENT [a-zA-Z_][a-zA-Z0-9_.-]*
66 
67 %x COMMENT SCALE SCOPE IGNORE VAR VAR2 VAR3 VAR4 DUMP TIMESTAMP CHANGE
68 %x BIN FLOAT
69 
70 %option yylineno noyywrap nounput prefix="vcd_"
71 
72 %%
73 
74 <INITIAL,COMMENT,SCALE,SCOPE,IGNORE,VAR4,DUMP>"$end" {
75  BEGIN(INITIAL);
76  return t_END;
77 }
78 
79 <INITIAL>"$comment" {
80  BEGIN(COMMENT);
81  return t_COMMENT;
82 }
83 
84 <INITIAL>"$date" {
85  BEGIN(IGNORE);
86  return t_DATE;
87 }
88 
89 <INITIAL>"$enddefinitions" {
90  return t_ENDDEFINITIONS;
91 }
92 
93 <INITIAL>"$scope" {
94  BEGIN(SCOPE);
95  return t_SCOPE;
96 }
97 
98 <INITIAL>"$timescale" {
99  BEGIN(SCALE);
100  return t_TIMESCALE;
101 }
102 
103 <SCALE>"1" { return ONE; }
104 <SCALE>"10" { return TEN; }
105 <SCALE>"100" { return HUNDRET; }
106 
107 <SCALE>"s" { return SECOND; }
108 <SCALE>"ms" { return MILLI; }
109 <SCALE>"us" { return MICRO; }
110 <SCALE>"ns" { return NANO; }
111 <SCALE>"ps" { return PICO; }
112 <SCALE>"fs" { return FEMTO; }
113 
114 <INITIAL>"$upscope" {
115  return t_UPSCOPE;
116 }
117 
118 <INITIAL>"$var" {
119  BEGIN(VAR);
120  return t_VAR;
121 }
122 
123 <VAR>"event" { return EVENT; }
124 <VAR>"integer" { return INTEGER; }
125 <VAR>"parameter" { return PARAMETER; }
126 <VAR>"real" { return REAL; }
127 <VAR>"reg" { return REG; }
128 <VAR>"supply0" { return SUPPLY0; }
129 <VAR>"supply1" { return SUPPLY1; }
130 <VAR>"time" { return TIME; }
131 <VAR>"tri" { return TRI; }
132 <VAR>"triand" { return TRIAND; }
133 <VAR>"trior" { return TRIOR; }
134 <VAR>"trireg" { return TRIREG; }
135 <VAR>"tri0" { return TRI0; }
136 <VAR>"tri1" { return TRI1; }
137 <VAR>"wand" { return WAND; }
138 <VAR>"wire" { return WIRE; }
139 <VAR>"wor" { return WOR; }
140 
141 <INITIAL,DUMP>"1" {
142  vcd_lval.value = strdup (vcd_text);
143  BEGIN(CHANGE);
144  return ONE;
145 }
146 
147 <INITIAL,DUMP>"0" {
148  vcd_lval.value = strdup (vcd_text);
149  BEGIN(CHANGE);
150  return ZERO;
151 }
152 
153 <INITIAL,DUMP>[xX] {
154  vcd_lval.value = strdup ("X");
155  BEGIN(CHANGE);
156  return X;
157 }
158 
159 <INITIAL,DUMP>[zZ] {
160  vcd_lval.value = strdup ("Z");
161  BEGIN(CHANGE);
162  return Z;
163 }
164 
165 <TIMESTAMP>{DECIMAL} {
166  vcd_lval.real = strtod (vcd_text, NULL);
167  BEGIN(INITIAL);
168  return PositiveHugeInteger;
169 }
170 
171 <INITIAL,DUMP>[rR] {
172  BEGIN(FLOAT);
173  return 'R';
174 }
175 
176 <INITIAL,DUMP>[bB] {
177  BEGIN(BIN);
178  return 'B';
179 }
180 
181 <FLOAT>{REAL}|{INT} {
182  vcd_lval.value = strdup (vcd_text);
183  BEGIN(CHANGE);
184  return Real;
185 }
186 
187 <BIN>{BINARY} {
188  vcd_lval.value = strdup (vcd_text);
189  char * p = vcd_lval.value;
190  while (*p) { *p = toupper (*p); p++; }
191  BEGIN(CHANGE);
192  return Binary;
193 }
194 
195 <INITIAL>"$version" {
196  BEGIN(IGNORE);
197  return t_VERSION;
198 }
199 
200 <INITIAL>"$dumpall" {
201  return t_DUMPALL;
202 }
203 
204 <INITIAL>"$dumpoff" {
205  return t_DUMPOFF;
206 }
207 
208 <INITIAL>"$dumpon" {
209  return t_DUMPON;
210 }
211 
212 <INITIAL>"$dumpvars" {
213  BEGIN(DUMP);
214  return t_DUMPVARS;
215 }
216 
217 <SCOPE>"module" { return s_MODULE; }
218 <SCOPE>"task" { return s_TASK; }
219 <SCOPE>"function" { return s_FUNCTION; }
220 <SCOPE>"fork" { return s_FORK; }
221 <SCOPE>"begin" { return s_BEGIN; }
222 
223 <INITIAL>"#" {
224  BEGIN(TIMESTAMP);
225  return HASHMARK;
226 }
227 
228 <SCOPE>{IDENT} {
229  vcd_lval.ident = strdup (vcd_text);
230  return Identifier;
231 }
232 
233 <VAR>{DECIMAL} {
234  vcd_lval.integer = atoi (vcd_text);
235  BEGIN(VAR2);
236  return PositiveInteger;
237 }
238 
239 <VAR2>{CODE} {
240  vcd_lval.ident = strdup (vcd_text);
241  BEGIN(VAR3);
242  return IdentifierCode;
243 }
244 
245 <VAR3>{IDENT} {
246  vcd_lval.ident = strdup (vcd_text);
247  BEGIN(VAR4);
248  return Reference;
249 }
250 
251 <VAR4>"[" { /* pass the '[' to the parser */ return '['; }
252 <VAR4>"]" { /* pass the ']' to the parser */ return ']'; }
253 <VAR4>":" { /* pass the ':' to the parser */ return ':'; }
254 <VAR4>"(" { /* pass the '(' to the parser */ return '('; }
255 <VAR4>")" { /* pass the ')' to the parser */ return ')'; }
256 
257 <VAR4>{DECIMAL} {
258  vcd_lval.integer = atoi (vcd_text);
259  return PositiveInteger;
260 }
261 
262 <CHANGE>{CODE} {
263  vcd_lval.ident = strdup (vcd_text);
264  BEGIN(INITIAL);
265  return IdentifierCode;
266 }
267 
268 <IGNORE,COMMENT>. { /* skip any character in here */ }
269 <*>\r?\n|{WS} { /* skip end of line and spaces */ }
270 
271 <*>. { /* any other character is invalid */
272  fprintf (stderr,
273  "line %d: syntax error, unrecognized character: `%s'\n",
274  vcd_lineno, vcd_text);
275  return InvalidCharacter;
276 }
277 
278 %%
#define INT(con)
Definition: evaluate.cpp:68
INTEGER
Definition: parse_vcd.y:231
s_BEGIN
Definition: parse_vcd.y:173
WOR
Definition: parse_vcd.y:262
TRIREG
Definition: parse_vcd.y:252
NANO
Definition: parse_vcd.y:194
Identifier
Definition: parse_csv.y:87
REG
Definition: parse_vcd.y:238
TRIAND
Definition: parse_vcd.y:248
MILLI
Definition: parse_vcd.y:192
n
Definition: parse_citi.y:147
r
Definition: parse_mdl.y:515
TRIOR
Definition: parse_vcd.y:250
TEN
Definition: parse_vcd.y:186
PARAMETER
Definition: parse_vcd.y:233
t_TIMESCALE TimeScaleDeclaration t_END t_UPSCOPE t_END
Definition: parse_vcd.y:136
FEMTO
Definition: parse_vcd.y:196
PICO
Definition: parse_vcd.y:195
SUPPLY1
Definition: parse_vcd.y:242
PositiveInteger
Definition: parse_vcd.y:221
WAND
Definition: parse_vcd.y:258
s_TASK
Definition: parse_vcd.y:171
< INITIAL >< INITIAL >< INITIAL >< INITIAL > return InvalidCharacter
Definition: scan_netlist.l:698
#define Z_(r, c)
Definition: hbsolver.cpp:689
x
Definition: parse_mdl.y:498
t_TABLE String Real
Definition: parse_mdl.y:382
int vcd_lineno
R Real IdentifierCode
Definition: parse_vcd.y:333
s_FORK
Definition: parse_vcd.y:174
name prefix
Definition: parse_spice.y:131
TRI
Definition: parse_vcd.y:246
s_FUNCTION
Definition: parse_vcd.y:172
Reference
HUNDRET
Definition: parse_vcd.y:187
WIRE
Definition: parse_vcd.y:260
TRI1
Definition: parse_vcd.y:256
TIME
Definition: parse_vcd.y:244
#define Z0
Wave impedance in vacuum ( )
Definition: constants.h:53
REAL
Definition: parse_vcd.y:236
MICRO
Definition: parse_vcd.y:193
TRI0
Definition: parse_vcd.y:254
SUPPLY0
Definition: parse_vcd.y:240