Qucs-core  0.0.19
scan_zvr.l
Go to the documentation of this file.
00001 /* -*-c-*- */
00002 
00003 %{
00004 /*
00005  * scan_zvr.l - scanner for a ZVR data file
00006  *
00007  * Copyright (C) 2006, 2007 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 "check_zvr.h"
00051 #include "tokens_zvr.h"
00052 
00053 #if !HAVE_STRCHR
00054 # define strchr  index
00055 # define strrchr rindex
00056 #endif
00057 
00058 using namespace qucs;
00059 
00060 %}
00061 
00062 WS       [ \t\n\r]
00063 DIGIT    [0-9]
00064 EXPONENT [Ee][+-]?{DIGIT}+
00065 INT      [+-]?{DIGIT}+
00066 REAL     [+-]?{DIGIT}+("."{DIGIT}+)?{EXPONENT}?
00067 DECIMAL  {DIGIT}+
00068 IDENT    [a-zA-Z][a-zA-Z-]*
00069 DIGITS   {DIGIT}+
00070 DIDENT   [A-Z]({DIGIT}{1,2})?
00071 
00072 %x VERSION
00073 
00074 %option yylineno noyywrap nounput noinput prefix="zvr_"
00075 
00076 %%
00077 
00078 <INITIAL>"ZVR," {
00079   BEGIN(VERSION);
00080   return ZVR;
00081 }
00082 
00083 <VERSION>{DIGITS}"."{DIGITS} {
00084   BEGIN(INITIAL);
00085   return Version;
00086 }
00087 
00088 <INITIAL>{REAL} {
00089   zvr_lval.f = strtod (zvr_text, NULL);
00090   return Real;
00091 }
00092 
00093 <INITIAL>("Hz")|("none")|("dB") {
00094   zvr_lval.ident = strdup (zvr_text);
00095   return Unit;
00096 }
00097 
00098 <INITIAL>("RI")|("COMPLEX")|("MAGNITUDE")|("PHASE")|("MA")|("DB") {
00099   zvr_lval.ident = strdup (zvr_text);
00100   return DataFMT;
00101 }
00102 
00103 <INITIAL>{DIDENT} {
00104   zvr_lval.ident = strdup (zvr_text);
00105   return DataTYP;
00106 }
00107 
00108 <INITIAL>{IDENT} {
00109   zvr_lval.ident = strdup (zvr_text);
00110   return Identifier;
00111 }
00112 
00113 <INITIAL>(("re")|("im")|("mag")|("ang")|("db"))?{DIDENT} {
00114   zvr_lval.ident = strdup (zvr_text);
00115   return DataIDN;
00116 }
00117 
00118 <INITIAL>";"   { /* pass the ';' to the parser */ return ';'; }
00119 
00120 <*>\r?\n|{WS}  { /* skip end of line and spaces */ }
00121 
00122 <*>. { /* any other character is invalid */
00123   fprintf (stderr,
00124            "line %d: syntax error, unrecognized character: `%s'\n",
00125            zvr_lineno, zvr_text);
00126   return InvalidCharacter;
00127 }
00128 
00129 %%