Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
scan_csv.l
Go to the documentation of this file.
1 /* -*-c-*- */
2 
3 %{
4 /*
5  * scan_csv.l - scanner 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 #include <ctype.h>
36 
37 #ifdef __MINGW32__
38 #include <io.h>
39 #endif
40 
41 #ifdef HAVE_UNISTD_H
42 #include <unistd.h>
43 #endif
44 
45 #include "logging.h"
46 #include "complex.h"
47 #include "object.h"
48 #include "vector.h"
49 #include "dataset.h"
50 #include "check_csv.h"
51 #include "tokens_csv.h"
52 
53 using namespace qucs;
54 
55 %}
56 
57 WS [ \t\n\r]
58 SEP [;,]
59 ARRAY \[[0-9]+,[0-9]+\]
60 ID1 [a-zA-Z_][a-zA-Z0-9_.]*{ARRAY}?
61 ID2 [^\"\n\r]*
62 DIGIT [0-9]
63 EXPONENT [Ee][+-]?{DIGIT}+
64 INT [+-]?{DIGIT}+
65 FLOAT1 [+-]?{DIGIT}+{EXPONENT}
66 FLOAT2 [+-]?{DIGIT}*"."{DIGIT}+({EXPONENT})?
67 SPACE [ \t]
68 
69 %x COMMENT IDENT
70 %option yylineno noyywrap nounput prefix="csv_"
71 
72 %%
73 
74 <INITIAL>\" { BEGIN(IDENT); /* pass the '"' to the parser */ return '"'; }
75 <INITIAL>\r?\n { /* detect end of line */ return Eol; }
76 
77 <INITIAL>{ID1} { /* identify identifier */
78  csv_lval.ident = strdup (csv_text);
79  return Identifier;
80  }
81 
82 <IDENT>{ID2} { /* identify identifier */
83  csv_lval.ident = strdup (csv_text);
84  return Identifier;
85  }
86 
87 <IDENT>\" { BEGIN(INITIAL); return '"'; }
88 <IDENT>\r?\n { BEGIN(INITIAL); return Eol; }
89 
90 <*>({SPACE}|{SEP}) /* skip spaces and separators */
91 
92 <INITIAL>({FLOAT1}|{FLOAT2}|{INT}) { /* identify float */
93  csv_lval.f = strtod (csv_text, NULL);
94  return Float;
95  }
96 
97 <INITIAL>. { /* any other character in invalid */
98  logprint (LOG_ERROR,
99  "line %d: syntax error, unrecognized character: `%s'\n",
100  csv_lineno, csv_text);
101  return InvalidCharacter;
102  }
103 
104 <COMMENT>. { /* skip any character in here */ }
105 <COMMENT>\r?\n { BEGIN(INITIAL); /* skipping ends here */ return Eol; }
106 
107 %%
r
Definition: parse_mdl.y:515
WS[\t\n\r] SEP[;,] ARRAY[[0-9]+, [0-9]+\] ID1 *[a-zA-Z_][a-zA-Z0-9_.]< INITIAL > r n
Definition: scan_csv.l:682
#define Z_(r, c)
Definition: hbsolver.cpp:689
#define Z0
Wave impedance in vacuum ( )
Definition: constants.h:53