Qucs-core
0.0.19
|
00001 /* -*-c++-*- */ 00002 00003 %{ 00004 /* 00005 * parse_dataset.y - parser for the Qucs dataset 00006 * 00007 * Copyright (C) 2003, 2004, 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 10000000 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_dataset.h" 00047 00048 using namespace qucs; 00049 00050 %} 00051 00052 %name-prefix "dataset_" 00053 00054 %token InvalidCharacter 00055 %token Identifier 00056 %token REAL 00057 %token IMAG 00058 %token COMPLEX 00059 %token Integer 00060 %token Eol 00061 %token IndepBegin 00062 %token DepBegin 00063 %token IndepEnd 00064 %token DepEnd 00065 %token Version 00066 00067 %union { 00068 char * ident; 00069 double f; 00070 struct { 00071 double r; 00072 double i; 00073 } c; 00074 long n; 00075 qucs::vector * v; 00076 qucs::dataset * data; 00077 qucs::strlist * list; 00078 } 00079 00080 %type <list> IdentifierList 00081 %type <ident> Identifier 00082 %type <f> REAL IMAG 00083 %type <c> COMPLEX 00084 %type <n> Integer 00085 %type <v> FloatList 00086 %type <data> VersionLine VariableList Variable 00087 00088 %% 00089 00090 Input: 00091 VersionLine VariableList { /* describes a valid dataset */ } 00092 ; 00093 00094 VersionLine: 00095 Version Eol { /* version line */ 00096 $$ = dataset_result = new dataset (); 00097 } 00098 ; 00099 00100 VariableList: /* nothing */ { } 00101 | Variable VariableList { /* dependent and independent variable vectors */ } 00102 | Eol VariableList { /* skip to next line */ } 00103 ; 00104 00105 Variable: 00106 '<' DepBegin Identifier IdentifierList '>' FloatList '<' DepEnd '>' { 00107 /* dependent variable vector */ 00108 dataset_vector->setName ($3); 00109 dataset_vector->reverse (); 00110 dataset_vector->setDependencies (dataset_idents); 00111 dataset_result->appendVariable (dataset_vector); 00112 dataset_vector = NULL; 00113 dataset_idents = NULL; 00114 free ($3); 00115 } 00116 | '<' IndepBegin Identifier Integer '>' FloatList '<' IndepEnd '>' { 00117 /* independent variable vector */ 00118 dataset_vector->setRequested ($4); 00119 dataset_vector->setName ($3); 00120 dataset_vector->reverse (); 00121 dataset_result->appendDependency (dataset_vector); 00122 dataset_vector = NULL; 00123 free ($3); 00124 } 00125 ; 00126 00127 FloatList: /* nothing */ { $$ = dataset_vector = new vector (); } 00128 | REAL FloatList { 00129 dataset_vector->add ($1); 00130 } 00131 | COMPLEX FloatList { 00132 dataset_vector->add (nr_complex_t ($1.r, $1.i)); 00133 } 00134 | IMAG FloatList { 00135 dataset_vector->add (nr_complex_t (0.0, $1)); 00136 } 00137 | Eol FloatList { /* skip to next line */ } 00138 ; 00139 00140 IdentifierList: /* nothing */ { $$ = dataset_idents = new strlist (); } 00141 | Identifier IdentifierList { 00142 dataset_idents->add ($1); 00143 free ($1); 00144 } 00145 ; 00146 00147 %% 00148 00149 int dataset_error (const char * error) { 00150 logprint (LOG_ERROR, "line %d: %s\n", dataset_lineno, error); 00151 return 0; 00152 }