Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
scan_citi.l
Go to the documentation of this file.
1 /* -*-c-*- */
2 
3 %{
4 /*
5  * scan_citi.l - scanner for CITIfiles
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 #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_citi.h"
51 #include "tokens_citi.h"
52 
53 using namespace qucs;
54 
55 %}
56 
57 WS [ \t\n\r]
58 ID [a-zA-Z_][a-zA-Z0-9_\.]*
59 DIGIT [0-9]
60 EXPONENT [Ee][+-]?{DIGIT}+
61 INT [+-]?{DIGIT}+
62 FLOAT1 [+-]?{DIGIT}+{EXPONENT}
63 FLOAT2 [+-]?{DIGIT}*"."{DIGIT}+({EXPONENT})?
64 SPACE [ \t]
65 EOL \r?\n
66 
67 %x COMMENTS FLOATS LISTS DATAS VALUES
68 %option yylineno noyywrap nounput prefix="citi_"
69 
70 %%
71 
72 <INITIAL,FLOATS,LISTS>{EOL}+ { /* detect end of line */ return Eol; }
73 
74 <*>{SPACE} /* skip spaces */
75 
76 <INITIAL,DATAS>{INT} { /* identify integer */
77  citi_lval.d = strtol (citi_text, NULL, 10);
78  return Integer;
79  }
80 
81 <INITIAL>[a-zA-Z]"."{DIGIT}+"."{DIGIT}+ {
82  return Version;
83  }
84 
85 <INITIAL,DATAS>("RI"|"MAG"|"MAGANGLE"|"DBANGLE") {
86  citi_lval.ident = strdup (citi_text);
87  return VarType;
88  }
89 
90 <INITIAL>^"CITIFILE" { return CITIFILE; }
91 <INITIAL>^"VAR" { return VAR; }
92 <INITIAL>^"DATA" { BEGIN(DATAS); return DATA; }
93 <INITIAL>^"NAME" { return NAME; }
94 <INITIAL>^"BEGIN" { BEGIN(FLOATS); return Begin; }
95 <INITIAL>^"CONSTANT" { BEGIN(VALUES); return CONSTANT; }
96 <INITIAL>^"COMMENT" { BEGIN(COMMENTS); }
97 
98 <INITIAL>^"SEG_LIST_BEGIN" { BEGIN(LISTS); return SegListBegin; }
99 <INITIAL>^"VAR_LIST_BEGIN" { BEGIN(LISTS); return VarListBegin; }
100 <LISTS>^"SEG_LIST_END" { BEGIN(INITIAL); return SegListEnd; }
101 <LISTS>^"VAR_LIST_END" { BEGIN(INITIAL); return VarListEnd; }
102 <LISTS>^"SEG" { return SEG; }
103 
104 <INITIAL,DATAS,VALUES>{ID} { /* identify identifier */
105  citi_lval.ident = strdup (citi_text);
106  return Identifier;
107  }
108 
109 <FLOATS,LISTS,VALUES>({FLOAT1}|{FLOAT2}|{INT}) { /* identify float */
110  citi_lval.f = strtod (citi_text, NULL);
111  return Float;
112  }
113 
114 <VALUES>{EOL}+ { BEGIN(INITIAL); return Eol; }
115 
116 <DATAS>"," { /* pass the ',' to the parser */ return ','; }
117 <DATAS>"[" { /* pass the '[' to the parser */ return '['; }
118 <DATAS>"]" { /* pass the ']' to the parser */ BEGIN(INITIAL); return ']'; }
119 <DATAS>{EOL}+ { BEGIN(INITIAL); return Eol; }
120 
121 <FLOATS>"," { /* pass the ',' to the parser */ return ','; }
122 
123 <FLOATS>^"END" { BEGIN(INITIAL); return End; }
124 
125 <INITIAL>^"#" { /* leave these characters */
126  BEGIN(COMMENTS);
127  }
128 
129 <COMMENTS>. { /* skip any character in here */ }
130 <COMMENTS>{EOL}+ { BEGIN(INITIAL); /* skipping ends here */ }
131 
132 <*>. { /* any other character in invalid */
134  "line %d: syntax error, unrecognized character: `%s'\n",
135  citi_lineno, citi_text);
136  return InvalidCharacter;
137  }
138 
139 %%
#define INT(con)
Definition: evaluate.cpp:68
int citi_lineno
Definition: parse_citi.y:53
Identifier
Definition: parse_csv.y:87
t
Definition: parse_vcd.y:290
n
Definition: parse_citi.y:147
r
Definition: parse_mdl.y:515
RLC_Device Node Node Value MODEL_Ident PairList Eol
Definition: parse_spice.y:225
< INITIAL >< INITIAL >< INITIAL >< INITIAL > return InvalidCharacter
Definition: scan_netlist.l:698
#define Z_(r, c)
Definition: hbsolver.cpp:689
x
Definition: parse_mdl.y:498
Float
Definition: parse_citi.y:213
name prefix
Definition: parse_spice.y:131
WS[\t\n\r] SIMPLEID *[a-zA-Z_][a-zA-Z0-9_] POSTID[a-zA-Z0-9_] ID
Definition: scan_netlist.l:581
#define LOG_ERROR
Definition: logging.h:28
void logprint(int level, const char *format,...)
Definition: logging.c:37
#define Z0
Wave impedance in vacuum ( )
Definition: constants.h:53