Qucs-core  0.0.19
scan_touchstone.l
Go to the documentation of this file.
00001 /* -*-c-*- */
00002 
00003 %{
00004 /*
00005  * scan_touchstone.l - scanner for Touchstone files
00006  *
00007  * Copyright (C) 2003, 2004, 2005, 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_touchstone.h"
00056 #include "tokens_touchstone.h"
00057 
00058 using namespace qucs;
00059 
00060 %}
00061 
00062 WS       [ \t\n\r]
00063 ID       [a-zA-Z_][a-zA-Z0-9_]*
00064 DIGIT    [0-9]
00065 EXPONENT [Ee][+-]?{DIGIT}+
00066 INT      [+-]?{DIGIT}+
00067 FLOAT1   [+-]?{DIGIT}+{EXPONENT}
00068 FLOAT2   [+-]?{DIGIT}*"."{DIGIT}+({EXPONENT})?
00069 SPACE    [ \t]
00070 
00071 %x COMMENT
00072 %option yylineno noyywrap nounput noinput prefix="touchstone_"
00073 
00074 %%
00075 
00076 <INITIAL>[Rr]  { /* pass the 'R' to the parser */ return 'R'; }
00077 <INITIAL>^#    { /* pass the leading '#' to the parser */ return '#'; }
00078 <INITIAL>\r?\n { /* detect end of line */ return Eol; }
00079 
00080 <*>{SPACE} /* skip spaces */
00081 
00082 <INITIAL>{ID} { /* identify identifier */
00083     touchstone_lval.ident = strdup (touchstone_text);
00084     return Option;
00085   }
00086 
00087 <INITIAL>({FLOAT1}|{FLOAT2}|{INT}) { /* identify float */
00088     touchstone_lval.f = strtod (touchstone_text, NULL);
00089     return Float;
00090   }
00091 
00092 <INITIAL>"!" { /* leave these characters */
00093     BEGIN(COMMENT);
00094   }
00095 
00096 <INITIAL>. { /* any other character in invalid */
00097     logprint (LOG_ERROR,
00098               "line %d: syntax error, unrecognized character: `%s'\n",
00099               touchstone_lineno, touchstone_text);
00100     return InvalidCharacter;
00101   }
00102 
00103 <COMMENT>.     { /* skip any character in here */ }
00104 <COMMENT>\r?\n { BEGIN(INITIAL); /* skipping ends here */ return Eol; }
00105 
00106 %%