Qucs-core  0.0.19
parse_touchstone.y
Go to the documentation of this file.
00001 /* -*-c++-*- */
00002 
00003 %{
00004 /*
00005  * parse_touchstone.y - parser for Touchstone files
00006  *
00007  * Copyright (C) 2003, 2005, 2006 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 HAVE_CONFIG_H
00029 # include <config.h>
00030 #endif
00031 
00032 #include <stdio.h>
00033 #include <stdlib.h>
00034 #include <string.h>
00035 
00036 #define YYERROR_VERBOSE 42
00037 #define YYDEBUG 1
00038 #define YYMAXDEPTH 1000000
00039 
00040 #include "logging.h"
00041 #include "complex.h"
00042 #include "object.h"
00043 #include "vector.h"
00044 #include "dataset.h"
00045 #include "strlist.h"
00046 #include "check_touchstone.h"
00047 
00048 using namespace qucs;
00049 
00050 %}
00051 
00052 %name-prefix "touchstone_"
00053 
00054 %token InvalidCharacter
00055 %token Float
00056 %token Option
00057 %token Eol
00058 
00059 %union {
00060   char * ident;
00061   double f;
00062   qucs::vector * v;
00063   qucs::strlist * list;
00064 }
00065 
00066 %type <list> OptionList
00067 %type <ident> Option
00068 %type <f> Float
00069 %type <v> DataLine Dataset
00070 
00071 %%
00072 
00073 Input:
00074   OptionLine Dataset { /* describes a valid touchstone */ }
00075 ;
00076 
00077 OptionLine: /* option line */
00078     '#' OptionList 'R' Float OptionList Eol {
00079     touchstone_vector = NULL;
00080     touchstone_options.resistance = $4;
00081   }
00082   | '#' OptionList Eol {
00083     touchstone_vector = NULL;
00084     touchstone_options.resistance = 50.0;
00085   }
00086   | Eol OptionLine { /* skip this line */ }
00087 ;
00088 
00089 OptionList: /* nothing */ { }
00090   | Option OptionList {
00091     if (touchstone_idents == NULL) touchstone_idents = new strlist ();
00092     touchstone_idents->add ($1);
00093     free ($1);
00094   }
00095 ;
00096 
00097 Dataset: /* nothing */ { }
00098   | DataLine Eol Dataset { /* append vector lines */
00099     $1->setNext (touchstone_vector);
00100     touchstone_vector = $1;
00101   }
00102   | DataLine { /* last line, no trailing end-of-line */
00103     $1->setNext (touchstone_vector);
00104     touchstone_vector = $1;
00105     logprint (LOG_ERROR, "line %d: no trailing end-of-line found, "
00106               "continuing...\n", touchstone_lineno);
00107   }
00108   | Eol Dataset { /* skip this line */ }
00109 ;
00110 
00111 DataLine:
00112     Float Float Float {
00113     /* 1-port start */
00114     $$ = new vector ();
00115     $$->add ($1);
00116     $$->add ($2);
00117     $$->add ($3);
00118   }
00119   | Float Float Float Float Float {
00120     /* noise parameters */
00121     $$ = new vector ();
00122     $$->add ($1);
00123     $$->add ($2);
00124     $$->add ($3);
00125     $$->add ($4);
00126     $$->add ($5);
00127   }
00128   | Float Float Float Float Float Float Float Float Float {
00129     /* 2-port and 4- to n-port start */
00130     $$ = new vector ();
00131     $$->add ($1);
00132     $$->add ($2);
00133     $$->add ($3);
00134     $$->add ($4);
00135     $$->add ($5);
00136     $$->add ($6);
00137     $$->add ($7);
00138     $$->add ($8);
00139     $$->add ($9);
00140   }
00141   | Float Float Float Float Float Float Float {
00142     /* 3-port start */
00143     $$ = new vector ();
00144     $$->add ($1);
00145     $$->add ($2);
00146     $$->add ($3);
00147     $$->add ($4);
00148     $$->add ($5);
00149     $$->add ($6);
00150     $$->add ($7);
00151   }
00152   | Float Float Float Float Float Float Float Float {
00153     /* 4- and n-port continued */
00154     $$ = new vector ();
00155     $$->add ($1);
00156     $$->add ($2);
00157     $$->add ($3);
00158     $$->add ($4);
00159     $$->add ($5);
00160     $$->add ($6);
00161     $$->add ($7);
00162     $$->add ($8);
00163   }
00164   | Float Float Float Float Float Float {
00165     /* 3- and n-port continued */
00166     $$ = new vector ();
00167     $$->add ($1);
00168     $$->add ($2);
00169     $$->add ($3);
00170     $$->add ($4);
00171     $$->add ($5);
00172     $$->add ($6);
00173   }
00174   | Float Float Float Float {
00175     /* n-port continued */
00176     $$ = new vector ();
00177     $$->add ($1);
00178     $$->add ($2);
00179     $$->add ($3);
00180     $$->add ($4);
00181   }
00182   | Float Float {
00183     /* n-port continued */
00184     $$ = new vector ();
00185     $$->add ($1);
00186     $$->add ($2);
00187   }
00188 ;
00189 
00190 %%
00191 
00192 int touchstone_error (const char * error) {
00193   logprint (LOG_ERROR, "line %d: %s\n", touchstone_lineno, error);
00194   return 0;
00195 }