Debian Codegraph @

src/Base/Quantity.l

raw
1 %{
2 /* SPDX-License-Identifier: LGPL-2.1-or-later */
3
4 /***************************************************************************
5 * Copyright (c) 2013 Jürgen Riegel <[email protected]> *
6 * *
7 * This library is free software; you can redistribute it and/or *
8 * modify it under the terms of the GNU Library General Public *
9 * License as published by the Free Software Foundation; either *
10 * version 2 of the License, or (at your option) any later version. *
11 * *
12 * This library is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU Library General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU Library General Public *
18 * License along with this library; see the file COPYING.LIB. If not, *
19 * write to the Free Software Foundation, Inc., 59 Temple Place, *
20 * Suite 330, Boston, MA 02111-1307, USA *
21 * *
22 ***************************************************************************/
23
24 /* Lexer for the FreeCAD Units language */
25
26 /* This disables inclusion of unistd.h, which is not available under Visual C++
27 * on Win32. The C++ scanner uses STL streams instead. */
28 #define YY_NO_UNISTD_H
29
30 %}
31
32 /*** Flex Declarations and Options ***/
33
34
35 /* the manual says "somewhat more optimized" */
36 %option batch
37 %option never-interactive
38
39
40 /* no support for include files is planned */
41 %option noyywrap nounput
42
43 DIGIT [0-9]
44 ID [a-z][a-z0-9]*
45 EXPO [eE][-+]?[0-9]+
46 DGRP '\.'[0-9][0-9][0-9]
47 CGRP '\,'[0-9][0-9][0-9]
48
49 %x C_COMMENT
50
51 %% /*** Filter language Part ***/
52
53 "\[" { BEGIN(C_COMMENT); }
54 <C_COMMENT>"\]" { BEGIN(INITIAL); }
55 <C_COMMENT>. { ;}
56
57
58 [ \t] ;
59 [\n]+ ;
60
61 [+()=/*^] return *yytext;
62
63 "-" return MINUSSIGN;
64 "\xe2\x88\x92" return MINUSSIGN;
65
66 "nm" yylval = Quantity::NanoMetre; return UNIT; // nano meter
67 "um" yylval = Quantity::MicroMetre; return UNIT; // micro meter
68 "\xC2\xB5m" yylval = Quantity::MicroMetre; return UNIT; // micro meter (greek micro in UTF8)
69 "mm" yylval = Quantity::MilliMetre; return UNIT; // milli meter (internal standard length)
70 "cm" yylval = Quantity::CentiMetre; return UNIT; // centi meter
71 "dm" yylval = Quantity::DeciMetre; return UNIT; // deci meter
72 "m" yylval = Quantity::Metre; return UNIT; // Metre
73 "km" yylval = Quantity::KiloMetre; return UNIT; // kilo meter
74
75 "l" yylval = Quantity::Liter; return UNIT; // Liter (dm^3)
76 "ml" yylval = Quantity::MilliLiter; return UNIT; // milli Liter
77
78 "Hz" yylval = Quantity::Hertz; return UNIT; // Hertz
79 "kHz" yylval = Quantity::KiloHertz; return UNIT; // kilo Hertz
80 "MHz" yylval = Quantity::MegaHertz; return UNIT; // mega Hertz
81 "GHz" yylval = Quantity::GigaHertz; return UNIT; // giga Hertz
82 "THz" yylval = Quantity::TeraHertz; return UNIT; // tera Hertz
83
84 "ug" yylval = Quantity::MicroGram; return UNIT; // micro gram
85 "\xC2\xB5g" yylval = Quantity::MicroGram; return UNIT; // micro gram
86 "mg" yylval = Quantity::MilliGram; return UNIT; // milli gram
87 "g" yylval = Quantity::Gram; return UNIT; // gram
88 "kg" yylval = Quantity::KiloGram; return UNIT; // kilo gram (internal standard for mass)
89 "t" yylval = Quantity::Ton; return UNIT; // Metric Tonne
90
91 "s" yylval = Quantity::Second; return UNIT; // second (internal standard time)
92 "min" yylval = Quantity::Minute; return UNIT; // minute
93 "h" yylval = Quantity::Hour; return UNIT; // hour
94
95 "A" yylval = Quantity::Ampere; return UNIT; // Ampere (internal standard electric current)
96 "mA" yylval = Quantity::MilliAmpere; return UNIT; // milli Ampere
97 "kA" yylval = Quantity::KiloAmpere; return UNIT; // kilo Ampere
98 "MA" yylval = Quantity::MegaAmpere; return UNIT; // mega Ampere
99
100 "K" yylval = Quantity::Kelvin; return UNIT; // Kelvin (internal standard thermodynamic temperature)
101 "mK" yylval = Quantity::MilliKelvin; return UNIT; // milli Kelvin
102 "\xC2\xB5K" yylval = Quantity::MicroKelvin; return UNIT; // micro Kelvin
103 "uK" yylval = Quantity::MicroKelvin; return UNIT; // micro Kelvin
104
105 "mol" yylval = Quantity::Mole; return UNIT; // Mole (internal standard amount of substance)
106 "mmol" yylval = Quantity::MilliMole; return UNIT; // Milli Mole
107
108 "cd" yylval = Quantity::Candela; return UNIT; // Candela (internal standard luminous intensity)
109
110 "in" yylval = Quantity::Inch; return UNIT; // inch
111 "\"" yylval = Quantity::Inch; return UNIT; // inch
112 "ft" yylval = Quantity::Foot; return UNIT; // foot
113 "'" yylval = Quantity::Foot; return UNIT; // foot
114 "thou" yylval = Quantity::Thou; return UNIT; // thou (in/1000)
115 "mil" yylval = Quantity::Thou; return UNIT; // mil (the thou in US)
116 "yd" yylval = Quantity::Yard; return UNIT; // yard
117 "mi" yylval = Quantity::Mile; return UNIT; // mile
118
119 "mph" yylval = Quantity::MilePerHour; return UNIT; // mile per hour
120 "sqft" yylval = Quantity::SquareFoot; return UNIT; // square foot
121 "cft" yylval = Quantity::CubicFoot; return UNIT; // cubic foot
122
123 "lb" yylval = Quantity::Pound; return UNIT; // pound
124 "lbm" yylval = Quantity::Pound; return UNIT; // pound
125 "oz" yylval = Quantity::Ounce; return UNIT; // ounce
126 "st" yylval = Quantity::Stone; return UNIT; // Stone
127 "cwt" yylval = Quantity::Hundredweights; return UNIT; // hundredweights
128
129 "lbf" yylval = Quantity::PoundForce; return UNIT; // pound
130
131 "N" yylval = Quantity::Newton; return UNIT; // Newton (kg*m/s^2)
132 "mN" yylval = Quantity::MilliNewton; return UNIT; // milli Newton
133 "kN" yylval = Quantity::KiloNewton; return UNIT; // kilo Newton
134 "MN" yylval = Quantity::MegaNewton; return UNIT; // mega Newton
135
136 "Pa" yylval = Quantity::Pascal; return UNIT; // Pascal (kg/m/s^2 or N/m^2)
137 "kPa" yylval = Quantity::KiloPascal; return UNIT; // kilo Pascal
138 "MPa" yylval = Quantity::MegaPascal; return UNIT; // mega Pascal
139 "GPa" yylval = Quantity::GigaPascal; return UNIT; // giga Pascal
140
141 "bar" yylval = Quantity::Bar; return UNIT; // 1 bar = 100 kPa
142 "mbar" yylval = Quantity::MilliBar; return UNIT; // milli Bar
143
144 "Torr" yylval = Quantity::Torr; return UNIT; // portion of Pascal ( 101325/760 )
145 "mTorr" yylval = Quantity::mTorr; return UNIT; //
146 "uTorr" yylval = Quantity::yTorr; return UNIT; //
147 "\xC2\xB5Torr" yylval = Quantity::yTorr; return UNIT; //
148
149 "psi" yylval = Quantity::PSI; return UNIT; // pounds/in^2
150 "ksi" yylval = Quantity::KSI; return UNIT; // 1000 x pounds/in^2
151 "Mpsi" yylval = Quantity::MPSI; return UNIT; // 1000 ksi
152
153 "W" yylval = Quantity::Watt; return UNIT; // Watt (kg*m^2/s^3)
154 "mW" yylval = Quantity::MilliWatt; return UNIT; // milli Watt
155 "kW" yylval = Quantity::KiloWatt; return UNIT; // kilo Watt
156 "VA" yylval = Quantity::VoltAmpere; return UNIT; // VoltAmpere (kg*m^2/s^3)
157
158 "V" yylval = Quantity::Volt; return UNIT; // Volt (kg*m^2/A/s^3)
159 "kV" yylval = Quantity::KiloVolt; return UNIT; // kilo Volt
160 "mV" yylval = Quantity::MilliVolt; return UNIT; // milli Volt
161
162 "MS" yylval = Quantity::MegaSiemens; return UNIT; // mega Siemens
163 "kS" yylval = Quantity::KiloSiemens; return UNIT; // kilo Siemens
164 "S" yylval = Quantity::Siemens; return UNIT; // Siemens (A^2*s^3/kg/m^2)
165 "mS" yylval = Quantity::MilliSiemens; return UNIT; // milli Siemens
166 "\xC2\xB5S" yylval = Quantity::MicroSiemens; return UNIT; // micro Siemens
167 "uS" yylval = Quantity::MicroSiemens; return UNIT; // micro Siemens
168
169 "Ohm" yylval = Quantity::Ohm; return UNIT; // Ohm (kg*m^2/A^2/s^3)
170 "kOhm" yylval = Quantity::KiloOhm; return UNIT; // kilo Ohm
171 "MOhm" yylval = Quantity::MegaOhm; return UNIT; // mega Ohm
172
173 "C" yylval = Quantity::Coulomb; return UNIT; // Coulomb (A*s)
174
175 "T" yylval = Quantity::Tesla; return UNIT; // Tesla (kg/s^2/A)
176 "G" yylval = Quantity::Gauss; return UNIT; // Gauss (1 G = 1e-4 T)
177
178 "Wb" yylval = Quantity::Weber; return UNIT; // Weber (kg*m^2/s^2/A)
179
180 "F" yylval = Quantity::Farad; return UNIT; // Farad (s^4*A^2/m^2/kg)
181 "mF" yylval = Quantity::MilliFarad; return UNIT; // milli Farad
182 "\xC2\xB5F" yylval = Quantity::MicroFarad; return UNIT; // micro Farad
183 "uF" yylval = Quantity::MicroFarad; return UNIT; // micro Farad
184 "nF" yylval = Quantity::NanoFarad; return UNIT; // nano Farad
185 "pF" yylval = Quantity::PicoFarad; return UNIT; // pico Farad
186
187 "H" yylval = Quantity::Henry; return UNIT; // Henry (kg*m^2/s^2/A^2)
188 "mH" yylval = Quantity::MilliHenry; return UNIT; // milli Henry
189 "\xC2\xB5H" yylval = Quantity::MicroHenry; return UNIT; // micro Henry
190 "uH" yylval = Quantity::MicroHenry; return UNIT; // micro Henry
191 "nH" yylval = Quantity::NanoHenry; return UNIT; // nano Henry
192
193 "J" yylval = Quantity::Joule; return UNIT; // Joule (kg*m^2/s^2)
194 "mJ" yylval = Quantity::MilliJoule; return UNIT; // milli Joule
195 "kJ" yylval = Quantity::KiloJoule; return UNIT; // kilo Joule
196 "Nm" yylval = Quantity::NewtonMeter; return UNIT; // N*m = Joule
197 "VAs" yylval = Quantity::VoltAmpereSecond; return UNIT; // V*A*s = Joule
198 "CV" yylval = Quantity::WattSecond; return UNIT; //
199 "Ws" yylval = Quantity::WattSecond; return UNIT; // W*s = Joule
200 "kWh" yylval = Quantity::KiloWattHour; return UNIT; // 1 kWh = 3.6e6 J
201 "eV" yylval = Quantity::ElectronVolt; return UNIT; // 1 eV = 1.602176634e-19 J
202 "keV" yylval = Quantity::KiloElectronVolt; return UNIT;
203 "MeV" yylval = Quantity::MegaElectronVolt; return UNIT;
204 "cal" yylval = Quantity::Calorie; return UNIT; // 1 cal = 4.1868 J
205 "kcal" yylval = Quantity::KiloCalorie; return UNIT;
206
207 "\xC2\xB0" yylval = Quantity::Degree; return UNIT; // degree (internal standard angle)
208 "deg" yylval = Quantity::Degree; return UNIT; // degree (internal standard angle)
209 "rad" yylval = Quantity::Radian; return UNIT; // radian
210 "gon" yylval = Quantity::Gon; return UNIT; // gon
211 "M" yylval = Quantity::AngMinute; return UNIT; // minute(Angular)
212 "\xE2\x80\xB2" yylval = Quantity::AngMinute; return UNIT; // minute(Angular)
213 "AS" yylval = Quantity::AngSecond; return UNIT; // second(Angular)
214 "\xE2\x80\xB3" yylval = Quantity::AngSecond; return UNIT; // second(Angular)
215
216 "1" yylval = Quantity(1.0); return ONE;
217 {DIGIT}+"."?{DIGIT}*{EXPO}? yylval = Quantity(num_change(yytext,'.',',')); return NUM;
218 "."?{DIGIT}+{EXPO}? yylval = Quantity(num_change(yytext,'.',',')); return NUM;
219 {DIGIT}+","?{DIGIT}*{EXPO}? yylval = Quantity(num_change(yytext,',','.')); return NUM;
220 ","?{DIGIT}+{EXPO}? yylval = Quantity(num_change(yytext,',','.')); return NUM;
221
222 "pi" yylval = Quantity(std::numbers::pi); return NUM; // constant pi
223 "e" yylval = Quantity(std::numbers::e); return NUM; // constant e
224
225 "acos" return ACOS;
226 "asin" return ASIN;
227 "atan" return ATAN;
228 "atan2" return ATAN2;
229 "cos" return COS;
230 "exp" return EXP;
231 "abs" return ABS;
232 "mod" return MOD;
233 "log" return LOG;
234 "log10" return LOG10;
235 "pow" return POW;
236 "sin" return SIN;
237 "sinh" return SINH;
238 "tan" return TAN;
239 "tanh" return TANH;
240 "sqrt" return SQRT;
241
242 . return *yytext;