Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
parse_csv.y
Go to the documentation of this file.
1 /* -*-c++-*- */
2 
3 %{
4 /*
5  * parse_csv.y - parser for CSV files
6  *
7  * Copyright (C) 2007 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 
36 #define YYERROR_VERBOSE 42
37 #define YYDEBUG 1
38 #define YYMAXDEPTH 1000000
39 
40 #include "logging.h"
41 #include "complex.h"
42 #include "object.h"
43 #include "vector.h"
44 #include "dataset.h"
45 #include "strlist.h"
46 #include "check_csv.h"
47 
48 using namespace qucs;
49 
50 %}
51 
52 %name-prefix="csv_"
53 
54 %token InvalidCharacter
55 %token Float
56 %token Identifier
57 %token Eol
58 
59 %union {
60  char * ident;
61  double f;
62  qucs::vector * v;
63  qucs::strlist * list;
64 }
65 
66 %type <list> HeaderList HeaderLine
67 %type <ident> Identifier Header
68 %type <f> Float
69 %type <v> DataLine DataSet DataList
70 
71 %%
72 
73 Input:
74  HeaderLine DataSet { /* describes a valid csv */
75  csv_header = $1;
76  csv_vector = $2;
77  }
78  | DataSet {
79  csv_vector = $1;
80  }
81 ;
82 
83 Header:
84  '"' Identifier '"' {
85  $$ = strdup ($2);
86  }
88  $$ = strdup ($1);
89  }
90 ;
91 
92 HeaderList: /* nothing */ { $$ = NULL; }
93  | Header HeaderList {
94  if ($2 == NULL) $2 = new strlist ();
95  $2->add ($1);
96  $$ = $2;
97  free ($1);
98  }
99 ;
100 
101 HeaderLine: /* header line */
102  HeaderList Eol {
103  $$ = $1;
104  }
105  | Eol HeaderLine { /* skip this line */
106  $$ = $2;
107  }
108 ;
109 
110 DataSet: /* nothing */ { $$ = NULL; }
111  | DataLine Eol DataSet { /* append vector lines */
112  $1->setNext ($3);
113  $$ = $1;
114  }
115  | DataLine { /* last line, no trailing end-of-line */
116  $$ = $1;
117  }
118  | Eol DataSet { /* skip this line */
119  $$ = $2;
120  }
121 ;
122 
124 ;
125 
126 DataList: /* nothing */ { $$ = NULL; }
128  if ($2 == NULL) $2 = new vector ();
129  $2->add ($1);
130  $$ = $2;
131  }
132 ;
133 
134 %%
135 
136 int csv_error (const char * error) {
137  logprint (LOG_ERROR, "line %d: %s\n", csv_lineno, error);
138  return 0;
139 }
name
Definition: parse_mdl.y:352
name prefix
Definition: parse_csv.y:52
Identifier
Definition: parse_csv.y:87
qucs::strlist * csv_header
Definition: check_csv.cpp:48
DataLine Eol DataSet
Definition: parse_csv.y:111
RLC_Device Node Node Value MODEL_Ident PairList Eol
Definition: parse_spice.y:225
free($1)
< INITIAL >< INITIAL >< INITIAL >< INITIAL > return InvalidCharacter
Definition: scan_netlist.l:698
Float
Definition: parse_citi.y:213
Float DataList
Definition: parse_csv.y:127
int csv_lineno
Header HeaderList
Definition: parse_csv.y:93
v
Definition: parse_zvr.y:141
qucs::vector * csv_vector
Definition: check_csv.cpp:49
DataLine
Definition: parse_csv.y:115
vcd scopes ident
Definition: parse_vcd.y:124
Eol HeaderLine
Definition: parse_csv.y:105
#define LOG_ERROR
Definition: logging.h:28
int csv_error(const char *)
Definition: parse_csv.y:136
void logprint(int level, const char *format,...)
Definition: logging.c:37