Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
parse_zvr.y
Go to the documentation of this file.
1 /* -*-c++-*- */
2 
3 %{
4 /*
5  * parse_zvr.y - parser for a ZVR data file
6  *
7  * Copyright (C) 2006 Stefan Jahn <stefan@lkcc.org>
8  *
9  * This is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2, or (at your option)
12  * any later version.
13  *
14  * This software is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this package; see the file COPYING. If not, write to
21  * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
22  * Boston, MA 02110-1301, USA.
23  *
24  * $Id$
25  *
26  */
27 
28 #if HAVE_CONFIG_H
29 # include <config.h>
30 #endif
31 
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <string.h>
35 #include <ctype.h>
36 
37 #define YYERROR_VERBOSE 42
38 #define YYDEBUG 1
39 #define YYMAXDEPTH 1000000
40 
41 #define __NOEXTENSIONS__ 1
42 
43 #include "object.h"
44 #include "complex.h"
45 #include "vector.h"
46 #include "check_zvr.h"
47 
48 using namespace qucs;
49 
50 %}
51 
52 %name-prefix="zvr_"
53 
54 %token ZVR
55 %token Version
56 %token Identifier
57 %token Real
58 %token Unit
59 %token DataFMT DataTYP DataIDN
60 %token InvalidCharacter
61 
62 %union {
63  char * ident;
64  double f;
65  struct zvr_data_t * data;
66  struct zvr_header_t * head;
67  struct zvr_vector_t * vec;
68  struct zvr_line_t * line;
69 }
70 
71 %type <ident> DataFMT DataTYP DataIDN DataIdent
72 %type <ident> Identifier Unit Ident
73 %type <f> Real
74 %type <head> BodyStart
75 %type <vec> DataHeader
76 %type <data> Body BodyList
77 %type <line> DataLine DataList
78 
79 %%
80 
81 Input:
82  Header Body BodyList { /* a ZVR file */
83  $2->next = $3;
84  zvr_root = $2;
85  }
86 ;
87 
88 Header:
89  ZVR Version { }
90 ;
91 
92 BodyList: /* nothing */ { $$ = NULL; }
93  | Body BodyList {
94  if ($1) {
95  $1->next = $2;
96  $$ = $1;
97  } else {
98  $$ = $2;
99  }
100  }
101 ;
102 
103 ParaList6:
106  }
107 ;
108 
109 ParaList2:
111  }
112 ;
113 
114 Ident:
115  Identifier | Unit
116 ;
117 
118 BodyStart:
119  ParaList6
120  Real ';' Real ';' Unit ';' Real ';' DataTYP ';' Real
121  ParaList6
122  DataTYP ';' Ident ';' DataFMT ';' Ident ';' Ident ';' Ident
123  ParaList2
124  Ident ';' Ident {
125  $$ = (struct zvr_header_t *) calloc (sizeof (struct zvr_header_t), 1);
126  $$->start = $2;
127  $$->stop = $4;
128  $$->funit = $6;
129  $$->points = (int) $8;
130  $$->zref = $12;
131  $$->d_TYP = $10;
132  $$->d_UNT = $20;
133  $$->d_FMT = $18;
134  }
135 ;
136 
137 Body:
138  BodyStart DataHeader DataList {
139  $$ = (struct zvr_data_t *) calloc (sizeof (struct zvr_data_t), 1);
140  $$->h = $1;
141  $$->v = $2;
142  $$->d = $3;
143  }
144 ;
145 
146 DataList: /* nothing */ { $$ = NULL; }
148  if ($1) {
149  $1->next = $2;
150  $$ = $1;
151  } else {
152  $$ = $2;
153  }
154  }
155 ;
156 
157 DataLine:
158  Real ';' Real {
159  $$ = (struct zvr_line_t *) calloc (sizeof (struct zvr_line_t), 1);
160  $$->d = $1;
161  $$->r = $3;
162  }
163  | Real ';' Real ';' Real {
164  $$ = (struct zvr_line_t *) calloc (sizeof (struct zvr_line_t), 1);
165  $$->d = $1;
166  $$->r = $3;
167  $$->i = $5;
168  }
169 ;
170 
171 DataIdent:
172  DataTYP | DataIDN
173 ;
174 
175 DataHeader:
177  $$ = (struct zvr_vector_t *) calloc (sizeof (struct zvr_vector_t), 1);
178  $$->nf = $1;
179  $$->n1 = $3;
180  $$->vi = new vector ();
181  $$->vd = new vector ();
182  }
183  | Identifier ';' DataIdent ';' DataIdent {
184  $$ = (struct zvr_vector_t *) calloc (sizeof (struct zvr_vector_t), 1);
185  $$->nf = $1;
186  $$->n1 = $3;
187  $$->n2 = $5;
188  $$->vi = new vector ();
189  $$->vd = new vector ();
190  }
191 ;
192 
193 %%
194 
195 int zvr_error (const char * error) {
196  fprintf (stderr, "line %d: %s\n", zvr_lineno, error);
197  return 0;
198 }
int zvr_lineno
DataFMT
Definition: parse_zvr.y:122
name
Definition: parse_mdl.y:352
DataLine DataList
Definition: parse_zvr.y:147
struct zvr_data_t * zvr_root
Definition: check_zvr.cpp:49
DataIdent
Definition: parse_zvr.y:176
DataTYP
Definition: parse_zvr.y:120
< INITIAL >< INITIAL >< INITIAL >< INITIAL > return InvalidCharacter
Definition: scan_netlist.l:698
Body BodyList
Definition: parse_zvr.y:93
int zvr_error(const char *)
Definition: parse_zvr.y:195
name prefix
Definition: parse_zvr.y:52
DataLine
Definition: parse_csv.y:115
List int
Definition: parse_citi.y:183
Real
Definition: parse_zvr.y:120
vcd scopes ident
Definition: parse_vcd.y:124
Unit
Definition: parse_zvr.y:120
Ident
Definition: parse_zvr.y:122
Identifier
Definition: parse_zvr.y:104
Package head
Definition: parse_citi.y:116
line
data
Definition: parse_citi.y:117