/* -*-c-*- */ %{ /* * scan_dataset.l - scanner for the Qucs dataset * * Copyright (C) 2003, 2004, 2005, 2006, 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 "logging.h" #include "complex.h" #include "object.h" #include "vector.h" #include "dataset.h" #include "check_dataset.h" #include "parse_dataset.hpp" using namespace qucs; %} WS [ \t\n\r] IDENT1 [a-zA-Z_][a-zA-Z0-9_]* IDENT2 [a-zA-Z_][a-zA-Z0-9_\[\],]* IDENT3 [a-zA-Z0-9_][a-zA-Z0-9_]* IDENT {IDENT1}|{IDENT2} PIDENT {IDENT1}|{IDENT2}|{IDENT3} SIMPLEID {IDENT} POSTID "."{PIDENT} ID {SIMPLEID}{POSTID}* DIGIT [0-9] EXPONENT [Ee][+-]?{DIGIT}+ RINT [+-]?{DIGIT}+ IINT [+-]?[ij]{1}{DIGIT}+ RFLOAT1 [+-]?{DIGIT}+{EXPONENT} RFLOAT2 [+-]?{DIGIT}*"."{DIGIT}+({EXPONENT})? IFLOAT1 [+-]?[ij]{1}{DIGIT}+{EXPONENT} IFLOAT2 [+-]?[ij]{1}{DIGIT}*"."{DIGIT}+({EXPONENT})? CREAL ({RFLOAT1}|{RFLOAT2}|{RINT}) CIMAG ({IFLOAT1}|{IFLOAT2}|{IINT}) COMPLEX {CREAL}{CIMAG} SPACE [ \t] VERSION "" DBEGIN "dep" IBEGIN "indep" DEND "/dep" IEND "/indep" %x COMMENT DESCRIPTION %option yylineno noyywrap nounput noinput prefix="dataset_" %% {VERSION} { return Version; } {DBEGIN} { return DepBegin; } {IBEGIN} { return IndepBegin; } {DEND} { return DepEnd; } {IEND} { return IndepEnd; } {ID} { /* identify identifier */ dataset_lval.ident = strdup (dataset_text); return Identifier; } {CREAL} { /* identify real float */ dataset_lval.f = strtod (dataset_text, NULL); return REAL; } {CIMAG} { /* identify imaginary float */ if (dataset_text[0] == 'i' || dataset_text[0] == 'j') dataset_text[0] = '0'; else dataset_text[1] = '0'; dataset_lval.f = strtod (dataset_text, NULL); return IMAG; } {COMPLEX} { /* identify complete complex number */ int i = 0; while (dataset_text[i] != 'i' && dataset_text[i] != 'j') i++; dataset_text[i] = dataset_text[i - 1]; dataset_text[i - 1] = '\0'; dataset_lval.c.r = strtod (dataset_text, NULL); dataset_lval.c.i = strtod (&dataset_text[i], NULL); return COMPLEX; } {RINT} { /* identify integer */ dataset_lval.n = strtol (dataset_text, NULL, 10); return Integer; } "<" { /* pass the '<' to the parser */ BEGIN(DESCRIPTION); return '<'; } ">" { /* pass the '>' to the parser */ BEGIN(INITIAL); return '>'; } \r?\n { /* detect end of line */ return Eol; } <*>{SPACE}|\\\r?\n /* skip spaces and the trailing '\' */ "#" { /* leave these characters */ BEGIN(COMMENT); } . { /* any other character in invalid */ logprint (LOG_ERROR, "line %d: syntax error, unrecognized character: `%s'\n", dataset_lineno, dataset_text); return InvalidCharacter; } . { /* skip any character in here */ } \r?\n { BEGIN(INITIAL); /* skipping ends here */ } %%