-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser.l
223 lines (188 loc) · 6.95 KB
/
parser.l
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
%option noyywrap yylineno
%{
#include <stdio.h>
#include <stdlib.h>
#include "parser.tab.h"
#include "log.h"
extern int yyparse();
extern void yyerror();
%}
%s PRE_INPUT
WS [ \t]
EOL "\n"
//End of statement ,used in prefix handling
EOS ({WS}|{EOL})
NUM [0-9]
alph [a-z]
ALPH [A-Z]
DEC [+-]?({NUM}+"."?{NUM}*|{NUM}*"."{NUM}+)
ELM_ID ({NUM}+|{alph}+|{ALPH}+)
NODE_ID {NUM}+
//Prefixes
FEMNTO f
PICO p
NANO n
MICRO u
MILLI m
CENTI c
KILO [kK]
MEGA M
GIGA G
TERA T
PETA P
PREFIX ({FEMNTO}|{PICO}|{NANO}|{MICRO}|{MILLI}|{CENTI}|{KILO}|{MEGA}|{GIGA}|{TERA}|{PETA})
//Group Identifier
G_ID [Gg]"2"
//End token
END ^".END"
//Simulator tyoe token
DC ^".DC"
TRAN ^".TRAN"
AC ^".AC"
//Source Type
DC_S "DC"
AC_S "AC"
SINE_S "SINE"
PULSE_S "PULSE"
RAMP_S "RAMP"
STEP_S "STEP"
//Output tokens
PLOT ^".PLOT"
ELEMENT ("I"{ELM_ID}|"V"{ELM_ID}|"E"{ELM_ID}|"F"{ELM_ID}|"G"{ELM_ID}|"H"{ELM_ID}|"R"{ELM_ID}|"L"{ELM_ID}|"C"{ELM_ID})
%%
"%".*$ {/*Comment*/}
{WS} {/*Ignore*/}
"(" {
return '(';
}
")" {
return ')';
}
"\n" {
return '\n';
}
^"R"{ELM_ID}/{WS} {
yylval.sv = (char *)malloc(yyleng * sizeof(char));
strcpy(yylval.sv, yytext);
return RE_T;
}
^"C"{ELM_ID}/{WS} {
yylval.sv = (char *)malloc(yyleng * sizeof(char));
strcpy(yylval.sv, yytext);
return CE_T;
}
^"L"{ELM_ID}/{WS} {
yylval.sv = (char *)malloc(yyleng * sizeof(char));
strcpy(yylval.sv, yytext);
return LE_T;
}
^"E"{ELM_ID}/{WS} {
yylval.sv = (char *)malloc(yyleng * sizeof(char));
strcpy(yylval.sv, yytext);
return EE_T;
}
^"F"{ELM_ID}/{WS} {
yylval.sv = (char *)malloc(yyleng * sizeof(char));
strcpy(yylval.sv, yytext);
return FE_T;
}
^"G"{ELM_ID}/{WS} {
yylval.sv = (char *)malloc(yyleng * sizeof(char));
strcpy(yylval.sv, yytext);
return GE_T;
}
^"H"{ELM_ID}/{WS} {
yylval.sv = (char *)malloc(yyleng * sizeof(char));
strcpy(yylval.sv, yytext);
return HE_T;
}
^"V"{ELM_ID}/{WS} {
yylval.sv = (char *)malloc(yyleng * sizeof(char));
strcpy(yylval.sv, yytext);
return VE_T;
}
^"I"{ELM_ID}/{WS} {
yylval.sv = (char *)malloc(yyleng * sizeof(char));
strcpy(yylval.sv, yytext);
return IE_T;
}
{ELEMENT} {
yylval.sv = (char *)malloc(yyleng * sizeof(char));
strcpy(yylval.sv, yytext);
return ELM_T;
}
{NUM}+ {
yylval.iv = atoi(yytext);
return INT_T;
}
{DEC} {
yylval.dv = atof(yytext);
return DEC_T;
}
{DEC}/{PREFIX} {
yylval.dv = atof(yytext);
BEGIN PRE_INPUT;
return DEC_T;
}
<PRE_INPUT>{PREFIX} {
switch(*yytext){
case 'f': yylval.dv = 1e-15; break;
case 'p': yylval.dv = 1e-12; break;
case 'n': yylval.dv = 1e-9; break;
case 'u': yylval.dv = 1e-6; break;
case 'm': yylval.dv = 1e-3; break;
case 'c': yylval.dv = 1e-2; break;
case 'k': yylval.dv = 1e+3; break;
case 'K': yylval.dv = 1e+3; break;
case 'M': yylval.dv = 1e+6; break;
case 'G': yylval.dv = 1e+9; break;
case 'T': yylval.dv = 1e+12; break;
case 'P': yylval.dv = 1e+15; break;
}
BEGIN INITIAL;
return PREF_T;
}
{G_ID} {
return G2_T;
}
{DC_S} {
return DC_T;
}
{AC_S} {
return AC_T;
}
{STEP_S} {
return STEP_T;
}
{RAMP_S} {
return RAMP_T;
}
{SINE_S} {
return SINE_T;
}
{PULSE_S} {
return PULSE_T;
}
{DC_S} {
return DC_T;
}
{DC} {
return DS_T;
}
{TRAN} {
return TS_T;
}
{AC} {
return AS_T;
}
{PLOT} {
return PLT_T;
}
{END} {
return END_T;
}
"Ic=" {
return IC_T;
}
. {yyerror("ERROR!, %c in line %d", *yytext, yylineno);}
%%