Qucs-core  0.0.19
parse_zvr.y
Go to the documentation of this file.
00001 /* -*-c++-*- */
00002 
00003 %{
00004 /*
00005  * parse_zvr.y - parser for a ZVR data file
00006  *
00007  * Copyright (C) 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 #include <ctype.h>
00036 
00037 #define YYERROR_VERBOSE 42
00038 #define YYDEBUG 1
00039 #define YYMAXDEPTH 1000000
00040 
00041 #define __NOEXTENSIONS__ 1
00042 
00043 #include "object.h"
00044 #include "complex.h"
00045 #include "vector.h"
00046 #include "check_zvr.h"
00047 
00048 using namespace qucs;
00049 
00050 %}
00051 
00052 %name-prefix "zvr_"
00053 
00054 %token ZVR
00055 %token Version
00056 %token Identifier
00057 %token Real
00058 %token Unit
00059 %token DataFMT DataTYP DataIDN
00060 %token InvalidCharacter
00061 
00062 %union {
00063   char * ident;
00064   double f;
00065   struct zvr_data_t * data;
00066   struct zvr_header_t * head;
00067   struct zvr_vector_t * vec;
00068   struct zvr_line_t * line;
00069 }
00070 
00071 %type <ident> DataFMT DataTYP DataIDN DataIdent
00072 %type <ident> Identifier Unit Ident
00073 %type <f> Real
00074 %type <head> BodyStart
00075 %type <vec> DataHeader
00076 %type <data> Body BodyList
00077 %type <line> DataLine DataList
00078 
00079 %%
00080 
00081 Input:
00082   Header Body BodyList { /* a ZVR file */
00083     $2->next = $3;
00084     zvr_root = $2;
00085   }
00086 ;
00087 
00088 Header:
00089   ZVR Version { }
00090 ;
00091 
00092 BodyList: /* nothing */ { $$ = NULL; }
00093   | Body BodyList {
00094     if ($1) {
00095       $1->next = $2;
00096       $$ = $1;
00097     } else {
00098       $$ = $2;
00099     }
00100   }
00101 ;
00102 
00103 ParaList6:
00104   Identifier ';' Identifier ';' Identifier ';'
00105   Identifier ';' Identifier ';' Identifier {
00106   }
00107 ;
00108 
00109 ParaList2:
00110   Identifier ';' Identifier {
00111   }
00112 ;
00113 
00114 Ident:
00115   Identifier | Unit
00116 ;
00117 
00118 BodyStart:
00119   ParaList6
00120   Real    ';' Real  ';' Unit    ';' Real    ';' DataTYP ';' Real
00121   ParaList6
00122   DataTYP ';' Ident ';' DataFMT ';' Ident   ';' Ident   ';' Ident
00123   ParaList2
00124   Ident   ';' Ident {
00125     $$ = (struct zvr_header_t *) calloc (sizeof (struct zvr_header_t), 1);
00126     $$->start = $2;
00127     $$->stop = $4;
00128     $$->funit = $6;
00129     $$->points = (int) $8;
00130     $$->zref = $12;
00131     $$->d_TYP = $10;
00132     $$->d_UNT = $20;
00133     $$->d_FMT = $18;
00134   }
00135 ;
00136 
00137 Body:
00138   BodyStart DataHeader DataList {
00139     $$ = (struct zvr_data_t *) calloc (sizeof (struct zvr_data_t), 1);
00140     $$->h = $1;
00141     $$->v = $2;
00142     $$->d = $3;
00143   }
00144 ;
00145 
00146 DataList: /* nothing */ { $$ = NULL; }
00147   | DataLine DataList {
00148     if ($1) {
00149       $1->next = $2;
00150       $$ = $1;
00151     } else {
00152       $$ = $2;
00153     }
00154   }
00155 ;
00156 
00157 DataLine:
00158   Real ';' Real {
00159     $$ = (struct zvr_line_t *) calloc (sizeof (struct zvr_line_t), 1);
00160     $$->d = $1;
00161     $$->r = $3;
00162   }
00163   | Real ';' Real ';' Real {
00164     $$ = (struct zvr_line_t *) calloc (sizeof (struct zvr_line_t), 1);
00165     $$->d = $1;
00166     $$->r = $3;
00167     $$->i = $5;
00168   }
00169 ;
00170 
00171 DataIdent:
00172   DataTYP | DataIDN
00173 ;
00174 
00175 DataHeader:
00176   Identifier ';' DataIdent {
00177     $$ = (struct zvr_vector_t *) calloc (sizeof (struct zvr_vector_t), 1);
00178     $$->nf = $1;
00179     $$->n1 = $3;
00180     $$->vi = new vector ();
00181     $$->vd = new vector ();
00182   }
00183   | Identifier ';' DataIdent ';' DataIdent {
00184     $$ = (struct zvr_vector_t *) calloc (sizeof (struct zvr_vector_t), 1);
00185     $$->nf = $1;
00186     $$->n1 = $3;
00187     $$->n2 = $5;
00188     $$->vi = new vector ();
00189     $$->vd = new vector ();
00190   }
00191 ;
00192 
00193 %%
00194 
00195 int zvr_error (const char * error) {
00196   fprintf (stderr, "line %d: %s\n", zvr_lineno, error);
00197   return 0;
00198 }