Qucs-core  0.0.19
scan_dataset.l
Go to the documentation of this file.
00001 /* -*-c-*- */
00002 
00003 %{
00004 /*
00005  * scan_dataset.l - scanner for the Qucs dataset
00006  *
00007  * Copyright (C) 2003, 2004, 2005, 2006, 2008 Stefan Jahn <stefan@lkcc.org>
00008  *
00009  * This is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2, or (at your option)
00012  * any later version.
00013  *
00014  * This software is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this package; see the file COPYING.  If not, write to
00021  * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
00022  * Boston, MA 02110-1301, USA.
00023  *
00024  * $Id$
00025  *
00026  */
00027 
00028 #if defined(__clang__)
00029 #pragma clang diagnostic push
00030 #pragma clang diagnostic ignored "-Wdeprecated-register"
00031 #endif
00032 
00033 #if HAVE_CONFIG_H
00034 # include <config.h>
00035 #endif
00036 
00037 #include <stdio.h>
00038 #include <stdlib.h>
00039 #include <string.h>
00040 #include <ctype.h>
00041 
00042 #ifdef __MINGW32__
00043 #include <io.h>
00044 #endif
00045 
00046 #ifdef HAVE_UNISTD_H
00047 #include <unistd.h>
00048 #endif
00049 
00050 #include "logging.h"
00051 #include "complex.h"
00052 #include "object.h"
00053 #include "vector.h"
00054 #include "dataset.h"
00055 #include "check_dataset.h"
00056 #include "tokens_dataset.h"
00057 
00058 using namespace qucs;
00059 
00060 %}
00061 
00062 WS       [ \t\n\r]
00063 IDENT1   [a-zA-Z_][a-zA-Z0-9_]*
00064 IDENT2   [a-zA-Z_][a-zA-Z0-9_\[\],]*
00065 IDENT3   [a-zA-Z0-9_][a-zA-Z0-9_]*
00066 IDENT    {IDENT1}|{IDENT2}
00067 PIDENT   {IDENT1}|{IDENT2}|{IDENT3}
00068 SIMPLEID {IDENT}
00069 POSTID   "."{PIDENT}
00070 ID       {SIMPLEID}{POSTID}*
00071 DIGIT    [0-9]
00072 EXPONENT [Ee][+-]?{DIGIT}+
00073 RINT     [+-]?{DIGIT}+
00074 IINT     [+-]?[ij]{1}{DIGIT}+
00075 RFLOAT1  [+-]?{DIGIT}+{EXPONENT}
00076 RFLOAT2  [+-]?{DIGIT}*"."{DIGIT}+({EXPONENT})?
00077 IFLOAT1  [+-]?[ij]{1}{DIGIT}+{EXPONENT}
00078 IFLOAT2  [+-]?[ij]{1}{DIGIT}*"."{DIGIT}+({EXPONENT})?
00079 CREAL    ({RFLOAT1}|{RFLOAT2}|{RINT})
00080 CIMAG    ({IFLOAT1}|{IFLOAT2}|{IINT})
00081 COMPLEX  {CREAL}{CIMAG}
00082 SPACE    [ \t]
00083 VERSION  "<Qucs Dataset "{DIGIT}+"."{DIGIT}+"."{DIGIT}+">"
00084 DBEGIN   "dep"
00085 IBEGIN   "indep"
00086 DEND     "/dep"
00087 IEND     "/indep"
00088 
00089 
00090 %x COMMENT DESCRIPTION
00091 %option yylineno noyywrap nounput noinput prefix="dataset_"
00092 
00093 %%
00094 
00095 <INITIAL>{VERSION} {
00096     return Version;
00097   }
00098 
00099 <DESCRIPTION>{DBEGIN} {
00100     return DepBegin;
00101   }
00102 
00103 <DESCRIPTION>{IBEGIN} {
00104     return IndepBegin;
00105   }
00106 
00107 <DESCRIPTION>{DEND} {
00108     return DepEnd;
00109   }
00110 
00111 <DESCRIPTION>{IEND} {
00112     return IndepEnd;
00113   }
00114 
00115 <INITIAL,DESCRIPTION>{ID} { /* identify identifier */
00116     dataset_lval.ident = strdup (dataset_text);
00117     return Identifier;
00118   }
00119 
00120 <INITIAL>{CREAL} { /* identify real float */
00121     dataset_lval.f = strtod (dataset_text, NULL);
00122     return REAL;
00123   }
00124 
00125 <INITIAL>{CIMAG} { /* identify imaginary float */
00126     if (dataset_text[0] == 'i' || dataset_text[0] == 'j')
00127       dataset_text[0] = '0';
00128     else
00129       dataset_text[1] = '0';
00130     dataset_lval.f = strtod (dataset_text, NULL);
00131     return IMAG;
00132   }
00133 
00134 <INITIAL>{COMPLEX} { /* identify complete complex number */
00135     int i = 0;
00136     while (dataset_text[i] != 'i' && dataset_text[i] != 'j') i++;
00137     dataset_text[i] = dataset_text[i - 1];
00138     dataset_text[i - 1] = '\0';
00139     dataset_lval.c.r = strtod (dataset_text, NULL);
00140     dataset_lval.c.i = strtod (&dataset_text[i], NULL);
00141     return COMPLEX;
00142   }
00143 
00144 <DESCRIPTION>{RINT} { /* identify integer */
00145     dataset_lval.n = strtol (dataset_text, NULL, 10);
00146     return Integer;
00147   }
00148 
00149 <INITIAL>"<" { /* pass the '<' to the parser */
00150     BEGIN(DESCRIPTION);
00151     return '<';
00152   }
00153 <DESCRIPTION>">" { /* pass the '>' to the parser */
00154     BEGIN(INITIAL);
00155     return '>';
00156   }
00157 <INITIAL>\r?\n { /* detect end of line */ return Eol; }
00158 
00159 <*>{SPACE}|\\\r?\n /* skip spaces and the trailing '\' */
00160 
00161 <INITIAL>"#" { /* leave these characters */
00162     BEGIN(COMMENT);
00163   }
00164 <INITIAL,DESCRIPTION>. { /* any other character in invalid */
00165     logprint (LOG_ERROR,
00166               "line %d: syntax error, unrecognized character: `%s'\n",
00167               dataset_lineno, dataset_text);
00168     return InvalidCharacter;
00169   }
00170 
00171 <COMMENT>.     { /* skip any character in here */ }
00172 <COMMENT>\r?\n { BEGIN(INITIAL); /* skipping ends here */ }
00173 
00174 %%