Qucs-core  0.0.19
parse_mdl.y
Go to the documentation of this file.
00001 /* -*-c++-*- */
00002 
00003 %{
00004 /*
00005  * parse_mdl.y - parser for an IC-CAP MDL 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_mdl.h"
00047 
00048 using namespace qucs;
00049 
00050 %}
00051 
00052 %name-prefix "mdl_"
00053 
00054 %token LINK
00055 %token Identifier
00056 %token String
00057 %token InvalidCharacter
00058 %token Real
00059 %token t_LINK
00060 %token t_VIEW
00061 %token t_TABLE
00062 %token t_PSTABLE
00063 %token t_CNTABLE
00064 %token t_OPTIMEDIT
00065 %token t_BLKEDIT
00066 %token t_HYPTABLE
00067 %token t_ELEMENT
00068 %token t_DATA
00069 %token t_DATASET
00070 %token t_DATASIZE
00071 %token t_POINT
00072 %token t_MEMBER
00073 %token t_LIST
00074 %token t_PLOTOPTIMIZEROPT
00075 %token t_PLOTOPTIMIZERTRACESET
00076 %token t_PLOTOPTIMIZERTRACEREGSET
00077 %token t_PLOTOPTIMIZERTRACENATREGSET
00078 %token t_PLOTERROR
00079 %token t_TYPE
00080 %token t_CIRCUITDECK
00081 %token t_PARAM
00082 %token t_RANGE
00083 %token t_CONNPAIR
00084 %token t_CALDATA
00085 %token t_CALSET
00086 %token t_TERM
00087 %token t_APPLIC
00088 %token t_SUBAPP
00089 %token t_EDITSIZE
00090 %token t_PLOTSIZE
00091 %token t_OPTRANGE
00092 
00093 %union {
00094   char * ident;
00095   double f;
00096   struct mdl_point_t * point;
00097   struct mdl_dataset_t * dset;
00098   struct mdl_datasize_t * dsize;
00099   struct mdl_link_t * link;
00100   struct mdl_data_t * data;
00101   struct mdl_dcontent_t * dcontent;
00102   struct mdl_lcontent_t * lcontent;
00103   struct mdl_element_t * element;
00104   struct mdl_hyptable_t * hyptable;
00105   struct mdl_table_t * table;
00106 }
00107 
00108 %type <ident> Identifier t_LINK String TYPE_Line
00109 %type <point> POINT_Line PointList Point
00110 %type <f> Real
00111 %type <dset> DSContent DATASET_Definition
00112 %type <link> LINK_Definition LinkList
00113 %type <lcontent> LinkContent LinkContentList
00114 %type <dcontent> DataContent DataContentList
00115 %type <data> DATA_Definition
00116 %type <dsize> DATASIZE_Line
00117 %type <element> ELEMENT_Line HypTableContent HypTableContentList
00118 %type <element> TableContent TableContentList
00119 %type <hyptable> HYPTABLE_Definition
00120 %type <table> TABLE_Definition
00121 
00122 %%
00123 
00124 Input:
00125   LinkList {
00126     mdl_root = $1;
00127   }
00128 ;
00129 
00130 LinkList: /* nothing */ { $$ = NULL; }
00131   | LINK_Definition LinkList {
00132     $1->next = $2;
00133     $$ = $1;
00134   }
00135 ;
00136 
00137 TableContent:
00138   VIEW_Line {
00139     $$ = NULL;
00140   }
00141   | ELEMENT_Line {
00142     $$ = $1;
00143   }
00144   | TABLE_Definition {
00145     $$ = NULL;
00146   }
00147 ;
00148 
00149 TableContentList: /* nothing */ { $$ = NULL; }
00150   | TableContent TableContentList {
00151     if ($1) {
00152       $1->next = $2;
00153       $$ = $1;
00154     } else {
00155       $$ = $2;
00156     }
00157   }
00158 ;
00159 
00160 HypTableContent:
00161   VIEW_Line {
00162     $$ = NULL;
00163   }
00164   | ELEMENT_Line {
00165     $$ = $1;
00166   }
00167 ;
00168 
00169 HypTableContentList: /* nothing */ { $$ = NULL; }
00170   | HypTableContent HypTableContentList {
00171     if ($1) {
00172       $1->next = $2;
00173       $$ = $1;
00174     } else {
00175       $$ = $2;
00176     }
00177   }
00178 ;
00179 
00180 ConnTableContent:
00181   CONNPAIR_Line
00182 ;
00183 
00184 ConnTableContentList: /* nothing */ { }
00185   | ConnTableContent ConnTableContentList {
00186   }
00187 ;
00188 
00189 OptEditContent:
00190   VIEW_Line
00191   | TABLE_Definition
00192 ;
00193 
00194 OptEditContentList: /* nothing */ { }
00195   | OptEditContent OptEditContentList {
00196   }
00197 ;
00198 
00199 LinkContent:
00200   VIEW_Line {
00201     $$ = NULL;
00202   }
00203   | APPLIC_Line {
00204     $$ = NULL;
00205   }
00206   | SUBAPP_Line {
00207     $$ = NULL;
00208   }
00209   | LIST_Line {
00210     $$ = NULL;
00211   }
00212   | MEMBER_Line {
00213     $$ = NULL;
00214   }
00215   | TABLE_Definition {
00216     $$ = (struct mdl_lcontent_t *) calloc (sizeof (struct mdl_lcontent_t), 1);
00217     $$->type = t_TABLE;
00218     $$->table = $1;
00219   }
00220   | LINK_Definition {
00221     $$ = (struct mdl_lcontent_t *) calloc (sizeof (struct mdl_lcontent_t), 1);
00222     $$->type = t_LINK;
00223     $$->link = $1;
00224   }
00225   | DATA_Definition {
00226     $$ = (struct mdl_lcontent_t *) calloc (sizeof (struct mdl_lcontent_t), 1);
00227     $$->type = t_DATA;
00228     $$->data = $1;
00229   }
00230 ;
00231 
00232 LinkContentList: /* nothing */ { $$ = NULL; }
00233   | LinkContent LinkContentList {
00234     if ($1) {
00235       $1->next = $2;
00236       $$ = $1;
00237     } else {
00238       $$ = $2;
00239     }
00240   }
00241 ;
00242 
00243 DataContent:
00244   PLOTOPTIMIZEROPT_Line {
00245     $$ = NULL;
00246   }
00247   | PLOTOPTIMIZERTRACESET_Line {
00248     $$ = NULL;
00249   }
00250   | PLOTOPTIMIZERTRACEREGSET_Line {
00251     $$ = NULL;
00252   }
00253   | PLOTOPTIMIZERTRACENATREGSET_Line {
00254     $$ = NULL;
00255   }
00256   | PLOTERROR_Line {
00257     $$ = NULL;
00258   }
00259   | EDITSIZE_Line {
00260     $$ = NULL;
00261   }
00262   | PLOTSIZE_Line {
00263     $$ = NULL;
00264   }
00265   | TABLE_Definition {
00266     $$ = NULL;
00267   }
00268   | PSTABLE_Definition {
00269     $$ = NULL;
00270   }
00271   | CNTABLE_Definition {
00272     $$ = NULL;
00273   }
00274   | OPTIMEDIT_Definition {
00275     $$ = NULL;
00276   }
00277   | CALSET_Definition {
00278     $$ = NULL;
00279   }
00280   | HYPTABLE_Definition {
00281     $$ = (struct mdl_dcontent_t *) calloc (sizeof (struct mdl_dcontent_t), 1);
00282     $$->type = t_HYPTABLE;
00283     $$->hyptable = $1;
00284   }
00285   | DATASET_Definition {
00286     $$ = (struct mdl_dcontent_t *) calloc (sizeof (struct mdl_dcontent_t), 1);
00287     $$->type = t_DATASET;
00288     $$->data = $1;
00289   }
00290   | BLKEDIT_Definition {
00291     $$ = NULL;
00292   }
00293   | CIRCUITDECK_Definition {
00294     $$ = NULL;
00295   }
00296 ;
00297 
00298 DataContentList: /* nothing */ { $$ = NULL; }
00299   | DataContent DataContentList {
00300     if ($1) {
00301       $1->next = $2;
00302       $$ = $1;
00303     } else {
00304       $$ = $2;
00305     }
00306   }
00307 ;
00308 
00309 PSContent:
00310   PARAM_Line
00311   | RANGE_Line
00312   | OPTRANGE_Line
00313 ;
00314 
00315 PSContentList: /* nothing */ { }
00316   | PSContent PSContentList {
00317   }
00318 ;
00319 
00320 DSContent:
00321   DATASIZE_Line TYPE_Line PointList {
00322     $$ = (struct mdl_dataset_t *) calloc (sizeof (struct mdl_dataset_t), 1);
00323     $$->dsize = $1;
00324     $$->type1 = $2;
00325     $$->data1 = $3;
00326   }
00327   | DATASIZE_Line TYPE_Line PointList TYPE_Line PointList {
00328     $$ = (struct mdl_dataset_t *) calloc (sizeof (struct mdl_dataset_t), 1);
00329     $$->dsize = $1;
00330     $$->type1 = $2;
00331     $$->data1 = $3;
00332     $$->type2 = $4;
00333     $$->data2 = $5;
00334   }
00335 ;
00336 
00337 Point:
00338   POINT_Line
00339 ;
00340 
00341 PointList: /* nothing */ { $$ = NULL; }
00342   | Point PointList {
00343     $1->next = $2;
00344     $$ = $1;
00345   }
00346 ;
00347 
00348 ELEMENT_Line:
00349   t_ELEMENT Real String String String {
00350     $$ = (struct mdl_element_t *) calloc (sizeof (struct mdl_element_t), 1);
00351     $$->number = (int) $2;
00352     $$->name = $3;
00353     $$->value = $4;
00354     $$->attr = $5;
00355   }
00356   | t_ELEMENT Real String String {
00357     $$ = (struct mdl_element_t *) calloc (sizeof (struct mdl_element_t), 1);
00358     $$->number = (int) $2;
00359     $$->name = $3;
00360     $$->value = $4;
00361   }
00362   | t_ELEMENT String String {
00363     $$ = (struct mdl_element_t *) calloc (sizeof (struct mdl_element_t), 1);
00364     $$->name = $2;
00365     $$->value = $3;
00366   }
00367 ;
00368 
00369 VIEW_Line:
00370   t_VIEW Identifier Real String {
00371     free ($2);
00372     free ($4);
00373   }
00374 ;
00375 
00376 TABLE_Definition:
00377   t_TABLE String '{' TableContentList '}' {
00378     $$ = (struct mdl_table_t *) calloc (sizeof (struct mdl_table_t), 1);
00379     $$->name = $2;
00380     $$->data = $4;
00381   }
00382   | t_TABLE String Real '{' TableContentList '}' {
00383     $$ = (struct mdl_table_t *) calloc (sizeof (struct mdl_table_t), 1);
00384     $$->name = $2;
00385     $$->data = $5;
00386   }
00387   | t_TABLE '{'  '}' {
00388     $$ = (struct mdl_table_t *) calloc (sizeof (struct mdl_table_t), 1);
00389   }
00390 ;
00391 
00392 LINK_Definition:
00393   LINK t_LINK String '{' LinkContentList '}' {
00394     $$ = (struct mdl_link_t *) calloc (sizeof (struct mdl_link_t), 1);
00395     $$->name = $3;
00396     $$->type = $2;
00397     $$->content = $5;
00398   }
00399 ;
00400 
00401 DATA_Definition:
00402   t_DATA '{' DataContentList '}' {
00403     $$ = (struct mdl_data_t *) calloc (sizeof (struct mdl_data_t), 1);
00404     $$->content = $3;
00405   }
00406 ;
00407 
00408 PSTABLE_Definition:
00409   t_PSTABLE String '{' PSContentList '}' {
00410     free ($2);
00411   }
00412 ;
00413 
00414 CIRCUITDECK_Definition:
00415   t_CIRCUITDECK '{' '}'
00416 ;
00417 
00418 BLKEDIT_Definition:
00419   t_BLKEDIT String '{' '}' {
00420     free ($2);
00421   }
00422 ;
00423 
00424 CNTABLE_Definition:
00425   t_CNTABLE String '{' ConnTableContentList '}' {
00426     free ($2);
00427   }
00428 ;
00429 
00430 OPTIMEDIT_Definition:
00431   t_OPTIMEDIT '{' OptEditContentList '}' {
00432   }
00433 ;
00434 
00435 CALSET_Definition:
00436   t_CALSET String '{' CalSetContent '}' {
00437     free ($2);
00438   }
00439 ;
00440 
00441 CalSetContent:
00442   Identifier Real Identifier Real Identifier Real
00443   CALDATA_Definition {
00444   }
00445 ;
00446 
00447 CALDATA_Definition:
00448   t_CALDATA '{' CalDataContentList '}' {
00449   }
00450 ;
00451 
00452 CalDataContentList: /* nothing */ { }
00453   | CalDataContent CalDataContentList {
00454   }
00455 ;
00456 
00457 CalDataContent:
00458   TERM_Line PointList {
00459   }
00460 ;
00461 
00462 TERM_Line:
00463   t_TERM Real {
00464   }
00465 ;
00466 
00467 APPLIC_Line:
00468   t_APPLIC String Real Real Real {
00469     free ($2);
00470   }
00471 ;
00472 
00473 SUBAPP_Line:
00474   t_SUBAPP String Real {
00475     free ($2);
00476   }
00477 ;
00478 
00479 HYPTABLE_Definition:
00480   t_HYPTABLE String '{' HypTableContentList '}' {
00481     $$ = (struct mdl_hyptable_t *) calloc (sizeof (struct mdl_hyptable_t), 1);
00482     $$->name = $2;
00483     $$->data = $4;
00484   }
00485 ;
00486 
00487 DATASET_Definition:
00488   t_DATASET '{' DSContent '}' {
00489     $$ = $3;
00490   }
00491 ;
00492 
00493 DATASIZE_Line:
00494   t_DATASIZE Identifier Real Real Real {
00495     $$ = (struct mdl_datasize_t *) calloc (sizeof (struct mdl_datasize_t), 1);
00496     $$->type = $2;
00497     $$->size = (int) $3;
00498     $$->x = (int) $4;
00499     $$->y = (int) $5;
00500   }
00501 ;
00502 
00503 TYPE_Line:
00504   t_TYPE Identifier {
00505     $$ = $2;
00506   }
00507 ;
00508 
00509 POINT_Line:
00510   t_POINT Real Real Real Real Real {
00511     $$ = (struct mdl_point_t *) calloc (sizeof (struct mdl_point_t), 1);
00512     $$->n = (int) $2;
00513     $$->x = (int) $3;
00514     $$->y = (int) $4;
00515     $$->r = $5;
00516     $$->i = $6;
00517   }
00518 ;
00519 
00520 LIST_Line:
00521   t_LIST t_LINK String {
00522     free ($2);
00523     free ($3);
00524   }
00525 ;
00526 
00527 PLOTOPTIMIZEROPT_Line:
00528   t_PLOTOPTIMIZEROPT Identifier Real {
00529     free ($2);
00530   }
00531 ;
00532 
00533 PLOTOPTIMIZERTRACESET_Line:
00534   t_PLOTOPTIMIZERTRACESET String String String {
00535     free ($2);
00536     free ($3);
00537     free ($4);
00538   }
00539   | t_PLOTOPTIMIZERTRACESET String String {
00540     free ($2);
00541     free ($3);
00542   }
00543 ;
00544 
00545 PLOTOPTIMIZERTRACEREGSET_Line:
00546   t_PLOTOPTIMIZERTRACEREGSET String Real String String String String {
00547     free ($2);
00548     free ($4);
00549     free ($5);
00550     free ($6);
00551     free ($7);
00552   }
00553 ;
00554 
00555 PLOTOPTIMIZERTRACENATREGSET_Line:
00556   t_PLOTOPTIMIZERTRACENATREGSET String Real String String String String {
00557     free ($2);
00558     free ($4);
00559     free ($5);
00560     free ($6);
00561     free ($7);
00562   }
00563 ;
00564 
00565 PLOTERROR_Line:
00566   t_PLOTERROR Identifier Real {
00567     free ($2);
00568   }
00569 ;
00570 
00571 EDITSIZE_Line:
00572   t_EDITSIZE Real Real {
00573   }
00574 ;
00575 
00576 PLOTSIZE_Line:
00577   t_PLOTSIZE Real Real {
00578   }
00579 ;
00580 
00581 MEMBER_Line:
00582   t_MEMBER t_LINK String {
00583     free ($2);
00584     free ($3);
00585   }
00586 ;
00587 
00588 PARAM_Line:
00589   t_PARAM Identifier String {
00590     free ($2);
00591     free ($3);
00592   }
00593 ;
00594 
00595 RANGE_Line:
00596   t_RANGE Identifier String String {
00597     free ($2);
00598     free ($3);
00599     free ($4);
00600   }
00601 ;
00602 
00603 OPTRANGE_Line:
00604   t_OPTRANGE Identifier String String {
00605     free ($2);
00606     free ($3);
00607     free ($4);
00608   }
00609 ;
00610 
00611 CONNPAIR_Line:
00612   t_CONNPAIR String String {
00613     free ($2);
00614     free ($3);
00615   }
00616 ;
00617 
00618 %%
00619 
00620 int mdl_error (const char * error) {
00621   fprintf (stderr, "line %d: %s\n", mdl_lineno, error);
00622   return 0;
00623 }