Qucs-core  0.0.19
scan_vcd.l
Go to the documentation of this file.
00001 /* -*-c-*- */
00002 
00003 %{
00004 /*
00005  * scan_vcd.l - scanner for a VCD data file
00006  *
00007  * Copyright (C) 2005 Raimund Jacob <raimi@lkcc.org>
00008  * Copyright (C) 2006, 2007, 2008 Stefan Jahn <stefan@lkcc.org>
00009  *
00010  * This is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2, or (at your option)
00013  * any later version.
00014  * 
00015  * This software is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  * 
00020  * You should have received a copy of the GNU General Public License
00021  * along with this package; see the file COPYING.  If not, write to
00022  * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
00023  * Boston, MA 02110-1301, USA.  
00024  *
00025  * $Id$
00026  *
00027  */
00028 
00029 #if defined(__clang__)
00030 #pragma clang diagnostic push
00031 #pragma clang diagnostic ignored "-Wdeprecated-register"
00032 #endif
00033 
00034 #if HAVE_CONFIG_H
00035 # include <config.h>
00036 #endif
00037 
00038 #include <stdio.h>
00039 #include <stdlib.h>
00040 #include <string.h>
00041 #include <ctype.h>
00042 
00043 #ifdef __MINGW32__
00044 #include <io.h>
00045 #endif
00046 
00047 #ifdef HAVE_UNISTD_H
00048 #include <unistd.h>
00049 #endif
00050 
00051 #include "check_vcd.h"
00052 #include "tokens_vcd.h"
00053 
00054 #if !HAVE_STRCHR
00055 # define strchr  index
00056 # define strrchr rindex
00057 #endif
00058 
00059 %}
00060 
00061 WS       [ \t\n\r]
00062 DIGIT    [0-9]
00063 EXPONENT [Ee][+-]?{DIGIT}+
00064 INT      [+-]?{DIGIT}+
00065 REAL     [+-]?{DIGIT}+("."{DIGIT}+)?{EXPONENT}?
00066 BINARY   [01xXzZ]+
00067 DECIMAL  {DIGIT}+
00068 SCALAR   [01xXzZ]
00069 CODE     [!-~]+
00070 IDENT    [a-zA-Z_][a-zA-Z0-9_.-]*
00071 
00072 %x COMMENT SCALE SCOPE IGNORE VAR VAR2 VAR3 VAR4 DUMP TIMESTAMP CHANGE
00073 %x BIN FLOAT
00074 
00075 %option yylineno noyywrap nounput noinput prefix="vcd_"
00076 
00077 %%
00078 
00079 <INITIAL,COMMENT,SCALE,SCOPE,IGNORE,VAR4,DUMP>"$end" {
00080   BEGIN(INITIAL);
00081   return t_END;
00082 }
00083 
00084 <INITIAL>"$comment" {
00085   BEGIN(COMMENT);
00086   return t_COMMENT;
00087 }
00088 
00089 <INITIAL>"$date" {
00090   BEGIN(IGNORE);
00091   return t_DATE;
00092 }
00093 
00094 <INITIAL>"$enddefinitions" {
00095   return t_ENDDEFINITIONS;
00096 }
00097 
00098 <INITIAL>"$scope" {
00099   BEGIN(SCOPE);
00100   return t_SCOPE;
00101 }
00102 
00103 <INITIAL>"$timescale" {
00104   BEGIN(SCALE);
00105   return t_TIMESCALE;
00106 }
00107 
00108 <SCALE>"1"   { return ONE; }
00109 <SCALE>"10"  { return TEN; }
00110 <SCALE>"100" { return HUNDRET; }
00111 
00112 <SCALE>"s"   { return SECOND; }
00113 <SCALE>"ms"  { return MILLI;  }
00114 <SCALE>"us"  { return MICRO;  }
00115 <SCALE>"ns"  { return NANO;   }
00116 <SCALE>"ps"  { return PICO;   }
00117 <SCALE>"fs"  { return FEMTO;  }
00118 
00119 <INITIAL>"$upscope" {
00120   return t_UPSCOPE;
00121 }
00122 
00123 <INITIAL>"$var" {
00124   BEGIN(VAR);
00125   return t_VAR;
00126 }
00127 
00128 <VAR>"event"     { return EVENT;     }
00129 <VAR>"integer"   { return INTEGER;   }
00130 <VAR>"parameter" { return PARAMETER; }
00131 <VAR>"real"      { return REAL;      }
00132 <VAR>"reg"       { return REG;       }
00133 <VAR>"supply0"   { return SUPPLY0;   }
00134 <VAR>"supply1"   { return SUPPLY1;   }
00135 <VAR>"time"      { return TIME;      }
00136 <VAR>"tri"       { return TRI;       }
00137 <VAR>"triand"    { return TRIAND;    }
00138 <VAR>"trior"     { return TRIOR;     }
00139 <VAR>"trireg"    { return TRIREG;    }
00140 <VAR>"tri0"      { return TRI0;      }
00141 <VAR>"tri1"      { return TRI1;      }
00142 <VAR>"wand"      { return WAND;      }
00143 <VAR>"wire"      { return WIRE;      }
00144 <VAR>"wor"       { return WOR;       }
00145 
00146 <INITIAL,DUMP>"1" {
00147   vcd_lval.value = strdup (vcd_text);
00148   BEGIN(CHANGE);
00149   return ONE;
00150 }
00151 
00152 <INITIAL,DUMP>"0" {
00153   vcd_lval.value = strdup (vcd_text);
00154   BEGIN(CHANGE);
00155   return ZERO;
00156 }
00157 
00158 <INITIAL,DUMP>[xX] {
00159   vcd_lval.value = strdup ("X");
00160   BEGIN(CHANGE);
00161   return X;
00162 }
00163 
00164 <INITIAL,DUMP>[zZ] {
00165   vcd_lval.value = strdup ("Z");
00166   BEGIN(CHANGE);
00167   return Z;
00168 }
00169 
00170 <TIMESTAMP>{DECIMAL} {
00171   vcd_lval.real = strtod (vcd_text, NULL);
00172   BEGIN(INITIAL);
00173   return PositiveHugeInteger;
00174 }
00175 
00176 <INITIAL,DUMP>[rR] {
00177   BEGIN(FLOAT);
00178   return 'R';
00179 }
00180 
00181 <INITIAL,DUMP>[bB] {
00182   BEGIN(BIN);
00183   return 'B';
00184 }
00185 
00186 <FLOAT>{REAL}|{INT} {
00187   vcd_lval.value = strdup (vcd_text);
00188   BEGIN(CHANGE);
00189   return Real;
00190 }
00191 
00192 <BIN>{BINARY} {
00193   vcd_lval.value = strdup (vcd_text);
00194   char * p = vcd_lval.value;
00195   while (*p) { *p = toupper (*p); p++; }
00196   BEGIN(CHANGE);
00197   return Binary;
00198 }
00199 
00200 <INITIAL>"$version" {
00201   BEGIN(IGNORE);
00202   return t_VERSION;
00203 }
00204 
00205 <INITIAL>"$dumpall" {
00206   return t_DUMPALL;
00207 }
00208 
00209 <INITIAL>"$dumpoff" {
00210   return t_DUMPOFF;
00211 }
00212 
00213 <INITIAL>"$dumpon" {
00214   return t_DUMPON;
00215 }
00216 
00217 <INITIAL>"$dumpvars" {
00218   BEGIN(DUMP);
00219   return t_DUMPVARS;
00220 }
00221 
00222 <SCOPE>"module"   { return s_MODULE;   }
00223 <SCOPE>"task"     { return s_TASK;     }
00224 <SCOPE>"function" { return s_FUNCTION; }
00225 <SCOPE>"fork"     { return s_FORK;     }
00226 <SCOPE>"begin"    { return s_BEGIN;    }
00227 
00228 <INITIAL>"#" {
00229   BEGIN(TIMESTAMP);
00230   return HASHMARK;
00231 }
00232 
00233 <SCOPE>{IDENT} {
00234   vcd_lval.ident = strdup (vcd_text);
00235   return Identifier;
00236 }
00237 
00238 <VAR>{DECIMAL} {
00239   vcd_lval.integer = atoi (vcd_text);
00240   BEGIN(VAR2);
00241   return PositiveInteger;
00242 }
00243 
00244 <VAR2>{CODE} {
00245   vcd_lval.ident = strdup (vcd_text);
00246   BEGIN(VAR3);
00247   return IdentifierCode;
00248 }
00249 
00250 <VAR3>{IDENT} {
00251   vcd_lval.ident = strdup (vcd_text);
00252   BEGIN(VAR4);
00253   return Reference;
00254 }
00255 
00256 <VAR4>"["   { /* pass the '[' to the parser */ return '['; }
00257 <VAR4>"]"   { /* pass the ']' to the parser */ return ']'; }
00258 <VAR4>":"   { /* pass the ':' to the parser */ return ':'; }
00259 <VAR4>"("   { /* pass the '(' to the parser */ return '('; }
00260 <VAR4>")"   { /* pass the ')' to the parser */ return ')'; }
00261 
00262 <VAR4>{DECIMAL} {
00263   vcd_lval.integer = atoi (vcd_text);
00264   return PositiveInteger;
00265 }
00266 
00267 <CHANGE>{CODE} {
00268   vcd_lval.ident = strdup (vcd_text);
00269   BEGIN(INITIAL);
00270   return IdentifierCode;
00271 }
00272 
00273 <IGNORE,COMMENT>. { /* skip any character in here */ }
00274 <*>\r?\n|{WS}     { /* skip end of line and spaces */ }
00275 
00276 <*>. { /* any other character is invalid */
00277   fprintf (stderr, 
00278            "line %d: syntax error, unrecognized character: `%s'\n", 
00279            vcd_lineno, vcd_text);
00280   return InvalidCharacter;
00281 }
00282 
00283 %%