FreeCAD

Форк
0
/
QuantityParser.l 
248 строк · 13.6 Кб
1
%{
2
/***************************************************************************
3
 *   Copyright (c) 2013 Jürgen Riegel <juergen.riegel@web.de>              *
4
 *                                                                         *
5
 *   This library is free software; you can redistribute it and/or         *
6
 *   modify it under the terms of the GNU Library General Public           *
7
 *   License as published by the Free Software Foundation; either          *
8
 *   version 2 of the License, or (at your option) any later version.      *
9
 *                                                                         *
10
 *   This library  is distributed in the hope that it will be useful,      *
11
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13
 *   GNU Library General Public License for more details.                  *
14
 *                                                                         *
15
 *   You should have received a copy of the GNU Library General Public     *
16
 *   License along with this library; see the file COPYING.LIB. If not,    *
17
 *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
18
 *   Suite 330, Boston, MA  02111-1307, USA                                *
19
 *                                                                         *
20
 ***************************************************************************/
21

22
/* Lexer for the FreeCAD  Units language   */
23

24
/* use this file to generate the file 'QuantityLexer.c' using the program flex
25
 * the command for this operation is:
26
 * flex --outfile=QuantityLexer.c QuantityParser.l
27
 * (flex for Windows is available here:
28
 *  https://sourceforge.net/projects/winflexbison/
29
 *  (you must then change 'flex' to 'win_flex' in the command)) */
30

31
/* This disables inclusion of unistd.h, which is not available under Visual C++
32
 * on Win32. The C++ scanner uses STL streams instead. */
33
#define YY_NO_UNISTD_H
34

35
%}
36

37
/*** Flex Declarations and Options ***/
38

39

40
/* the manual says "somewhat more optimized" */
41
%option batch
42
%option never-interactive
43

44

45
/* no support for include files is planned */
46
%option noyywrap nounput
47

48
DIGIT    [0-9]
49
ID       [a-z][a-z0-9]*
50
EXPO     [eE][-+]?[0-9]+
51
DGRP     '\.'[0-9][0-9][0-9]
52
CGRP     '\,'[0-9][0-9][0-9]
53

54
%x C_COMMENT
55

56
%% /*** Filter language Part ***/
57

58
"\["            { BEGIN(C_COMMENT); }
59
<C_COMMENT>"\]" { BEGIN(INITIAL); }
60
<C_COMMENT>.    { ;}
61

62

63
[ \t]       ;
64
[\n]+       ;
65

