/* -*-c-*- */ %{ /* * scan_vcd.l - scanner for a VCD data file * * Copyright (C) 2005 Raimund Jacob * Copyright (C) 2006, 2007, 2008 Stefan Jahn * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this package; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, * Boston, MA 02110-1301, USA. * * $Id$ * */ #if defined(__clang__) #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-register" #endif #if HAVE_CONFIG_H # include #endif #include #include #include #include #ifdef __MINGW32__ #include #endif #ifdef HAVE_UNISTD_H #include #endif #include "check_vcd.h" #include "parse_vcd.hpp" #if !HAVE_STRCHR # define strchr index # define strrchr rindex #endif %} WS [ \t\n\r] DIGIT [0-9] EXPONENT [Ee][+-]?{DIGIT}+ INT [+-]?{DIGIT}+ REAL [+-]?{DIGIT}+("."{DIGIT}+)?{EXPONENT}? BINARY [01xXzZ]+ DECIMAL {DIGIT}+ SCALAR [01xXzZ] CODE [!-~]+ IDENT [a-zA-Z_][a-zA-Z0-9_.-]* %x COMMENT SCALE SCOPE IGNORE VAR VAR2 VAR3 VAR4 DUMP TIMESTAMP CHANGE %x BIN FLOAT %option yylineno noyywrap nounput noinput prefix="vcd_" %% "$end" { BEGIN(INITIAL); return t_END; } "$comment" { BEGIN(COMMENT); return t_COMMENT; } "$date" { BEGIN(IGNORE); return t_DATE; } "$enddefinitions" { return t_ENDDEFINITIONS; } "$scope" { BEGIN(SCOPE); return t_SCOPE; } "$timescale" { BEGIN(SCALE); return t_TIMESCALE; } "1" { return ONE; } "10" { return TEN; } "100" { return HUNDRET; } "s" { return SECOND; } "ms" { return MILLI; } "us" { return MICRO; } "ns" { return NANO; } "ps" { return PICO; } "fs" { return FEMTO; } "$upscope" { return t_UPSCOPE; } "$var" { BEGIN(VAR); return t_VAR; } "event" { return EVENT; } "integer" { return INTEGER; } "parameter" { return PARAMETER; } "real" { return REAL; } "reg" { return REG; } "supply0" { return SUPPLY0; } "supply1" { return SUPPLY1; } "time" { return TIME; } "tri" { return TRI; } "triand" { return TRIAND; } "trior" { return TRIOR; } "trireg" { return TRIREG; } "tri0" { return TRI0; } "tri1" { return TRI1; } "wand" { return WAND; } "wire" { return WIRE; } "wor" { return WOR; } "1" { vcd_lval.value = strdup (vcd_text); BEGIN(CHANGE); return ONE; } "0" { vcd_lval.value = strdup (vcd_text); BEGIN(CHANGE); return ZERO; } [xX] { vcd_lval.value = strdup ("X"); BEGIN(CHANGE); return X; } [zZ] { vcd_lval.value = strdup ("Z"); BEGIN(CHANGE); return Z; } {DECIMAL} { vcd_lval.real = strtod (vcd_text, NULL); BEGIN(INITIAL); return PositiveHugeInteger; } [rR] { BEGIN(FLOAT); return 'R'; } [bB] { BEGIN(BIN); return 'B'; } {REAL}|{INT} { vcd_lval.value = strdup (vcd_text); BEGIN(CHANGE); return Real; } {BINARY} { vcd_lval.value = strdup (vcd_text); char * p = vcd_lval.value; while (*p) { *p = toupper (*p); p++; } BEGIN(CHANGE); return Binary; } "$version" { BEGIN(IGNORE); return t_VERSION; } "$dumpall" { return t_DUMPALL; } "$dumpoff" { return t_DUMPOFF; } "$dumpon" { return t_DUMPON; } "$dumpvars" { BEGIN(DUMP); return t_DUMPVARS; } "module" { return s_MODULE; } "task" { return s_TASK; } "function" { return s_FUNCTION; } "fork" { return s_FORK; } "begin" { return s_BEGIN; } "#" { BEGIN(TIMESTAMP); return HASHMARK; } {IDENT} { vcd_lval.ident = strdup (vcd_text); return Identifier; } {DECIMAL} { vcd_lval.integer = atoi (vcd_text); BEGIN(VAR2); return PositiveInteger; } {CODE} { vcd_lval.ident = strdup (vcd_text); BEGIN(VAR3); return IdentifierCode; } {IDENT} { vcd_lval.ident = strdup (vcd_text); BEGIN(VAR4); return Reference; } "[" { /* pass the '[' to the parser */ return '['; } "]" { /* pass the ']' to the parser */ return ']'; } ":" { /* pass the ':' to the parser */ return ':'; } "(" { /* pass the '(' to the parser */ return '('; } ")" { /* pass the ')' to the parser */ return ')'; } {DECIMAL} { vcd_lval.integer = atoi (vcd_text); return PositiveInteger; } {CODE} { vcd_lval.ident = strdup (vcd_text); BEGIN(INITIAL); return IdentifierCode; } . { /* skip any character in here */ } <*>\r?\n|{WS} { /* skip end of line and spaces */ } <*>. { /* any other character is invalid */ fprintf (stderr, "line %d: syntax error, unrecognized character: `%s'\n", vcd_lineno, vcd_text); return InvalidCharacter; } %%