66
[+()=/*^]  { return *yytext; }
67

68
"-"                                                return MINUSSIGN;
69
"\xe2\x88\x92"                                     return MINUSSIGN;
70

71
"nm"       yylval = Quantity::NanoMetre;           return UNIT; // nano meter
72
"um"       yylval = Quantity::MicroMetre;          return UNIT; // micro meter
73
"\xC2\xB5m"    yylval = Quantity::MicroMetre;          return UNIT; // micro meter    (greek micro in UTF8)
74
"mm"       yylval = Quantity::MilliMetre;          return UNIT; // milli meter    (internal standard length)
75
"cm"       yylval = Quantity::CentiMetre;          return UNIT; // centi meter
76
"dm"       yylval = Quantity::DeciMetre;           return UNIT; // deci meter
77
"m"        yylval = Quantity::Metre;               return UNIT; // Metre
78
"km"       yylval = Quantity::KiloMetre;           return UNIT; // kilo meter
79

80
"l"        yylval = Quantity::Liter;               return UNIT; // Liter  (dm^3)
81
"ml"       yylval = Quantity::MilliLiter;          return UNIT; // milli Liter
82

83
"Hz"       yylval = Quantity::Hertz;               return UNIT; // Hertz
84
"kHz"      yylval = Quantity::KiloHertz;           return UNIT; // kilo Hertz
85
"MHz"      yylval = Quantity::MegaHertz;           return UNIT; // mega Hertz
86
"GHz"      yylval = Quantity::GigaHertz;           return UNIT; // giga Hertz
87
"THz"      yylval = Quantity::TeraHertz;           return UNIT; // tera Hertz
88

89
"ug"       yylval = Quantity::MicroGram;           return UNIT; // micro gram
90
"\xC2\xB5g"    yylval = Quantity::MicroGram;           return UNIT; // micro gram
91
"mg"       yylval = Quantity::MilliGram;           return UNIT; // milli gram
92
"g"        yylval = Quantity::Gram;                return UNIT; // gram
93
"kg"       yylval = Quantity::KiloGram;            return UNIT; // kilo gram      (internal standard for mass)
94
"t"        yylval = Quantity::Ton;                 return UNIT; // Metric Tonne
95

96
"s"        yylval = Quantity::Second;              return UNIT; // second         (internal standard time)
97
"min"      yylval = Quantity::Minute;              return UNIT; // minute
98
"h"        yylval = Quantity::Hour;                return UNIT; // hour
99

100
"A"        yylval = Quantity::Ampere;              return UNIT; // Ampere         (internal standard electric current)
101
"mA"       yylval = Quantity::MilliAmpere;         return UNIT; // milli Ampere
102
"kA"       yylval = Quantity::KiloAmpere;          return UNIT; // kilo Ampere
103
"MA"       yylval = Quantity::MegaAmpere;          return UNIT; // mega Ampere
104

105
"K"        yylval = Quantity::Kelvin;              return UNIT; // Kelvin         (internal standard thermodynamic temperature)
106
"mK"       yylval = Quantity::MilliKelvin;         return UNIT; // milli Kelvin
107
"\xC2\xB5K"    yylval = Quantity::MicroKelvin;         return UNIT; // micro Kelvin
108
"uK"       yylval = Quantity::MicroKelvin;         return UNIT; // micro Kelvin
109

110
"mol"      yylval = Quantity::Mole;                return UNIT; // Mole           (internal standard amount of substance)
111
"mmol"     yylval = Quantity::MilliMole;           return UNIT; // Milli Mole
112

113
"cd"       yylval = Quantity::Candela;             return UNIT; // Candela        (internal standard luminous intensity)
114

115
"in"       yylval = Quantity::Inch;                return UNIT; // inch
116
"\""       yylval = Quantity::Inch;                return UNIT; // inch
117
"ft"       yylval = Quantity::Foot;                return UNIT; // foot
118
"'"        yylval = Quantity::Foot;                return UNIT; // foot
119
"thou"     yylval = Quantity::Thou;                return UNIT; // thou (in/1000)
120
"mil"      yylval = Quantity::Thou;                return UNIT; // mil  (the thou in US)
121
"yd"       yylval = Quantity::Yard;                return UNIT; // yard
122
"mi"       yylval = Quantity::Mile;                return UNIT; // mile
123

124
"mph"      yylval = Quantity::MilePerHour;         return UNIT; // mile per hour
125
"sqft"     yylval = Quantity::SquareFoot;          return UNIT; // square foot
126
"cft"      yylval = Quantity::CubicFoot;           return UNIT; // cubic foot
127

128
"lb"       yylval = Quantity::Pound;               return UNIT; // pound
129
"lbm"      yylval = Quantity::Pound;               return UNIT; // pound
130
"oz"       yylval = Quantity::Ounce;               return UNIT; // ounce
131
"st"       yylval = Quantity::Stone;               return UNIT; // Stone
132
"cwt"      yylval = Quantity::Hundredweights;      return UNIT; // hundredweights
133

134
"lbf"      yylval = Quantity::PoundForce;          return UNIT; // pound
135

136
"N"        yylval = Quantity::Newton;              return UNIT; // Newton (kg*m/s^2)
137
"mN"       yylval = Quantity::MilliNewton;         return UNIT; // milli Newton
138
"kN"       yylval = Quantity::KiloNewton;          return UNIT; // kilo Newton
139
"MN"       yylval = Quantity::MegaNewton;          return UNIT; // mega Newton
140

141
"Pa"       yylval = Quantity::Pascal;              return UNIT; // Pascal (kg/m/s^2 or N/m^2)
142
"kPa"      yylval = Quantity::KiloPascal;          return UNIT; // kilo Pascal
143
"MPa"      yylval = Quantity::MegaPascal;          return UNIT; // mega Pascal
144
"GPa"      yylval = Quantity::GigaPascal;          return UNIT; // giga Pascal
145

146
"bar"      yylval = Quantity::Bar;                 return UNIT; // 1 bar = 100 kPa
147
"mbar"     yylval = Quantity::MilliBar;            return UNIT; // milli Bar
148

149
"Torr"     yylval = Quantity::Torr;                return UNIT; // portion of Pascal ( 101325/760 )
150
"mTorr"    yylval = Quantity::mTorr;               return UNIT; //
151
"uTorr"    yylval = Quantity::yTorr;               return UNIT; //
152
"\xC2\xB5Torr"    yylval = Quantity::yTorr;               return UNIT; //
153

154
"psi"      yylval = Quantity::PSI;                 return UNIT; // pounds/in^2
155
"ksi"      yylval = Quantity::KSI;                 return UNIT; // 1000 x pounds/in^2
156
"Mpsi"     yylval = Quantity::MPSI;                return UNIT; // 1000 ksi
157

158
"W"        yylval = Quantity::Watt;                return UNIT; // Watt (kg*m^2/s^3)
159
"mW"       yylval = Quantity::MilliWatt;           return UNIT; // milli Watt
160
"kW"       yylval = Quantity::KiloWatt;            return UNIT; // kilo Watt
161
"VA"       yylval = Quantity::VoltAmpere;          return UNIT; // VoltAmpere (kg*m^2/s^3)
162

163
"V"        yylval = Quantity::Volt;                return UNIT; // Volt (kg*m^2/A/s^3)
164
"kV"       yylval = Quantity::KiloVolt;            return UNIT; // kilo Volt
165
"mV"       yylval = Quantity::MilliVolt;           return UNIT; // milli Volt
166

167
"MS"       yylval = Quantity::MegaSiemens;         return UNIT; // mega Siemens
168
"kS"       yylval = Quantity::KiloSiemens;         return UNIT; // kilo Siemens
169
"S"        yylval = Quantity::Siemens;             return UNIT; // Siemens (A^2*s^3/kg/m^2)
170
"mS"       yylval = Quantity::MilliSiemens;        return UNIT; // milli Siemens
171
"\xC2\xB5S"     yylval = Quantity::MicroSiemens;   return UNIT; // micro Siemens
172
"uS"       yylval = Quantity::MicroSiemens;        return UNIT; // micro Siemens
173

174
"Ohm"      yylval = Quantity::Ohm;                 return UNIT; // Ohm (kg*m^2/A^2/s^3)
175
"kOhm"     yylval = Quantity::KiloOhm;             return UNIT; // kilo Ohm
176
"MOhm"     yylval = Quantity::MegaOhm;             return UNIT; // mega Ohm
177

178
"C"        yylval = Quantity::Coulomb;             return UNIT; // Coulomb (A*s)
179

180
"T"        yylval = Quantity::Tesla;               return UNIT; // Tesla (kg/s^2/A)
181
"G"        yylval = Quantity::Gauss;               return UNIT; // Gauss (1 G = 1e-4 T)
182

183
"Wb"       yylval = Quantity::Weber;               return UNIT; // Weber (kg*m^2/s^2/A)
184

185
"F"        yylval = Quantity::Farad;               return UNIT; // Farad (s^4*A^2/m^2/kg)
186
"mF"       yylval = Quantity::MilliFarad;          return UNIT; // milli Farad
187
"\xC2\xB5F"    yylval = Quantity::MicroFarad;      return UNIT; // micro Farad
188
"uF"       yylval = Quantity::MicroFarad;          return UNIT; // micro Farad
189
"nF"       yylval = Quantity::NanoFarad;           return UNIT; // nano Farad
190
"pF"       yylval = Quantity::PicoFarad;           return UNIT; // pico Farad
191

192
"H"        yylval = Quantity::Henry;               return UNIT; // Henry (kg*m^2/s^2/A^2)
193
"mH"       yylval = Quantity::MilliHenry;          return UNIT; // milli Henry
194
"\xC2\xB5H"    yylval = Quantity::MicroHenry;      return UNIT; // micro Henry
195
"uH"       yylval = Quantity::MicroHenry;          return UNIT; // micro Henry
196
"nH"       yylval = Quantity::NanoHenry;           return UNIT; // nano Henry
197

198
"J"        yylval = Quantity::Joule;               return UNIT; // Joule (kg*m^2/s^2)
199
"mJ"       yylval = Quantity::MilliJoule;          return UNIT; // milli Joule
200
"kJ"       yylval = Quantity::KiloJoule;           return UNIT; // kilo Joule
201
"Nm"       yylval = Quantity::NewtonMeter;         return UNIT; // N*m = Joule
202
"VAs"      yylval = Quantity::VoltAmpereSecond;    return UNIT; // V*A*s = Joule
203
"CV"       yylval = Quantity::WattSecond;          return UNIT; //
204
"Ws"       yylval = Quantity::WattSecond;          return UNIT; // W*s = Joule
205
"kWh"      yylval = Quantity::KiloWattHour;        return UNIT; // 1 kWh = 3.6e6 J
206
"eV"       yylval = Quantity::ElectronVolt;        return UNIT; // 1 eV = 1.602176634e-19 J
207
"keV"      yylval = Quantity::KiloElectronVolt;    return UNIT;
208
"MeV"      yylval = Quantity::MegaElectronVolt;    return UNIT;
209
"cal"      yylval = Quantity::Calorie;             return UNIT; // 1 cal = 4.1868 J
210
"kcal"     yylval = Quantity::KiloCalorie;         return UNIT;
211

212
"\xC2\xB0" yylval = Quantity::Degree;              return UNIT; // degree         (internal standard angle)
213
"deg"      yylval = Quantity::Degree;              return UNIT; // degree         (internal standard angle)
214
"rad"      yylval = Quantity::Radian;              return UNIT; // radian
215
"gon"      yylval = Quantity::Gon;                 return UNIT; // gon
216
"M"        yylval = Quantity::AngMinute;           return UNIT; // minute(Angular)
217
"\xE2\x80\xB2" yylval = Quantity::AngMinute;       return UNIT; // minute(Angular)
218
"AS"       yylval = Quantity::AngSecond;           return UNIT; // second(Angular)
219
"\xE2\x80\xB3" yylval = Quantity::AngSecond;       return UNIT; // second(Angular)
220

221
"1"        yylval = Quantity(1.0);                 return ONE;
222
{DIGIT}+"."?{DIGIT}*{EXPO}?                         {  yylval = Quantity(num_change(yytext,'.',','));return NUM;  }
223
"."?{DIGIT}+{EXPO}?                                 {  yylval = Quantity(num_change(yytext,'.',','));return NUM;  }
224
{DIGIT}+","?{DIGIT}*{EXPO}?                         {  yylval = Quantity(num_change(yytext,',','.'));return NUM;  }
225
","?{DIGIT}+{EXPO}?                                 {  yylval = Quantity(num_change(yytext,',','.'));return NUM;  }
226

227

228
"pi"                   {yylval = Quantity(M_PI)          ; return NUM;} // constant pi
229
"e"                    {yylval = Quantity(M_E)           ; return NUM;} // constant e
230

231
"acos"                 return ACOS;
232
"asin"                 return ASIN;
233
"atan"                 return ATAN;
234
"atan2"                return ATAN2;
235
"cos"                  return COS;
236
"exp"                  return EXP;
237
"abs"                  return ABS;
238
"mod"                  return MOD;
239
"log"                  return LOG;
240
"log10"                return LOG10;
241
"pow"                  return POW;
242
"sin"                  return SIN;
243
"sinh"                 return SINH;
244
"tan"                  return TAN;
245
"tanh"                 return TANH;
246
"sqrt"                 return SQRT;
247

248
.                      return *yytext;
249

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.