From 3f025585dcee5e4cc66903cb0f00593e0417a05f Mon Sep 17 00:00:00 2001 From: Ladislav Michl Date: Mon, 7 Apr 2025 21:51:14 +0200 Subject: [PATCH] App: Expression: rename lexer and parser files Rename files according 7d233dc ("Gui: Rename generated lexer files to match core naming pattern"). Note that C space errors (space before tabs, spaces on blank lines, etc.) still need to be fixed manually after regenerating lexer file. --- src/App/Expression.cpp | 8 +- src/App/{ExpressionParser.l => Expression.l} | 17 +- ...ex.ExpressionParser.c => Expression.lex.c} | 428 ++++++++-------- ...xpressionParser.tab.c => Expression.tab.c} | 384 ++++++++------- ...xpressionParser.tab.h => Expression.tab.h} | 6 +- src/App/{ExpressionParser.y => Expression.y} | 458 +++++++++--------- src/App/ExpressionParser.h | 2 +- src/App/ExpressionParser.sh | 10 +- 8 files changed, 648 insertions(+), 665 deletions(-) rename src/App/{ExpressionParser.l => Expression.l} (99%) rename src/App/{lex.ExpressionParser.c => Expression.lex.c} (98%) rename src/App/{ExpressionParser.tab.c => Expression.tab.c} (91%) rename src/App/{ExpressionParser.tab.h => Expression.tab.h} (95%) rename src/App/{ExpressionParser.y => Expression.y} (96%) diff --git a/src/App/Expression.cpp b/src/App/Expression.cpp index 0405af5fa3..d825d2d81a 100644 --- a/src/App/Expression.cpp +++ b/src/App/Expression.cpp @@ -3544,13 +3544,13 @@ int ExpressionParserlex(); # pragma GCC diagnostic ignored "-Wfree-nonheap-object" #endif -// Parser, defined in ExpressionParser.y +// Parser, defined in Expression.y # define YYTOKENTYPE -#include "ExpressionParser.tab.c" +#include "Expression.tab.c" #ifndef DOXYGEN_SHOULD_SKIP_THIS -// Scanner, defined in ExpressionParser.l -#include "lex.ExpressionParser.c" +// Scanner, defined in Expression.l +#include "Expression.lex.c" #endif // DOXYGEN_SHOULD_SKIP_THIS class StringBufferCleaner diff --git a/src/App/ExpressionParser.l b/src/App/Expression.l similarity index 99% rename from src/App/ExpressionParser.l rename to src/App/Expression.l index 566dab95e0..f89bf02636 100644 --- a/src/App/ExpressionParser.l +++ b/src/App/Expression.l @@ -22,14 +22,7 @@ * * ***************************************************************************/ -/* Lexer for the FreeCAD Expression language */ - -/* use this file to generate the file 'lex.ExpressionParser.c' using the program flex - * the command for this operation is: - * flex --outfile=lex.ExpressionParser.c ExpressionParser.l - * (flex for Windows is available here: - * https://sourceforge.net/projects/winflexbison/ - * (you must then change 'flex' to 'win_flex' in the command)) */ +/* Lexer for the FreeCAD Expression language */ /* This disables inclusion of unistd.h, which is not available under Visual C++ * on Win32. The C++ scanner uses STL streams instead. */ @@ -165,7 +158,7 @@ S ({S1}|{S2}) Z (\x20|\xc2\xa0|\xe1(\x9a\x80)|\xe2(\x80[\x80-\x8a\xa8-\xa9\xaf]|\x81\x9f)|\xe3(\x80\x80)) DIGIT [0-9] -EXPO [eE][-+]?[0-9]+ +EXPO [eE][-+]?[0-9]+ %% /*** Filter language Part ***/ @@ -174,7 +167,7 @@ EXPO [eE][-+]?[0-9]+ \<\<(\\(.|\n)|[^\\>\n])*\>\> COUNTCHARS; yylval.string = unquote(yytext); return STRING; -[%+()=/*^,\.\{\}\[\]:;@\?#] COUNTCHARS; return *yytext; +[%+()=/*^,\.\{\}\[\]:;@\?#] COUNTCHARS; return *yytext; "==" COUNTCHARS; return EQ; "!=" COUNTCHARS; return NEQ; @@ -332,9 +325,9 @@ EXPO [eE][-+]?[0-9]+ "rad" COUNTCHARS; yylval.quantity.scaler = Quantity::Radian; yylval.quantity.unitStr = yytext; return UNIT; // radian "gon" COUNTCHARS; yylval.quantity.scaler = Quantity::Gon; yylval.quantity.unitStr = yytext; return UNIT; // gon "M" COUNTCHARS; yylval.quantity.scaler = Quantity::AngMinute; yylval.quantity.unitStr = yytext; return UNIT; // angminute -"\xE2\x80\xB2" COUNTCHARS; yylval.quantity.scaler = Quantity::AngMinute; yylval.quantity.unitStr = yytext; return UNIT; // angminute U+2032 ′ ′ ′ +"\xE2\x80\xB2" COUNTCHARS; yylval.quantity.scaler = Quantity::AngMinute; yylval.quantity.unitStr = yytext; return UNIT; // angminute U+2032 ′ ′ ′ "AS" COUNTCHARS; yylval.quantity.scaler = Quantity::AngSecond; yylval.quantity.unitStr = yytext; return UNIT; // angsecond -"\xE2\x80\xB3" COUNTCHARS; yylval.quantity.scaler = Quantity::AngSecond; yylval.quantity.unitStr = yytext; return UNIT; // angsecond U+2033 ″ ″ ″ +"\xE2\x80\xB3" COUNTCHARS; yylval.quantity.scaler = Quantity::AngSecond; yylval.quantity.unitStr = yytext; return UNIT; // angsecond U+2033 ″ ″ ″ {DIGIT}*"."{DIGIT}+{EXPO}? COUNTCHARS; yylval.fvalue = num_change(yytext,'.',','); return yylval.fvalue == 1 ? ONE : NUM; {DIGIT}*","{DIGIT}+{EXPO}? COUNTCHARS; yylval.fvalue = num_change(yytext,',','.'); return yylval.fvalue == 1 ? ONE : NUM; diff --git a/src/App/lex.ExpressionParser.c b/src/App/Expression.lex.c similarity index 98% rename from src/App/lex.ExpressionParser.c rename to src/App/Expression.lex.c index cc9777e092..c01442d52b 100644 --- a/src/App/lex.ExpressionParser.c +++ b/src/App/Expression.lex.c @@ -1,6 +1,7 @@ -#line 1 "lex.ExpressionParser.c" +// clang-format off +#line 2 "Expression.lex.c" -#line 3 "lex.ExpressionParser.c" +#line 4 "Expression.lex.c" #define YY_INT_ALIGNED short int @@ -293,7 +294,7 @@ #if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, - * if you want the limit (max/min) macros for int types. + * if you want the limit (max/min) macros for int types. */ #ifndef __STDC_LIMIT_MACROS #define __STDC_LIMIT_MACROS 1 @@ -310,7 +311,7 @@ typedef uint32_t flex_uint32_t; typedef signed char flex_int8_t; typedef short int flex_int16_t; typedef int flex_int32_t; -typedef unsigned char flex_uint8_t; +typedef unsigned char flex_uint8_t; typedef unsigned short int flex_uint16_t; typedef unsigned int flex_uint32_t; @@ -421,10 +422,10 @@ extern FILE *yyin, *yyout; #define EOB_ACT_CONTINUE_SCAN 0 #define EOB_ACT_END_OF_FILE 1 #define EOB_ACT_LAST_MATCH 2 - + #define YY_LESS_LINENO(n) #define YY_LINENO_REWIND_TO(ptr) - + /* Return all but the first "n" matched characters back to the input stream. */ #define yyless(n) \ do \ @@ -8560,8 +8561,8 @@ int yy_flex_debug = 0; #define YY_MORE_ADJ 0 #define YY_RESTORE_YY_MORE_OFFSET char *yytext; -#line 1 "ExpressionParser.l" -#line 2 "ExpressionParser.l" +#line 1 "Expression.l" +#line 2 "Expression.l" /*************************************************************************** * Copyright (c) 2010 Jürgen Riegel * * Copyright (c) 2015 Eivind Kvedalen * @@ -8585,14 +8586,7 @@ char *yytext; * * ***************************************************************************/ -/* Lexer for the FreeCAD Expression language */ - -/* use this file to generate the file 'lex.ExpressionParser.c' using the program flex - * the command for this operation is: - * flex --outfile=lex.ExpressionParser.c ExpressionParser.l - * (flex for Windows is available here: - * https://sourceforge.net/projects/winflexbison/ - * (you must then change 'flex' to 'win_flex' in the command)) */ +/* Lexer for the FreeCAD Expression language */ /* This disables inclusion of unistd.h, which is not available under Visual C++ * on Win32. The C++ scanner uses STL streams instead. */ @@ -8608,14 +8602,14 @@ extern int column; #define COUNTCHARS do { last_column = column; column += yyleng; } while (0) -#line 8611 "lex.ExpressionParser.c" +#line 8605 "Expression.lex.c" /*** Flex Declarations and Options ***/ /* change the name of the scanner class. */ /* the manual says "somewhat more optimized" */ /* no support for include files is planned */ /* UTF-8 unicode regular expressions. */ /* http://www.unicode.org/reports/tr44/#General_Category_Values */ -#line 8618 "lex.ExpressionParser.c" +#line 8612 "Expression.lex.c" #define INITIAL 0 @@ -8675,7 +8669,7 @@ extern int yywrap ( void ); #endif #ifndef YY_NO_UNPUT - + #endif #ifndef yytext_ptr @@ -8802,7 +8796,7 @@ YY_DECL yy_state_type yy_current_state; char *yy_cp, *yy_bp; int yy_act; - + if ( !(yy_init) ) { (yy_init) = 1; @@ -8830,10 +8824,10 @@ YY_DECL } { -#line 170 "ExpressionParser.l" +#line 163 "Expression.l" -#line 8836 "lex.ExpressionParser.c" +#line 8830 "Expression.lex.c" while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */ { @@ -8888,751 +8882,751 @@ do_action: /* This label is used only to access EOF actions. */ case 1: YY_RULE_SETUP -#line 172 "ExpressionParser.l" +#line 165 "Expression.l" COUNTCHARS; YY_BREAK case 2: /* rule 2 can match eol */ YY_RULE_SETUP -#line 173 "ExpressionParser.l" +#line 166 "Expression.l" column = 0; YY_BREAK case 3: /* rule 3 can match eol */ YY_RULE_SETUP -#line 175 "ExpressionParser.l" +#line 168 "Expression.l" COUNTCHARS; yylval.string = unquote(yytext); return STRING; YY_BREAK case 4: YY_RULE_SETUP -#line 177 "ExpressionParser.l" +#line 170 "Expression.l" COUNTCHARS; return *yytext; YY_BREAK case 5: YY_RULE_SETUP -#line 179 "ExpressionParser.l" +#line 172 "Expression.l" COUNTCHARS; return EQ; YY_BREAK case 6: YY_RULE_SETUP -#line 180 "ExpressionParser.l" +#line 173 "Expression.l" COUNTCHARS; return NEQ; YY_BREAK case 7: YY_RULE_SETUP -#line 181 "ExpressionParser.l" +#line 174 "Expression.l" COUNTCHARS; return GT; YY_BREAK case 8: YY_RULE_SETUP -#line 182 "ExpressionParser.l" +#line 175 "Expression.l" COUNTCHARS; return LT; YY_BREAK case 9: YY_RULE_SETUP -#line 183 "ExpressionParser.l" +#line 176 "Expression.l" COUNTCHARS; return GTE; YY_BREAK case 10: YY_RULE_SETUP -#line 184 "ExpressionParser.l" +#line 177 "Expression.l" COUNTCHARS; return LTE; YY_BREAK case 11: YY_RULE_SETUP -#line 186 "ExpressionParser.l" +#line 179 "Expression.l" COUNTCHARS; return MINUSSIGN; YY_BREAK case 12: YY_RULE_SETUP -#line 187 "ExpressionParser.l" +#line 180 "Expression.l" COUNTCHARS; return MINUSSIGN; YY_BREAK case 13: YY_RULE_SETUP -#line 189 "ExpressionParser.l" +#line 182 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::NanoMetre; yylval.quantity.unitStr = yytext; return UNIT; // nano meter YY_BREAK case 14: YY_RULE_SETUP -#line 190 "ExpressionParser.l" +#line 183 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::MicroMetre; yylval.quantity.unitStr = yytext; return UNIT; // micro meter YY_BREAK case 15: YY_RULE_SETUP -#line 191 "ExpressionParser.l" +#line 184 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::MicroMetre; yylval.quantity.unitStr = yytext; return UNIT; // micro meter (greek micro in UTF8) YY_BREAK case 16: YY_RULE_SETUP -#line 192 "ExpressionParser.l" +#line 185 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::MilliMetre; yylval.quantity.unitStr = yytext; return UNIT; // milli meter (internal standard length) YY_BREAK case 17: YY_RULE_SETUP -#line 193 "ExpressionParser.l" +#line 186 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::CentiMetre; yylval.quantity.unitStr = yytext; return UNIT; // centi meter YY_BREAK case 18: YY_RULE_SETUP -#line 194 "ExpressionParser.l" +#line 187 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::DeciMetre; yylval.quantity.unitStr = yytext; return UNIT; // deci meter YY_BREAK case 19: YY_RULE_SETUP -#line 195 "ExpressionParser.l" +#line 188 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::Metre; yylval.quantity.unitStr = yytext; return UNIT; // Metre YY_BREAK case 20: YY_RULE_SETUP -#line 196 "ExpressionParser.l" +#line 189 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::KiloMetre; yylval.quantity.unitStr = yytext; return UNIT; // kilo meter YY_BREAK case 21: YY_RULE_SETUP -#line 198 "ExpressionParser.l" +#line 191 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::Liter; yylval.quantity.unitStr = yytext; return UNIT; // Liter dm^3 YY_BREAK case 22: YY_RULE_SETUP -#line 199 "ExpressionParser.l" +#line 192 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::MilliLiter; yylval.quantity.unitStr = yytext; return UNIT; // milli Liter YY_BREAK case 23: YY_RULE_SETUP -#line 201 "ExpressionParser.l" +#line 194 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::Hertz; yylval.quantity.unitStr = yytext; return UNIT; // Hertz YY_BREAK case 24: YY_RULE_SETUP -#line 202 "ExpressionParser.l" +#line 195 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::KiloHertz; yylval.quantity.unitStr = yytext; return UNIT; // kilo Hertz YY_BREAK case 25: YY_RULE_SETUP -#line 203 "ExpressionParser.l" +#line 196 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::MegaHertz; yylval.quantity.unitStr = yytext; return UNIT; // mega Hertz YY_BREAK case 26: YY_RULE_SETUP -#line 204 "ExpressionParser.l" +#line 197 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::GigaHertz; yylval.quantity.unitStr = yytext; return UNIT; // giga Hertz YY_BREAK case 27: YY_RULE_SETUP -#line 205 "ExpressionParser.l" +#line 198 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::TeraHertz; yylval.quantity.unitStr = yytext; return UNIT; // tera Hertz YY_BREAK case 28: YY_RULE_SETUP -#line 207 "ExpressionParser.l" +#line 200 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::MicroGram; yylval.quantity.unitStr = yytext; return UNIT; // micro gram YY_BREAK case 29: YY_RULE_SETUP -#line 208 "ExpressionParser.l" +#line 201 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::MicroGram; yylval.quantity.unitStr = yytext; return UNIT; // micro gram YY_BREAK case 30: YY_RULE_SETUP -#line 209 "ExpressionParser.l" +#line 202 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::MilliGram; yylval.quantity.unitStr = yytext; return UNIT; // milli gram YY_BREAK case 31: YY_RULE_SETUP -#line 210 "ExpressionParser.l" +#line 203 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::Gram; yylval.quantity.unitStr = yytext; return UNIT; // gram YY_BREAK case 32: YY_RULE_SETUP -#line 211 "ExpressionParser.l" +#line 204 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::KiloGram; yylval.quantity.unitStr = yytext; return UNIT; // kilo gram (internal standard for mass) YY_BREAK case 33: YY_RULE_SETUP -#line 212 "ExpressionParser.l" +#line 205 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::Ton; yylval.quantity.unitStr = yytext; return UNIT; // Metric Tonne YY_BREAK case 34: YY_RULE_SETUP -#line 214 "ExpressionParser.l" +#line 207 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::Second; yylval.quantity.unitStr = yytext; return UNIT; // second (internal standard time) YY_BREAK case 35: YY_RULE_SETUP -#line 215 "ExpressionParser.l" +#line 208 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::Minute; yylval.quantity.unitStr = yytext; return UNIT; // minute YY_BREAK case 36: YY_RULE_SETUP -#line 216 "ExpressionParser.l" +#line 209 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::Hour; yylval.quantity.unitStr = yytext; return UNIT; // hour YY_BREAK case 37: YY_RULE_SETUP -#line 218 "ExpressionParser.l" +#line 211 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::Ampere; yylval.quantity.unitStr = yytext; return UNIT; // Ampere (internal standard electric current) YY_BREAK case 38: YY_RULE_SETUP -#line 219 "ExpressionParser.l" +#line 212 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::MilliAmpere; yylval.quantity.unitStr = yytext; return UNIT; // milli Ampere YY_BREAK case 39: YY_RULE_SETUP -#line 220 "ExpressionParser.l" +#line 213 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::KiloAmpere; yylval.quantity.unitStr = yytext; return UNIT; // kilo Ampere YY_BREAK case 40: YY_RULE_SETUP -#line 221 "ExpressionParser.l" +#line 214 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::MegaAmpere; yylval.quantity.unitStr = yytext; return UNIT; // mega Ampere YY_BREAK case 41: YY_RULE_SETUP -#line 223 "ExpressionParser.l" +#line 216 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::Kelvin; yylval.quantity.unitStr = yytext; return UNIT; // Kelvin (internal standard thermodynamic temperature) YY_BREAK case 42: YY_RULE_SETUP -#line 224 "ExpressionParser.l" +#line 217 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::MilliKelvin; yylval.quantity.unitStr = yytext; return UNIT; // milli Kelvin YY_BREAK case 43: YY_RULE_SETUP -#line 225 "ExpressionParser.l" +#line 218 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::MicroKelvin; yylval.quantity.unitStr = yytext; return UNIT; // micro Kelvin YY_BREAK case 44: YY_RULE_SETUP -#line 226 "ExpressionParser.l" +#line 219 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::MicroKelvin; yylval.quantity.unitStr = yytext; return UNIT; // micro Kelvin YY_BREAK case 45: YY_RULE_SETUP -#line 228 "ExpressionParser.l" +#line 221 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::Mole; yylval.quantity.unitStr = yytext; return UNIT; // Mole (internal standard amount of substance) YY_BREAK case 46: YY_RULE_SETUP -#line 229 "ExpressionParser.l" +#line 222 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::MilliMole; yylval.quantity.unitStr = yytext; return UNIT; // milli Mole YY_BREAK case 47: YY_RULE_SETUP -#line 231 "ExpressionParser.l" +#line 224 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::Candela; yylval.quantity.unitStr = yytext; return UNIT; // Candela (internal standard luminous intensity) YY_BREAK case 48: YY_RULE_SETUP -#line 233 "ExpressionParser.l" +#line 226 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::Inch; yylval.quantity.unitStr = yytext; return UNIT; // inch YY_BREAK case 49: YY_RULE_SETUP -#line 234 "ExpressionParser.l" +#line 227 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::Inch; yylval.quantity.unitStr = yytext; return USUNIT; // inch YY_BREAK case 50: YY_RULE_SETUP -#line 235 "ExpressionParser.l" +#line 228 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::Foot; yylval.quantity.unitStr = yytext; return UNIT; // foot YY_BREAK case 51: YY_RULE_SETUP -#line 236 "ExpressionParser.l" +#line 229 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::Foot; yylval.quantity.unitStr = yytext; return USUNIT; // foot YY_BREAK case 52: YY_RULE_SETUP -#line 237 "ExpressionParser.l" +#line 230 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::Thou; yylval.quantity.unitStr = yytext; return UNIT; // thou (in/1000) YY_BREAK case 53: YY_RULE_SETUP -#line 238 "ExpressionParser.l" +#line 231 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::Thou; yylval.quantity.unitStr = yytext; return UNIT; // mil (the thou in US) YY_BREAK case 54: YY_RULE_SETUP -#line 239 "ExpressionParser.l" +#line 232 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::Yard; yylval.quantity.unitStr = yytext; return UNIT; // yard YY_BREAK case 55: YY_RULE_SETUP -#line 240 "ExpressionParser.l" +#line 233 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::Mile; yylval.quantity.unitStr = yytext; return UNIT; // mile YY_BREAK case 56: YY_RULE_SETUP -#line 242 "ExpressionParser.l" +#line 235 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::MilePerHour; yylval.quantity.unitStr = yytext; return UNIT; // mile per hour YY_BREAK case 57: YY_RULE_SETUP -#line 243 "ExpressionParser.l" +#line 236 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::SquareFoot; yylval.quantity.unitStr = yytext; return UNIT; // square foot YY_BREAK case 58: YY_RULE_SETUP -#line 244 "ExpressionParser.l" +#line 237 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::CubicFoot; yylval.quantity.unitStr = yytext; return UNIT; // cubic foot YY_BREAK case 59: YY_RULE_SETUP -#line 246 "ExpressionParser.l" +#line 239 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::Pound; yylval.quantity.unitStr = yytext; return UNIT; // pound YY_BREAK case 60: YY_RULE_SETUP -#line 247 "ExpressionParser.l" +#line 240 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::Pound; yylval.quantity.unitStr = yytext; return UNIT; // pound YY_BREAK case 61: YY_RULE_SETUP -#line 248 "ExpressionParser.l" +#line 241 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::Ounce; yylval.quantity.unitStr = yytext; return UNIT; // ounce YY_BREAK case 62: YY_RULE_SETUP -#line 249 "ExpressionParser.l" +#line 242 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::Stone; yylval.quantity.unitStr = yytext; return UNIT; // Stone YY_BREAK case 63: YY_RULE_SETUP -#line 250 "ExpressionParser.l" +#line 243 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::Hundredweights; yylval.quantity.unitStr = yytext; return UNIT; // hundredweights YY_BREAK case 64: YY_RULE_SETUP -#line 252 "ExpressionParser.l" +#line 245 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::PoundForce; yylval.quantity.unitStr = yytext; return UNIT; // pound YY_BREAK case 65: YY_RULE_SETUP -#line 254 "ExpressionParser.l" +#line 247 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::Newton; yylval.quantity.unitStr = yytext; return UNIT; // Newton (kg*m/s^2)a-za-za-z YY_BREAK case 66: YY_RULE_SETUP -#line 255 "ExpressionParser.l" +#line 248 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::MilliNewton; yylval.quantity.unitStr = yytext; return UNIT; // milli Newton YY_BREAK case 67: YY_RULE_SETUP -#line 256 "ExpressionParser.l" +#line 249 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::KiloNewton; yylval.quantity.unitStr = yytext; return UNIT; // kilo Newton YY_BREAK case 68: YY_RULE_SETUP -#line 257 "ExpressionParser.l" +#line 250 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::MegaNewton; yylval.quantity.unitStr = yytext; return UNIT; // mega Newton YY_BREAK case 69: YY_RULE_SETUP -#line 259 "ExpressionParser.l" +#line 252 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::Pascal; yylval.quantity.unitStr = yytext; return UNIT; // Pascal (kg/m*s^2 or N/m^2) YY_BREAK case 70: YY_RULE_SETUP -#line 260 "ExpressionParser.l" +#line 253 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::KiloPascal; yylval.quantity.unitStr = yytext; return UNIT; // kilo Pascal YY_BREAK case 71: YY_RULE_SETUP -#line 261 "ExpressionParser.l" +#line 254 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::MegaPascal; yylval.quantity.unitStr = yytext; return UNIT; // mega Pascal YY_BREAK case 72: YY_RULE_SETUP -#line 262 "ExpressionParser.l" +#line 255 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::GigaPascal; yylval.quantity.unitStr = yytext; return UNIT; // giga Pascal YY_BREAK case 73: YY_RULE_SETUP -#line 264 "ExpressionParser.l" +#line 257 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::Bar; yylval.quantity.unitStr = yytext; return UNIT; // Bar YY_BREAK case 74: YY_RULE_SETUP -#line 265 "ExpressionParser.l" +#line 258 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::MilliBar; yylval.quantity.unitStr = yytext; return UNIT; // milli Bar YY_BREAK case 75: YY_RULE_SETUP -#line 267 "ExpressionParser.l" +#line 260 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::Torr; yylval.quantity.unitStr = yytext; return UNIT; // portion of Pascal ( 101325/760 ) YY_BREAK case 76: YY_RULE_SETUP -#line 268 "ExpressionParser.l" +#line 261 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::mTorr; yylval.quantity.unitStr = yytext; return UNIT; // YY_BREAK case 77: YY_RULE_SETUP -#line 269 "ExpressionParser.l" +#line 262 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::yTorr; yylval.quantity.unitStr = yytext; return UNIT; // YY_BREAK case 78: YY_RULE_SETUP -#line 270 "ExpressionParser.l" +#line 263 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::yTorr; yylval.quantity.unitStr = yytext; return UNIT; // YY_BREAK case 79: YY_RULE_SETUP -#line 272 "ExpressionParser.l" +#line 265 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::PSI; yylval.quantity.unitStr = yytext; return UNIT; // pounds/in^2 YY_BREAK case 80: YY_RULE_SETUP -#line 273 "ExpressionParser.l" +#line 266 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::KSI; yylval.quantity.unitStr = yytext; return UNIT; // 1000 x pounds/in^2 YY_BREAK case 81: YY_RULE_SETUP -#line 274 "ExpressionParser.l" +#line 267 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::MPSI; yylval.quantity.unitStr = yytext; return UNIT; // 1000 ksi YY_BREAK case 82: YY_RULE_SETUP -#line 276 "ExpressionParser.l" +#line 269 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::Watt; yylval.quantity.unitStr = yytext; return UNIT; // Watt (kg*m^2/s^3) YY_BREAK case 83: YY_RULE_SETUP -#line 277 "ExpressionParser.l" +#line 270 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::MilliWatt; yylval.quantity.unitStr = yytext; return UNIT; // milli Watt YY_BREAK case 84: YY_RULE_SETUP -#line 278 "ExpressionParser.l" +#line 271 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::KiloWatt; yylval.quantity.unitStr = yytext; return UNIT; // kilo Watt YY_BREAK case 85: YY_RULE_SETUP -#line 279 "ExpressionParser.l" +#line 272 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::VoltAmpere; yylval.quantity.unitStr = yytext; return UNIT; // VoltAmpere (kg*m^2/s^3) YY_BREAK case 86: YY_RULE_SETUP -#line 281 "ExpressionParser.l" +#line 274 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::Volt; yylval.quantity.unitStr = yytext; return UNIT; // Volt (kg*m^2/A/s^3) YY_BREAK case 87: YY_RULE_SETUP -#line 282 "ExpressionParser.l" +#line 275 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::KiloVolt; yylval.quantity.unitStr = yytext; return UNIT; // kilo Volt YY_BREAK case 88: YY_RULE_SETUP -#line 283 "ExpressionParser.l" +#line 276 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::MilliVolt; yylval.quantity.unitStr = yytext; return UNIT; // milli Volt YY_BREAK case 89: YY_RULE_SETUP -#line 285 "ExpressionParser.l" +#line 278 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::MegaSiemens; yylval.quantity.unitStr = yytext; return UNIT; // mega Siemens YY_BREAK case 90: YY_RULE_SETUP -#line 286 "ExpressionParser.l" +#line 279 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::KiloSiemens; yylval.quantity.unitStr = yytext; return UNIT; // kilo Siemens YY_BREAK case 91: YY_RULE_SETUP -#line 287 "ExpressionParser.l" +#line 280 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::Siemens; yylval.quantity.unitStr = yytext; return UNIT; // Siemens (A^2*s^3/kg/m^2) YY_BREAK case 92: YY_RULE_SETUP -#line 288 "ExpressionParser.l" +#line 281 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::MilliSiemens; yylval.quantity.unitStr = yytext; return UNIT; // milli Siemens YY_BREAK case 93: YY_RULE_SETUP -#line 289 "ExpressionParser.l" +#line 282 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::MicroSiemens; yylval.quantity.unitStr = yytext; return UNIT; // micro Siemens YY_BREAK case 94: YY_RULE_SETUP -#line 290 "ExpressionParser.l" +#line 283 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::MicroSiemens; yylval.quantity.unitStr = yytext; return UNIT; // micro Siemens YY_BREAK case 95: YY_RULE_SETUP -#line 292 "ExpressionParser.l" +#line 285 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::Ohm; yylval.quantity.unitStr = yytext; return UNIT; // Ohm (kg*m^2/A^2/s^3) YY_BREAK case 96: YY_RULE_SETUP -#line 293 "ExpressionParser.l" +#line 286 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::KiloOhm; yylval.quantity.unitStr = yytext; return UNIT; // kilo Ohm YY_BREAK case 97: YY_RULE_SETUP -#line 294 "ExpressionParser.l" +#line 287 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::MegaOhm; yylval.quantity.unitStr = yytext; return UNIT; // mega Ohm YY_BREAK case 98: YY_RULE_SETUP -#line 296 "ExpressionParser.l" +#line 289 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::Coulomb; yylval.quantity.unitStr = yytext; return UNIT; // Coulomb (A*s) YY_BREAK case 99: YY_RULE_SETUP -#line 298 "ExpressionParser.l" +#line 291 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::Tesla; yylval.quantity.unitStr = yytext; return UNIT; // Tesla (kg/s^2/A) YY_BREAK case 100: YY_RULE_SETUP -#line 299 "ExpressionParser.l" +#line 292 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::Gauss; yylval.quantity.unitStr = yytext; return UNIT; // Gauss (1 G = 1e-4 T) YY_BREAK case 101: YY_RULE_SETUP -#line 301 "ExpressionParser.l" +#line 294 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::Weber; yylval.quantity.unitStr = yytext; return UNIT; // Weber (kg*m^2/s^2/A) YY_BREAK case 102: YY_RULE_SETUP -#line 303 "ExpressionParser.l" +#line 296 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::Farad; yylval.quantity.unitStr = yytext; return UNIT; // Farad (s^4*A^2/m^2/kg) YY_BREAK case 103: YY_RULE_SETUP -#line 304 "ExpressionParser.l" +#line 297 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::MilliFarad; yylval.quantity.unitStr = yytext; return UNIT; // milli Farad YY_BREAK case 104: YY_RULE_SETUP -#line 305 "ExpressionParser.l" +#line 298 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::MicroFarad; yylval.quantity.unitStr = yytext; return UNIT; // micro Farad YY_BREAK case 105: YY_RULE_SETUP -#line 306 "ExpressionParser.l" +#line 299 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::MicroFarad; yylval.quantity.unitStr = yytext; return UNIT; // micro Farad YY_BREAK case 106: YY_RULE_SETUP -#line 307 "ExpressionParser.l" +#line 300 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::NanoFarad; yylval.quantity.unitStr = yytext; return UNIT; // nano Farad YY_BREAK case 107: YY_RULE_SETUP -#line 308 "ExpressionParser.l" +#line 301 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::PicoFarad; yylval.quantity.unitStr = yytext; return UNIT; // pico Farad YY_BREAK case 108: YY_RULE_SETUP -#line 310 "ExpressionParser.l" +#line 303 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::Henry; yylval.quantity.unitStr = yytext; return UNIT; // Henry (kg*m^2/s^2/A^2) YY_BREAK case 109: YY_RULE_SETUP -#line 311 "ExpressionParser.l" +#line 304 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::MilliHenry; yylval.quantity.unitStr = yytext; return UNIT; // milli Henry YY_BREAK case 110: YY_RULE_SETUP -#line 312 "ExpressionParser.l" +#line 305 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::MicroHenry; yylval.quantity.unitStr = yytext; return UNIT; // micro Henry YY_BREAK case 111: YY_RULE_SETUP -#line 313 "ExpressionParser.l" +#line 306 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::MicroHenry; yylval.quantity.unitStr = yytext; return UNIT; // micro Henry) YY_BREAK case 112: YY_RULE_SETUP -#line 314 "ExpressionParser.l" +#line 307 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::NanoHenry; yylval.quantity.unitStr = yytext; return UNIT; // nano Henry YY_BREAK case 113: YY_RULE_SETUP -#line 316 "ExpressionParser.l" +#line 309 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::Joule; yylval.quantity.unitStr = yytext; return UNIT; // Joule (kg*m^2/s^2) YY_BREAK case 114: YY_RULE_SETUP -#line 317 "ExpressionParser.l" +#line 310 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::MilliJoule; yylval.quantity.unitStr = yytext; return UNIT; // milli Joule YY_BREAK case 115: YY_RULE_SETUP -#line 318 "ExpressionParser.l" +#line 311 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::KiloJoule; yylval.quantity.unitStr = yytext; return UNIT; // kilo Joule YY_BREAK case 116: YY_RULE_SETUP -#line 319 "ExpressionParser.l" +#line 312 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::NewtonMeter; yylval.quantity.unitStr = yytext; return UNIT; // N*m = Joule YY_BREAK case 117: YY_RULE_SETUP -#line 320 "ExpressionParser.l" +#line 313 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::VoltAmpereSecond; yylval.quantity.unitStr = yytext; return UNIT; // V*A*s = Joule YY_BREAK case 118: YY_RULE_SETUP -#line 321 "ExpressionParser.l" +#line 314 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::WattSecond; yylval.quantity.unitStr = yytext; return UNIT; // YY_BREAK case 119: YY_RULE_SETUP -#line 322 "ExpressionParser.l" +#line 315 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::WattSecond; yylval.quantity.unitStr = yytext; return UNIT; // W*s = Joule YY_BREAK case 120: YY_RULE_SETUP -#line 323 "ExpressionParser.l" +#line 316 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::KiloWattHour; yylval.quantity.unitStr = yytext; return UNIT; // 1 kWh = 3.6e6 J YY_BREAK case 121: YY_RULE_SETUP -#line 324 "ExpressionParser.l" +#line 317 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::ElectronVolt; yylval.quantity.unitStr = yytext; return UNIT; // 1 eV = 1.602176634e-19 J YY_BREAK case 122: YY_RULE_SETUP -#line 325 "ExpressionParser.l" +#line 318 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::KiloElectronVolt; yylval.quantity.unitStr = yytext; return UNIT; YY_BREAK case 123: YY_RULE_SETUP -#line 326 "ExpressionParser.l" +#line 319 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::MegaElectronVolt; yylval.quantity.unitStr = yytext; return UNIT; YY_BREAK case 124: YY_RULE_SETUP -#line 327 "ExpressionParser.l" +#line 320 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::Calorie; yylval.quantity.unitStr = yytext; return UNIT; // 1 cal = 4.1868 J YY_BREAK case 125: YY_RULE_SETUP -#line 328 "ExpressionParser.l" +#line 321 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::KiloCalorie; yylval.quantity.unitStr = yytext; return UNIT; YY_BREAK case 126: YY_RULE_SETUP -#line 330 "ExpressionParser.l" +#line 323 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::Degree; yylval.quantity.unitStr = yytext; return UNIT; // degree (internal standard angle) YY_BREAK case 127: YY_RULE_SETUP -#line 331 "ExpressionParser.l" +#line 324 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::Degree; yylval.quantity.unitStr = yytext; return UNIT; // degree (internal standard angle) YY_BREAK case 128: YY_RULE_SETUP -#line 332 "ExpressionParser.l" +#line 325 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::Radian; yylval.quantity.unitStr = yytext; return UNIT; // radian YY_BREAK case 129: YY_RULE_SETUP -#line 333 "ExpressionParser.l" +#line 326 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::Gon; yylval.quantity.unitStr = yytext; return UNIT; // gon YY_BREAK case 130: YY_RULE_SETUP -#line 334 "ExpressionParser.l" +#line 327 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::AngMinute; yylval.quantity.unitStr = yytext; return UNIT; // angminute YY_BREAK case 131: YY_RULE_SETUP -#line 335 "ExpressionParser.l" -COUNTCHARS; yylval.quantity.scaler = Quantity::AngMinute; yylval.quantity.unitStr = yytext; return UNIT; // angminute U+2032 ′ ′ ′ +#line 328 "Expression.l" +COUNTCHARS; yylval.quantity.scaler = Quantity::AngMinute; yylval.quantity.unitStr = yytext; return UNIT; // angminute U+2032 ′ ′ ′ YY_BREAK case 132: YY_RULE_SETUP -#line 336 "ExpressionParser.l" +#line 329 "Expression.l" COUNTCHARS; yylval.quantity.scaler = Quantity::AngSecond; yylval.quantity.unitStr = yytext; return UNIT; // angsecond YY_BREAK case 133: YY_RULE_SETUP -#line 337 "ExpressionParser.l" -COUNTCHARS; yylval.quantity.scaler = Quantity::AngSecond; yylval.quantity.unitStr = yytext; return UNIT; // angsecond U+2033 ″ ″ ″ +#line 330 "Expression.l" +COUNTCHARS; yylval.quantity.scaler = Quantity::AngSecond; yylval.quantity.unitStr = yytext; return UNIT; // angsecond U+2033 ″ ″ ″ YY_BREAK case 134: YY_RULE_SETUP -#line 339 "ExpressionParser.l" +#line 332 "Expression.l" COUNTCHARS; yylval.fvalue = num_change(yytext,'.',','); return yylval.fvalue == 1 ? ONE : NUM; YY_BREAK case 135: YY_RULE_SETUP -#line 340 "ExpressionParser.l" +#line 333 "Expression.l" COUNTCHARS; yylval.fvalue = num_change(yytext,',','.'); return yylval.fvalue == 1 ? ONE : NUM; YY_BREAK case 136: YY_RULE_SETUP -#line 341 "ExpressionParser.l" +#line 334 "Expression.l" COUNTCHARS; yylval.fvalue = num_change(yytext,',','.'); return yylval.fvalue == 1 ? ONE : NUM; YY_BREAK case 137: YY_RULE_SETUP -#line 342 "ExpressionParser.l" +#line 335 "Expression.l" { COUNTCHARS; yylval.ivalue = strtoll( yytext, NULL, 10 ); - if (yylval.ivalue == LLONG_MIN) + if (yylval.ivalue == std::numeric_limits::min()) throw Base::UnderflowError("Integer underflow"); - else if (yylval.ivalue == LLONG_MAX) + else if (yylval.ivalue == std::numeric_limits::max()) throw Base::OverflowError("Integer overflow"); if (yylval.ivalue == 1) { yylval.fvalue = 1; return ONE; } else return INTEGER; } YY_BREAK case 138: YY_RULE_SETUP -#line 351 "ExpressionParser.l" +#line 344 "Expression.l" COUNTCHARS; yylval.constant.fvalue = std::numbers::pi; yylval.constant.name = "pi"; return CONSTANT; // constant pi YY_BREAK case 139: YY_RULE_SETUP -#line 352 "ExpressionParser.l" +#line 345 "Expression.l" COUNTCHARS; yylval.constant.fvalue = std::numbers::e; yylval.constant.name = "e"; return CONSTANT; // constant e YY_BREAK case 140: YY_RULE_SETUP -#line 354 "ExpressionParser.l" +#line 347 "Expression.l" COUNTCHARS; yylval.constant.fvalue = 0; yylval.constant.name = "None"; return CONSTANT; YY_BREAK case 141: YY_RULE_SETUP -#line 355 "ExpressionParser.l" +#line 348 "Expression.l" COUNTCHARS; yylval.constant.fvalue = 1; yylval.constant.name = "True"; return CONSTANT; YY_BREAK case 142: YY_RULE_SETUP -#line 356 "ExpressionParser.l" +#line 349 "Expression.l" COUNTCHARS; yylval.constant.fvalue = 1; yylval.constant.name = "True"; return CONSTANT; YY_BREAK case 143: YY_RULE_SETUP -#line 357 "ExpressionParser.l" +#line 350 "Expression.l" COUNTCHARS; yylval.constant.fvalue = 0; yylval.constant.name = "False"; return CONSTANT; YY_BREAK case 144: YY_RULE_SETUP -#line 358 "ExpressionParser.l" +#line 351 "Expression.l" COUNTCHARS; yylval.constant.fvalue = 0; yylval.constant.name = "False"; return CONSTANT; YY_BREAK case 145: YY_RULE_SETUP -#line 360 "ExpressionParser.l" +#line 353 "Expression.l" COUNTCHARS; yylval.string = yytext; return CELLADDRESS; YY_BREAK case 146: YY_RULE_SETUP -#line 361 "ExpressionParser.l" +#line 354 "Expression.l" COUNTCHARS; yylval.string = yytext; return CELLADDRESS; YY_BREAK case 147: YY_RULE_SETUP -#line 362 "ExpressionParser.l" +#line 355 "Expression.l" COUNTCHARS; yylval.string = yytext; return CELLADDRESS; YY_BREAK case 148: YY_RULE_SETUP -#line 364 "ExpressionParser.l" +#line 357 "Expression.l" { COUNTCHARS; std::string s = yytext; @@ -9650,15 +9644,15 @@ YY_RULE_SETUP YY_BREAK case 149: YY_RULE_SETUP -#line 379 "ExpressionParser.l" +#line 372 "Expression.l" COUNTCHARS; yylval.string = yytext; return IDENTIFIER; YY_BREAK case 150: YY_RULE_SETUP -#line 380 "ExpressionParser.l" +#line 373 "Expression.l" ECHO; YY_BREAK -#line 9661 "lex.ExpressionParser.c" +#line 9655 "Expression.lex.c" case YY_STATE_EOF(INITIAL): yyterminate(); @@ -9942,7 +9936,7 @@ static int yy_get_next_buffer (void) { yy_state_type yy_current_state; char *yy_cp; - + yy_current_state = (yy_start); for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp ) @@ -9973,7 +9967,7 @@ static int yy_get_next_buffer (void) static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state ) { int yy_is_jam; - char *yy_cp = (yy_c_buf_p); + char *yy_cp = (yy_c_buf_p); YY_CHAR yy_c = 1; if ( yy_accept[yy_current_state] ) @@ -10006,7 +10000,7 @@ static int yy_get_next_buffer (void) { int c; - + *(yy_c_buf_p) = (yy_hold_char); if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR ) @@ -10073,12 +10067,12 @@ static int yy_get_next_buffer (void) /** Immediately switch to a different input stream. * @param input_file A readable stream. - * + * * @note This function does not reset the start condition to @c INITIAL . */ void yyrestart (FILE * input_file ) { - + if ( ! YY_CURRENT_BUFFER ){ yyensure_buffer_stack (); YY_CURRENT_BUFFER_LVALUE = @@ -10091,11 +10085,11 @@ static int yy_get_next_buffer (void) /** Switch to a different input buffer. * @param new_buffer The new input buffer. - * + * */ void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ) { - + /* TODO. We should be able to replace this entire function body * with * yypop_buffer_state(); @@ -10126,7 +10120,7 @@ static int yy_get_next_buffer (void) static void yy_load_buffer_state (void) { - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; (yy_hold_char) = *(yy_c_buf_p); @@ -10135,13 +10129,13 @@ static void yy_load_buffer_state (void) /** Allocate and initialize an input buffer state. * @param file A readable stream. * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. - * + * * @return the allocated buffer state. */ YY_BUFFER_STATE yy_create_buffer (FILE * file, int size ) { YY_BUFFER_STATE b; - + b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) ); if ( ! b ) YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); @@ -10164,11 +10158,11 @@ static void yy_load_buffer_state (void) /** Destroy the buffer. * @param b a buffer created with yy_create_buffer() - * + * */ void yy_delete_buffer (YY_BUFFER_STATE b ) { - + if ( ! b ) return; @@ -10189,7 +10183,7 @@ static void yy_load_buffer_state (void) { int oerrno = errno; - + yy_flush_buffer( b ); b->yy_input_file = file; @@ -10205,17 +10199,17 @@ static void yy_load_buffer_state (void) } b->yy_is_interactive = 0; - + errno = oerrno; } /** Discard all buffered characters. On the next scan, YY_INPUT will be called. * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. - * + * */ void yy_flush_buffer (YY_BUFFER_STATE b ) { - if ( ! b ) + if ( ! b ) return; b->yy_n_chars = 0; @@ -10240,11 +10234,11 @@ static void yy_load_buffer_state (void) * the current state. This function will allocate the stack * if necessary. * @param new_buffer The new state. - * + * */ void yypush_buffer_state (YY_BUFFER_STATE new_buffer ) { - if (new_buffer == NULL) + if (new_buffer == NULL) return; yyensure_buffer_stack(); @@ -10270,11 +10264,11 @@ void yypush_buffer_state (YY_BUFFER_STATE new_buffer ) /** Removes and deletes the top of the stack, if present. * The next element becomes the new top. - * + * */ void yypop_buffer_state (void) { - if (!YY_CURRENT_BUFFER) + if (!YY_CURRENT_BUFFER) return; yy_delete_buffer(YY_CURRENT_BUFFER ); @@ -10294,7 +10288,7 @@ void yypop_buffer_state (void) static void yyensure_buffer_stack (void) { yy_size_t num_to_alloc; - + if (!(yy_buffer_stack)) { /* First allocation is just for 2 elements, since we don't know if this @@ -10337,13 +10331,13 @@ static void yyensure_buffer_stack (void) /** Setup the input buffer state to scan directly from a user-specified character buffer. * @param base the character buffer * @param size the size in bytes of the character buffer - * + * * @return the newly allocated buffer state object. */ YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ) { YY_BUFFER_STATE b; - + if ( size < 2 || base[size-2] != YY_END_OF_BUFFER_CHAR || base[size-1] != YY_END_OF_BUFFER_CHAR ) @@ -10372,14 +10366,14 @@ YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ) /** Setup the input buffer state to scan a string. The next call to yylex() will * scan from a @e copy of @a str. * @param yystr a NUL-terminated string to scan - * + * * @return the newly allocated buffer state object. * @note If you want to scan bytes that may contain NUL values, then use * yy_scan_bytes() instead. */ YY_BUFFER_STATE yy_scan_string (const char * yystr ) { - + return yy_scan_bytes( yystr, (int) strlen(yystr) ); } @@ -10387,7 +10381,7 @@ YY_BUFFER_STATE yy_scan_string (const char * yystr ) * scan from a @e copy of @a bytes. * @param yybytes the byte buffer to scan * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes. - * + * * @return the newly allocated buffer state object. */ YY_BUFFER_STATE yy_scan_bytes (const char * yybytes, int _yybytes_len ) @@ -10396,7 +10390,7 @@ YY_BUFFER_STATE yy_scan_bytes (const char * yybytes, int _yybytes_len ) char *buf; yy_size_t n; int i; - + /* Get memory for full buffer, including space for trailing EOB's. */ n = (yy_size_t) (_yybytes_len + 2); buf = (char *) yyalloc( n ); @@ -10450,16 +10444,16 @@ static void yynoreturn yy_fatal_error (const char* msg ) /* Accessor methods (get/set functions) to struct members. */ /** Get the current line number. - * + * */ int yyget_lineno (void) { - + return yylineno; } /** Get the input stream. - * + * */ FILE *yyget_in (void) { @@ -10467,7 +10461,7 @@ FILE *yyget_in (void) } /** Get the output stream. - * + * */ FILE *yyget_out (void) { @@ -10475,7 +10469,7 @@ FILE *yyget_out (void) } /** Get the length of the current token. - * + * */ int yyget_leng (void) { @@ -10483,7 +10477,7 @@ int yyget_leng (void) } /** Get the current token. - * + * */ char *yyget_text (void) @@ -10493,18 +10487,18 @@ char *yyget_text (void) /** Set the current line number. * @param _line_number line number - * + * */ void yyset_lineno (int _line_number ) { - + yylineno = _line_number; } /** Set the input stream. This does not discard the current * input buffer. * @param _in_str A readable stream. - * + * * @see yy_switch_to_buffer */ void yyset_in (FILE * _in_str ) @@ -10558,7 +10552,7 @@ static int yy_init_globals (void) /* yylex_destroy is for both reentrant and non-reentrant scanners. */ int yylex_destroy (void) { - + /* Pop the buffer stack, destroying each element. */ while(YY_CURRENT_BUFFER){ yy_delete_buffer( YY_CURRENT_BUFFER ); @@ -10584,7 +10578,7 @@ int yylex_destroy (void) #ifndef yytext_ptr static void yy_flex_strncpy (char* s1, const char * s2, int n ) { - + int i; for ( i = 0; i < n; ++i ) s1[i] = s2[i]; @@ -10609,7 +10603,7 @@ void *yyalloc (yy_size_t size ) void *yyrealloc (void * ptr, yy_size_t size ) { - + /* The cast to (char *) in the following accommodates both * implementations that use char* generic pointers, and those * that use void* generic pointers. It works with the latter @@ -10627,4 +10621,4 @@ void yyfree (void * ptr ) #define YYTABLES_NAME "yytables" -#line 380 "ExpressionParser.l" +#line 373 "Expression.l" diff --git a/src/App/ExpressionParser.tab.c b/src/App/Expression.tab.c similarity index 91% rename from src/App/ExpressionParser.tab.c rename to src/App/Expression.tab.c index 3c1dcc7510..d25df1e97b 100644 --- a/src/App/ExpressionParser.tab.c +++ b/src/App/Expression.tab.c @@ -1,3 +1,4 @@ +// clang-format off /* A Bison parser, made by GNU Bison 3.8.2. */ /* Bison implementation for Yacc-like parsers in C @@ -67,18 +68,16 @@ /* First part of user prologue. */ -#line 28 "ExpressionParser.y" - - -#define YYSTYPE App::ExpressionParser::semantic_type - -std::stack functions; /**< Function identifier */ - - //#define YYSTYPE yystype - #define yyparse ExpressionParser_yyparse - #define yyerror ExpressionParser_yyerror +#line 26 "Expression.y" -#line 82 "ExpressionParser.tab.c" +#define YYSTYPE App::ExpressionParser::semantic_type + +std::stack functions; /**< Function identifier */ + +#define yyparse ExpressionParser_yyparse +#define yyerror ExpressionParser_yyerror + +#line 80 "Expression.tab.c" # ifndef YY_CAST # ifdef __cplusplus @@ -101,7 +100,7 @@ std::stack functions; /**< Function # endif # endif -#include "ExpressionParser.tab.h" +#include "Expression.tab.h" /* Symbol kind. */ enum yysymbol_kind_t { @@ -555,14 +554,14 @@ static const yytype_int8 yytranslate[] = /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ static const yytype_uint8 yyrline[] = { - 0, 86, 86, 87, 90, 91, 94, 95, 96, 97, - 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, - 108, 109, 110, 113, 114, 115, 116, 118, 119, 120, - 121, 122, 123, 126, 129, 130, 131, 132, 133, 134, - 135, 138, 139, 141, 142, 143, 144, 145, 146, 147, - 150, 151, 155, 156, 160, 161, 165, 170, 175, 181, - 188, 195, 202, 206, 207, 208, 209, 210, 211, 212, - 213, 217, 218, 219, 223, 224, 228, 229 + 0, 81, 81, 82, 85, 86, 89, 90, 91, 92, + 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, + 103, 104, 105, 108, 109, 110, 111, 113, 114, 115, + 116, 117, 118, 121, 124, 125, 126, 127, 128, 129, + 130, 133, 134, 136, 137, 138, 139, 140, 141, 142, + 145, 146, 150, 151, 155, 156, 160, 165, 170, 176, + 183, 190, 197, 201, 202, 203, 204, 205, 206, 207, + 208, 212, 213, 214, 218, 219, 223, 224 }; #endif @@ -1008,51 +1007,51 @@ yydestruct (const char *yymsg, switch (yykind) { case YYSYMBOL_exp: /* exp */ -#line 78 "ExpressionParser.y" +#line 73 "Expression.y" { delete ((*yyvaluep).expr); } -#line 1014 "ExpressionParser.tab.c" +#line 1012 "Expression.tab.c" break; case YYSYMBOL_num: /* num */ -#line 78 "ExpressionParser.y" +#line 73 "Expression.y" { delete ((*yyvaluep).expr); } -#line 1020 "ExpressionParser.tab.c" +#line 1018 "Expression.tab.c" break; case YYSYMBOL_args: /* args */ -#line 80 "ExpressionParser.y" +#line 75 "Expression.y" { std::vector::const_iterator i = ((*yyvaluep).arguments).begin(); while (i != ((*yyvaluep).arguments).end()) { delete *i; ++i; } } -#line 1026 "ExpressionParser.tab.c" +#line 1024 "Expression.tab.c" break; case YYSYMBOL_range: /* range */ -#line 78 "ExpressionParser.y" +#line 73 "Expression.y" { delete ((*yyvaluep).expr); } -#line 1032 "ExpressionParser.tab.c" +#line 1030 "Expression.tab.c" break; case YYSYMBOL_cond: /* cond */ -#line 78 "ExpressionParser.y" +#line 73 "Expression.y" { delete ((*yyvaluep).expr); } -#line 1038 "ExpressionParser.tab.c" +#line 1036 "Expression.tab.c" break; case YYSYMBOL_unit_exp: /* unit_exp */ -#line 78 "ExpressionParser.y" +#line 73 "Expression.y" { delete ((*yyvaluep).expr); } -#line 1044 "ExpressionParser.tab.c" +#line 1042 "Expression.tab.c" break; case YYSYMBOL_indexer: /* indexer */ -#line 79 "ExpressionParser.y" +#line 74 "Expression.y" { delete ((*yyvaluep).component); } -#line 1050 "ExpressionParser.tab.c" +#line 1048 "Expression.tab.c" break; case YYSYMBOL_indexable: /* indexable */ -#line 78 "ExpressionParser.y" +#line 73 "Expression.y" { delete ((*yyvaluep).expr); } -#line 1056 "ExpressionParser.tab.c" +#line 1054 "Expression.tab.c" break; default: @@ -1320,362 +1319,362 @@ yyreduce: switch (yyn) { case 2: /* input: exp */ -#line 86 "ExpressionParser.y" +#line 81 "Expression.y" { ScanResult = (yyvsp[0].expr); valueExpression = true; } -#line 1326 "ExpressionParser.tab.c" +#line 1324 "Expression.tab.c" break; case 3: /* input: unit_exp */ -#line 87 "ExpressionParser.y" +#line 82 "Expression.y" { ScanResult = (yyvsp[0].expr); unitExpression = true; } -#line 1332 "ExpressionParser.tab.c" +#line 1330 "Expression.tab.c" break; case 4: /* unit_num: num unit_exp */ -#line 90 "ExpressionParser.y" +#line 85 "Expression.y" { (yyval.expr) = new OperatorExpression(DocumentObject, (yyvsp[-1].expr), OperatorExpression::UNIT, (yyvsp[0].expr)); } -#line 1338 "ExpressionParser.tab.c" +#line 1336 "Expression.tab.c" break; case 5: /* unit_num: num us_building_unit num us_building_unit */ -#line 91 "ExpressionParser.y" +#line 86 "Expression.y" { (yyval.expr) = new OperatorExpression(DocumentObject, new OperatorExpression(DocumentObject, (yyvsp[-3].expr), OperatorExpression::UNIT, (yyvsp[-2].expr)), OperatorExpression::ADD, new OperatorExpression(DocumentObject, (yyvsp[-1].expr), OperatorExpression::UNIT, (yyvsp[0].expr)));} -#line 1344 "ExpressionParser.tab.c" +#line 1342 "Expression.tab.c" break; case 6: /* exp: num */ -#line 94 "ExpressionParser.y" +#line 89 "Expression.y" { (yyval.expr) = (yyvsp[0].expr); } -#line 1350 "ExpressionParser.tab.c" +#line 1348 "Expression.tab.c" break; case 7: /* exp: unit_num */ -#line 95 "ExpressionParser.y" +#line 90 "Expression.y" { (yyval.expr) = (yyvsp[0].expr); } -#line 1356 "ExpressionParser.tab.c" +#line 1354 "Expression.tab.c" break; case 8: /* exp: STRING */ -#line 96 "ExpressionParser.y" +#line 91 "Expression.y" { (yyval.expr) = new StringExpression(DocumentObject, (yyvsp[0].string)); } -#line 1362 "ExpressionParser.tab.c" +#line 1360 "Expression.tab.c" break; case 9: /* exp: identifier */ -#line 97 "ExpressionParser.y" +#line 92 "Expression.y" { (yyval.expr) = new VariableExpression(DocumentObject, (yyvsp[0].path)); } -#line 1368 "ExpressionParser.tab.c" +#line 1366 "Expression.tab.c" break; case 10: /* exp: MINUSSIGN exp */ -#line 98 "ExpressionParser.y" +#line 93 "Expression.y" { (yyval.expr) = new OperatorExpression(DocumentObject, (yyvsp[0].expr), OperatorExpression::NEG, new NumberExpression(DocumentObject, Quantity(-1))); } -#line 1374 "ExpressionParser.tab.c" +#line 1372 "Expression.tab.c" break; case 11: /* exp: '+' exp */ -#line 99 "ExpressionParser.y" +#line 94 "Expression.y" { (yyval.expr) = new OperatorExpression(DocumentObject, (yyvsp[0].expr), OperatorExpression::POS, new NumberExpression(DocumentObject, Quantity(1))); } -#line 1380 "ExpressionParser.tab.c" +#line 1378 "Expression.tab.c" break; case 12: /* exp: exp '+' exp */ -#line 100 "ExpressionParser.y" +#line 95 "Expression.y" { (yyval.expr) = new OperatorExpression(DocumentObject, (yyvsp[-2].expr), OperatorExpression::ADD, (yyvsp[0].expr)); } -#line 1386 "ExpressionParser.tab.c" +#line 1384 "Expression.tab.c" break; case 13: /* exp: exp MINUSSIGN exp */ -#line 101 "ExpressionParser.y" +#line 96 "Expression.y" { (yyval.expr) = new OperatorExpression(DocumentObject, (yyvsp[-2].expr), OperatorExpression::SUB, (yyvsp[0].expr)); } -#line 1392 "ExpressionParser.tab.c" +#line 1390 "Expression.tab.c" break; case 14: /* exp: exp '*' exp */ -#line 102 "ExpressionParser.y" +#line 97 "Expression.y" { (yyval.expr) = new OperatorExpression(DocumentObject, (yyvsp[-2].expr), OperatorExpression::MUL, (yyvsp[0].expr)); } -#line 1398 "ExpressionParser.tab.c" +#line 1396 "Expression.tab.c" break; case 15: /* exp: exp '/' exp */ -#line 103 "ExpressionParser.y" +#line 98 "Expression.y" { (yyval.expr) = new OperatorExpression(DocumentObject, (yyvsp[-2].expr), OperatorExpression::DIV, (yyvsp[0].expr)); } -#line 1404 "ExpressionParser.tab.c" +#line 1402 "Expression.tab.c" break; case 16: /* exp: exp '%' exp */ -#line 104 "ExpressionParser.y" +#line 99 "Expression.y" { (yyval.expr) = new OperatorExpression(DocumentObject, (yyvsp[-2].expr), OperatorExpression::MOD, (yyvsp[0].expr)); } -#line 1410 "ExpressionParser.tab.c" +#line 1408 "Expression.tab.c" break; case 17: /* exp: exp '/' unit_exp */ -#line 105 "ExpressionParser.y" +#line 100 "Expression.y" { (yyval.expr) = new OperatorExpression(DocumentObject, (yyvsp[-2].expr), OperatorExpression::DIV, (yyvsp[0].expr)); } -#line 1416 "ExpressionParser.tab.c" +#line 1414 "Expression.tab.c" break; case 18: /* exp: exp '^' exp */ -#line 106 "ExpressionParser.y" +#line 101 "Expression.y" { (yyval.expr) = new OperatorExpression(DocumentObject, (yyvsp[-2].expr), OperatorExpression::POW, (yyvsp[0].expr)); } -#line 1422 "ExpressionParser.tab.c" +#line 1420 "Expression.tab.c" break; case 19: /* exp: indexable */ -#line 107 "ExpressionParser.y" +#line 102 "Expression.y" { (yyval.expr) = (yyvsp[0].expr); } -#line 1428 "ExpressionParser.tab.c" +#line 1426 "Expression.tab.c" break; case 20: /* exp: FUNC args ')' */ -#line 108 "ExpressionParser.y" +#line 103 "Expression.y" { (yyval.expr) = new FunctionExpression(DocumentObject, (yyvsp[-2].func).first, std::move((yyvsp[-2].func).second), (yyvsp[-1].arguments));} -#line 1434 "ExpressionParser.tab.c" +#line 1432 "Expression.tab.c" break; case 21: /* exp: cond '?' exp ':' exp */ -#line 109 "ExpressionParser.y" +#line 104 "Expression.y" { (yyval.expr) = new ConditionalExpression(DocumentObject, (yyvsp[-4].expr), (yyvsp[-2].expr), (yyvsp[0].expr)); } -#line 1440 "ExpressionParser.tab.c" +#line 1438 "Expression.tab.c" break; case 22: /* exp: '(' exp ')' */ -#line 110 "ExpressionParser.y" +#line 105 "Expression.y" { (yyval.expr) = (yyvsp[-1].expr); } -#line 1446 "ExpressionParser.tab.c" +#line 1444 "Expression.tab.c" break; case 23: /* num: ONE */ -#line 113 "ExpressionParser.y" +#line 108 "Expression.y" { (yyval.expr) = new NumberExpression(DocumentObject, Quantity((yyvsp[0].fvalue))); } -#line 1452 "ExpressionParser.tab.c" +#line 1450 "Expression.tab.c" break; case 24: /* num: NUM */ -#line 114 "ExpressionParser.y" +#line 109 "Expression.y" { (yyval.expr) = new NumberExpression(DocumentObject, Quantity((yyvsp[0].fvalue))); } -#line 1458 "ExpressionParser.tab.c" +#line 1456 "Expression.tab.c" break; case 25: /* num: INTEGER */ -#line 115 "ExpressionParser.y" +#line 110 "Expression.y" { (yyval.expr) = new NumberExpression(DocumentObject, Quantity((double)(yyvsp[0].ivalue))); } -#line 1464 "ExpressionParser.tab.c" +#line 1462 "Expression.tab.c" break; case 26: /* num: CONSTANT */ -#line 116 "ExpressionParser.y" +#line 111 "Expression.y" { (yyval.expr) = new ConstantExpression(DocumentObject, (yyvsp[0].constant).name, Quantity((yyvsp[0].constant).fvalue)); } -#line 1470 "ExpressionParser.tab.c" +#line 1468 "Expression.tab.c" break; case 27: /* args: exp */ -#line 118 "ExpressionParser.y" +#line 113 "Expression.y" { (yyval.arguments).push_back((yyvsp[0].expr)); } -#line 1476 "ExpressionParser.tab.c" +#line 1474 "Expression.tab.c" break; case 28: /* args: range */ -#line 119 "ExpressionParser.y" +#line 114 "Expression.y" { (yyval.arguments).push_back((yyvsp[0].expr)); } -#line 1482 "ExpressionParser.tab.c" +#line 1480 "Expression.tab.c" break; case 29: /* args: args ',' exp */ -#line 120 "ExpressionParser.y" +#line 115 "Expression.y" { (yyvsp[-2].arguments).push_back((yyvsp[0].expr)); (yyval.arguments) = (yyvsp[-2].arguments); } -#line 1488 "ExpressionParser.tab.c" +#line 1486 "Expression.tab.c" break; case 30: /* args: args ';' exp */ -#line 121 "ExpressionParser.y" +#line 116 "Expression.y" { (yyvsp[-2].arguments).push_back((yyvsp[0].expr)); (yyval.arguments) = (yyvsp[-2].arguments); } -#line 1494 "ExpressionParser.tab.c" +#line 1492 "Expression.tab.c" break; case 31: /* args: args ',' range */ -#line 122 "ExpressionParser.y" +#line 117 "Expression.y" { (yyvsp[-2].arguments).push_back((yyvsp[0].expr)); (yyval.arguments) = (yyvsp[-2].arguments); } -#line 1500 "ExpressionParser.tab.c" +#line 1498 "Expression.tab.c" break; case 32: /* args: args ';' range */ -#line 123 "ExpressionParser.y" +#line 118 "Expression.y" { (yyvsp[-2].arguments).push_back((yyvsp[0].expr)); (yyval.arguments) = (yyvsp[-2].arguments); } -#line 1506 "ExpressionParser.tab.c" +#line 1504 "Expression.tab.c" break; case 33: /* range: id_or_cell ':' id_or_cell */ -#line 126 "ExpressionParser.y" +#line 121 "Expression.y" { (yyval.expr) = new RangeExpression(DocumentObject, (yyvsp[-2].string), (yyvsp[0].string)); } -#line 1512 "ExpressionParser.tab.c" +#line 1510 "Expression.tab.c" break; case 34: /* cond: exp EQ exp */ -#line 129 "ExpressionParser.y" +#line 124 "Expression.y" { (yyval.expr) = new OperatorExpression(DocumentObject, (yyvsp[-2].expr), OperatorExpression::EQ, (yyvsp[0].expr)); } -#line 1518 "ExpressionParser.tab.c" +#line 1516 "Expression.tab.c" break; case 35: /* cond: exp NEQ exp */ -#line 130 "ExpressionParser.y" +#line 125 "Expression.y" { (yyval.expr) = new OperatorExpression(DocumentObject, (yyvsp[-2].expr), OperatorExpression::NEQ, (yyvsp[0].expr)); } -#line 1524 "ExpressionParser.tab.c" +#line 1522 "Expression.tab.c" break; case 36: /* cond: exp LT exp */ -#line 131 "ExpressionParser.y" +#line 126 "Expression.y" { (yyval.expr) = new OperatorExpression(DocumentObject, (yyvsp[-2].expr), OperatorExpression::LT, (yyvsp[0].expr)); } -#line 1530 "ExpressionParser.tab.c" +#line 1528 "Expression.tab.c" break; case 37: /* cond: exp GT exp */ -#line 132 "ExpressionParser.y" +#line 127 "Expression.y" { (yyval.expr) = new OperatorExpression(DocumentObject, (yyvsp[-2].expr), OperatorExpression::GT, (yyvsp[0].expr)); } -#line 1536 "ExpressionParser.tab.c" +#line 1534 "Expression.tab.c" break; case 38: /* cond: exp GTE exp */ -#line 133 "ExpressionParser.y" +#line 128 "Expression.y" { (yyval.expr) = new OperatorExpression(DocumentObject, (yyvsp[-2].expr), OperatorExpression::GTE, (yyvsp[0].expr)); } -#line 1542 "ExpressionParser.tab.c" +#line 1540 "Expression.tab.c" break; case 39: /* cond: exp LTE exp */ -#line 134 "ExpressionParser.y" +#line 129 "Expression.y" { (yyval.expr) = new OperatorExpression(DocumentObject, (yyvsp[-2].expr), OperatorExpression::LTE, (yyvsp[0].expr)); } -#line 1548 "ExpressionParser.tab.c" +#line 1546 "Expression.tab.c" break; case 40: /* cond: '(' cond ')' */ -#line 135 "ExpressionParser.y" +#line 130 "Expression.y" { (yyval.expr) = (yyvsp[-1].expr); } -#line 1554 "ExpressionParser.tab.c" +#line 1552 "Expression.tab.c" break; case 41: /* us_building_unit: USUNIT */ -#line 138 "ExpressionParser.y" - { (yyval.expr) = new UnitExpression(DocumentObject, (yyvsp[0].quantity).scaler, (yyvsp[0].quantity).unitStr ); } -#line 1560 "ExpressionParser.tab.c" +#line 133 "Expression.y" + { (yyval.expr) = new UnitExpression(DocumentObject, (yyvsp[0].quantity).scaler, (yyvsp[0].quantity).unitStr ); } +#line 1558 "Expression.tab.c" break; case 42: /* other_unit: UNIT */ -#line 139 "ExpressionParser.y" - { (yyval.expr) = new UnitExpression(DocumentObject, (yyvsp[0].quantity).scaler, (yyvsp[0].quantity).unitStr ); } -#line 1566 "ExpressionParser.tab.c" +#line 134 "Expression.y" + { (yyval.expr) = new UnitExpression(DocumentObject, (yyvsp[0].quantity).scaler, (yyvsp[0].quantity).unitStr ); } +#line 1564 "Expression.tab.c" break; case 43: /* unit_exp: other_unit */ -#line 141 "ExpressionParser.y" +#line 136 "Expression.y" { (yyval.expr) = (yyvsp[0].expr); } -#line 1572 "ExpressionParser.tab.c" +#line 1570 "Expression.tab.c" break; case 44: /* unit_exp: us_building_unit */ -#line 142 "ExpressionParser.y" +#line 137 "Expression.y" { (yyval.expr) = (yyvsp[0].expr); } -#line 1578 "ExpressionParser.tab.c" +#line 1576 "Expression.tab.c" break; case 45: /* unit_exp: unit_exp '/' unit_exp */ -#line 143 "ExpressionParser.y" +#line 138 "Expression.y" { (yyval.expr) = new OperatorExpression(DocumentObject, (yyvsp[-2].expr), OperatorExpression::DIV, (yyvsp[0].expr)); } -#line 1584 "ExpressionParser.tab.c" +#line 1582 "Expression.tab.c" break; case 46: /* unit_exp: unit_exp '*' unit_exp */ -#line 144 "ExpressionParser.y" +#line 139 "Expression.y" { (yyval.expr) = new OperatorExpression(DocumentObject, (yyvsp[-2].expr), OperatorExpression::MUL, (yyvsp[0].expr)); } -#line 1590 "ExpressionParser.tab.c" +#line 1588 "Expression.tab.c" break; case 47: /* unit_exp: unit_exp '^' integer */ -#line 145 "ExpressionParser.y" +#line 140 "Expression.y" { (yyval.expr) = new OperatorExpression(DocumentObject, (yyvsp[-2].expr), OperatorExpression::POW, new NumberExpression(DocumentObject, Quantity((double)(yyvsp[0].ivalue)))); } -#line 1596 "ExpressionParser.tab.c" +#line 1594 "Expression.tab.c" break; case 48: /* unit_exp: unit_exp '^' MINUSSIGN integer */ -#line 146 "ExpressionParser.y" +#line 141 "Expression.y" { (yyval.expr) = new OperatorExpression(DocumentObject, (yyvsp[-3].expr), OperatorExpression::POW, new OperatorExpression(DocumentObject, new NumberExpression(DocumentObject, Quantity((double)(yyvsp[0].ivalue))), OperatorExpression::NEG, new NumberExpression(DocumentObject, Quantity(-1)))); } -#line 1602 "ExpressionParser.tab.c" +#line 1600 "Expression.tab.c" break; case 49: /* unit_exp: '(' unit_exp ')' */ -#line 147 "ExpressionParser.y" +#line 142 "Expression.y" { (yyval.expr) = (yyvsp[-1].expr); } -#line 1608 "ExpressionParser.tab.c" +#line 1606 "Expression.tab.c" break; case 50: /* integer: INTEGER */ -#line 150 "ExpressionParser.y" +#line 145 "Expression.y" { (yyval.ivalue) = (yyvsp[0].ivalue); } -#line 1614 "ExpressionParser.tab.c" +#line 1612 "Expression.tab.c" break; case 51: /* integer: ONE */ -#line 151 "ExpressionParser.y" +#line 146 "Expression.y" { (yyval.ivalue) = (yyvsp[0].fvalue); } -#line 1620 "ExpressionParser.tab.c" +#line 1618 "Expression.tab.c" break; case 52: /* id_or_cell: IDENTIFIER */ -#line 155 "ExpressionParser.y" +#line 150 "Expression.y" { (yyval.string) = std::move((yyvsp[0].string)); } -#line 1626 "ExpressionParser.tab.c" +#line 1624 "Expression.tab.c" break; case 53: /* id_or_cell: CELLADDRESS */ -#line 156 "ExpressionParser.y" +#line 151 "Expression.y" { (yyval.string) = std::move((yyvsp[0].string)); } -#line 1632 "ExpressionParser.tab.c" +#line 1630 "Expression.tab.c" break; case 54: /* identifier: id_or_cell */ -#line 160 "ExpressionParser.y" +#line 155 "Expression.y" { (yyval.path) = ObjectIdentifier(DocumentObject); (yyval.path) << ObjectIdentifier::SimpleComponent((yyvsp[0].string)); } -#line 1638 "ExpressionParser.tab.c" +#line 1636 "Expression.tab.c" break; case 55: /* identifier: iden */ -#line 161 "ExpressionParser.y" +#line 156 "Expression.y" { (yyval.path) = std::move((yyvsp[0].path)); } -#line 1644 "ExpressionParser.tab.c" +#line 1642 "Expression.tab.c" break; case 56: /* iden: '.' STRING '.' id_or_cell */ -#line 165 "ExpressionParser.y" +#line 160 "Expression.y" { /* Path to property of a sub-object of the current object*/ (yyval.path) = ObjectIdentifier(DocumentObject,true); (yyval.path).setDocumentObjectName(DocumentObject,false,ObjectIdentifier::String(std::move((yyvsp[-2].string)),true),true); (yyval.path).addComponent(ObjectIdentifier::SimpleComponent((yyvsp[0].string))); } -#line 1654 "ExpressionParser.tab.c" +#line 1652 "Expression.tab.c" break; case 57: /* iden: '.' id_or_cell */ -#line 170 "ExpressionParser.y" +#line 165 "Expression.y" { /* Path to property of the current document object */ (yyval.path) = ObjectIdentifier(DocumentObject,true); (yyval.path).setDocumentObjectName(DocumentObject); (yyval.path).addComponent(ObjectIdentifier::SimpleComponent((yyvsp[0].string))); } -#line 1664 "ExpressionParser.tab.c" +#line 1662 "Expression.tab.c" break; case 58: /* iden: object '.' STRING '.' id_or_cell */ -#line 175 "ExpressionParser.y" +#line 170 "Expression.y" { /* Path to property of a sub-object */ (yyval.path) = ObjectIdentifier(DocumentObject); (yyval.path).setDocumentObjectName(std::move((yyvsp[-4].string_or_identifier)), true, ObjectIdentifier::String(std::move((yyvsp[-2].string)),true),true); (yyval.path).addComponent(ObjectIdentifier::SimpleComponent((yyvsp[0].string))); (yyval.path).resolveAmbiguity(); } -#line 1675 "ExpressionParser.tab.c" +#line 1673 "Expression.tab.c" break; case 59: /* iden: object '.' id_or_cell */ -#line 181 "ExpressionParser.y" +#line 176 "Expression.y" { /* Path to property of a given document object */ (yyval.path) = ObjectIdentifier(DocumentObject); (yyvsp[-2].string_or_identifier).checkImport(DocumentObject); @@ -1683,11 +1682,11 @@ yyreduce: (yyval.path).addComponent(ObjectIdentifier::SimpleComponent((yyvsp[0].string))); (yyval.path).resolveAmbiguity(); } -#line 1687 "ExpressionParser.tab.c" +#line 1685 "Expression.tab.c" break; case 60: /* iden: document '#' object '.' id_or_cell */ -#line 188 "ExpressionParser.y" +#line 183 "Expression.y" { /* Path to property from an external document, within a named document object */ (yyval.path) = ObjectIdentifier(DocumentObject); (yyval.path).setDocumentName(std::move((yyvsp[-4].string_or_identifier)), true); @@ -1695,118 +1694,118 @@ yyreduce: (yyval.path).addComponent(ObjectIdentifier::SimpleComponent((yyvsp[0].string))); (yyval.path).resolveAmbiguity(); } -#line 1699 "ExpressionParser.tab.c" +#line 1697 "Expression.tab.c" break; case 61: /* iden: document '#' object '.' STRING '.' id_or_cell */ -#line 196 "ExpressionParser.y" +#line 191 "Expression.y" { (yyval.path) = ObjectIdentifier(DocumentObject); (yyval.path).setDocumentName(std::move((yyvsp[-6].string_or_identifier)), true); (yyval.path).setDocumentObjectName(std::move((yyvsp[-4].string_or_identifier)), true, ObjectIdentifier::String(std::move((yyvsp[-2].string)),true)); (yyval.path).addComponent(ObjectIdentifier::SimpleComponent((yyvsp[0].string))); (yyval.path).resolveAmbiguity(); } -#line 1710 "ExpressionParser.tab.c" +#line 1708 "Expression.tab.c" break; case 62: /* iden: iden '.' IDENTIFIER */ -#line 202 "ExpressionParser.y" +#line 197 "Expression.y" { (yyval.path)= std::move((yyvsp[-2].path)); (yyval.path).addComponent(ObjectIdentifier::SimpleComponent((yyvsp[0].string))); } -#line 1716 "ExpressionParser.tab.c" +#line 1714 "Expression.tab.c" break; case 63: /* indexer: '[' exp ']' */ -#line 206 "ExpressionParser.y" +#line 201 "Expression.y" { (yyval.component) = Expression::createComponent((yyvsp[-1].expr)); } -#line 1722 "ExpressionParser.tab.c" +#line 1720 "Expression.tab.c" break; case 64: /* indexer: '[' exp ':' ']' */ -#line 207 "ExpressionParser.y" +#line 202 "Expression.y" { (yyval.component) = Expression::createComponent((yyvsp[-2].expr),0,0,true); } -#line 1728 "ExpressionParser.tab.c" +#line 1726 "Expression.tab.c" break; case 65: /* indexer: '[' ':' exp ']' */ -#line 208 "ExpressionParser.y" +#line 203 "Expression.y" { (yyval.component) = Expression::createComponent(0,(yyvsp[-1].expr)); } -#line 1734 "ExpressionParser.tab.c" +#line 1732 "Expression.tab.c" break; case 66: /* indexer: '[' ':' ':' exp ']' */ -#line 209 "ExpressionParser.y" +#line 204 "Expression.y" { (yyval.component) = Expression::createComponent(0,0,(yyvsp[-1].expr)); } -#line 1740 "ExpressionParser.tab.c" +#line 1738 "Expression.tab.c" break; case 67: /* indexer: '[' exp ':' exp ']' */ -#line 210 "ExpressionParser.y" +#line 205 "Expression.y" { (yyval.component) = Expression::createComponent((yyvsp[-3].expr),(yyvsp[-1].expr));} -#line 1746 "ExpressionParser.tab.c" +#line 1744 "Expression.tab.c" break; case 68: /* indexer: '[' exp ':' ':' exp ']' */ -#line 211 "ExpressionParser.y" +#line 206 "Expression.y" { (yyval.component) = Expression::createComponent((yyvsp[-4].expr),0,(yyvsp[-1].expr)); } -#line 1752 "ExpressionParser.tab.c" +#line 1750 "Expression.tab.c" break; case 69: /* indexer: '[' ':' exp ':' exp ']' */ -#line 212 "ExpressionParser.y" +#line 207 "Expression.y" { (yyval.component) = Expression::createComponent(0,(yyvsp[-3].expr),(yyvsp[-1].expr)); } -#line 1758 "ExpressionParser.tab.c" +#line 1756 "Expression.tab.c" break; case 70: /* indexer: '[' exp ':' exp ':' exp ']' */ -#line 213 "ExpressionParser.y" +#line 208 "Expression.y" { (yyval.component) = Expression::createComponent((yyvsp[-5].expr),(yyvsp[-3].expr),(yyvsp[-1].expr));} -#line 1764 "ExpressionParser.tab.c" +#line 1762 "Expression.tab.c" break; case 71: /* indexable: identifier indexer */ -#line 217 "ExpressionParser.y" +#line 212 "Expression.y" { (yyval.expr) = new VariableExpression(DocumentObject,(yyvsp[-1].path)); (yyval.expr)->addComponent((yyvsp[0].component)); } -#line 1770 "ExpressionParser.tab.c" +#line 1768 "Expression.tab.c" break; case 72: /* indexable: indexable indexer */ -#line 218 "ExpressionParser.y" +#line 213 "Expression.y" { (yyvsp[-1].expr)->addComponent(std::move((yyvsp[0].component))); (yyval.expr) = (yyvsp[-1].expr); } -#line 1776 "ExpressionParser.tab.c" +#line 1774 "Expression.tab.c" break; case 73: /* indexable: indexable '.' IDENTIFIER */ -#line 219 "ExpressionParser.y" +#line 214 "Expression.y" { (yyvsp[-2].expr)->addComponent(Expression::createComponent((yyvsp[0].string))); (yyval.expr) = (yyvsp[-2].expr); } -#line 1782 "ExpressionParser.tab.c" +#line 1780 "Expression.tab.c" break; case 74: /* document: STRING */ -#line 223 "ExpressionParser.y" +#line 218 "Expression.y" { (yyval.string_or_identifier) = ObjectIdentifier::String(std::move((yyvsp[0].string)), true); } -#line 1788 "ExpressionParser.tab.c" +#line 1786 "Expression.tab.c" break; case 75: /* document: IDENTIFIER */ -#line 224 "ExpressionParser.y" +#line 219 "Expression.y" { (yyval.string_or_identifier) = ObjectIdentifier::String(std::move((yyvsp[0].string)), false, true);} -#line 1794 "ExpressionParser.tab.c" +#line 1792 "Expression.tab.c" break; case 76: /* object: STRING */ -#line 228 "ExpressionParser.y" +#line 223 "Expression.y" { (yyval.string_or_identifier) = ObjectIdentifier::String(std::move((yyvsp[0].string)), true); } -#line 1800 "ExpressionParser.tab.c" +#line 1798 "Expression.tab.c" break; case 77: /* object: id_or_cell */ -#line 229 "ExpressionParser.y" +#line 224 "Expression.y" { (yyval.string_or_identifier) = ObjectIdentifier::String(std::move((yyvsp[0].string)), false);} -#line 1806 "ExpressionParser.tab.c" +#line 1804 "Expression.tab.c" break; -#line 1810 "ExpressionParser.tab.c" +#line 1808 "Expression.tab.c" default: break; } @@ -1999,5 +1998,4 @@ yyreturnlab: return yyresult; } -#line 232 "ExpressionParser.y" - +#line 227 "Expression.y" diff --git a/src/App/ExpressionParser.tab.h b/src/App/Expression.tab.h similarity index 95% rename from src/App/ExpressionParser.tab.h rename to src/App/Expression.tab.h index effb065853..dddad9207f 100644 --- a/src/App/ExpressionParser.tab.h +++ b/src/App/Expression.tab.h @@ -35,8 +35,8 @@ especially those whose name start with YY_ or yy_. They are private implementation details that can be changed or removed. */ -#ifndef YY_YY_EXPRESSIONPARSER_TAB_H_INCLUDED -# define YY_YY_EXPRESSIONPARSER_TAB_H_INCLUDED +#ifndef YY_YY_EXPRESSION_TAB_H_INCLUDED +# define YY_YY_EXPRESSION_TAB_H_INCLUDED /* Debug traces. */ #ifndef YYDEBUG # define YYDEBUG 0 @@ -91,4 +91,4 @@ extern YYSTYPE yylval; int yyparse (void); -#endif /* !YY_YY_EXPRESSIONPARSER_TAB_H_INCLUDED */ +#endif /* !YY_YY_EXPRESSION_TAB_H_INCLUDED */ diff --git a/src/App/ExpressionParser.y b/src/App/Expression.y similarity index 96% rename from src/App/ExpressionParser.y rename to src/App/Expression.y index 976d3eaa20..e1a90ebf56 100644 --- a/src/App/ExpressionParser.y +++ b/src/App/Expression.y @@ -1,231 +1,227 @@ -/*************************************************************************** - * Copyright (c) 2010 Jürgen Riegel * - * Copyright (c) 2015 Eivind Kvedalen * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU Library General Public License for more details. * - * * - * You should have received a copy of the GNU Library General Public * - * License along with this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ***************************************************************************/ - -/* Parser for the FreeCAD Units language */ -/* Represents the many different ways we can access our data */ - - -%{ - -#define YYSTYPE App::ExpressionParser::semantic_type - -std::stack functions; /**< Function identifier */ - - //#define YYSTYPE yystype - #define yyparse ExpressionParser_yyparse - #define yyerror ExpressionParser_yyerror -%} - - %token FUNC - %token ONE - %token NUM - %token IDENTIFIER - %token UNIT USUNIT - %token INTEGER - %token CONSTANT - %token CELLADDRESS - %token EQ NEQ LT GT GTE LTE - %token STRING MINUSSIGN PROPERTY_REF - %token DOCUMENT OBJECT - %token EXPONENT - %type args - %type input unit_num us_building_unit other_unit exp unit_exp cond indexable - %type UNIT USUNIT - %type id_or_cell STRING IDENTIFIER CELLADDRESS - %type INTEGER - %type PROPERTY_REF - %type ONE - %type NUM - %type CONSTANT - %type num - %type range - %type identifier iden - %type indexer - %type FUNC - %type document - %type object - %type integer - %precedence EQ NEQ LT GT GTE LTE - %precedence ':' - %left MINUSSIGN '+' - %left '*' '/' '%' - %precedence NUM_AND_UNIT - %left '^' - %precedence NEG - %precedence POS - -%destructor { delete $$; } num range exp cond unit_exp indexable -%destructor { delete $$; } -%destructor { std::vector::const_iterator i = $$.begin(); while (i != $$.end()) { delete *i; ++i; } } args - -%start input -%% - - -input: exp { ScanResult = $1; valueExpression = true; } - | unit_exp { ScanResult = $1; unitExpression = true; } - ; - -unit_num: num unit_exp %prec NUM_AND_UNIT { $$ = new OperatorExpression(DocumentObject, $1, OperatorExpression::UNIT, $2); } - | num us_building_unit num us_building_unit %prec NUM_AND_UNIT { $$ = new OperatorExpression(DocumentObject, new OperatorExpression(DocumentObject, $1, OperatorExpression::UNIT, $2), OperatorExpression::ADD, new OperatorExpression(DocumentObject, $3, OperatorExpression::UNIT, $4));} - ; - -exp: num { $$ = $1; } - | unit_num { $$ = $1; } - | STRING { $$ = new StringExpression(DocumentObject, $1); } - | identifier { $$ = new VariableExpression(DocumentObject, $1); } - | MINUSSIGN exp %prec NEG { $$ = new OperatorExpression(DocumentObject, $2, OperatorExpression::NEG, new NumberExpression(DocumentObject, Quantity(-1))); } - | '+' exp %prec POS { $$ = new OperatorExpression(DocumentObject, $2, OperatorExpression::POS, new NumberExpression(DocumentObject, Quantity(1))); } - | exp '+' exp { $$ = new OperatorExpression(DocumentObject, $1, OperatorExpression::ADD, $3); } - | exp MINUSSIGN exp { $$ = new OperatorExpression(DocumentObject, $1, OperatorExpression::SUB, $3); } - | exp '*' exp { $$ = new OperatorExpression(DocumentObject, $1, OperatorExpression::MUL, $3); } - | exp '/' exp { $$ = new OperatorExpression(DocumentObject, $1, OperatorExpression::DIV, $3); } - | exp '%' exp { $$ = new OperatorExpression(DocumentObject, $1, OperatorExpression::MOD, $3); } - | exp '/' unit_exp { $$ = new OperatorExpression(DocumentObject, $1, OperatorExpression::DIV, $3); } - | exp '^' exp { $$ = new OperatorExpression(DocumentObject, $1, OperatorExpression::POW, $3); } - | indexable { $$ = $1; } - | FUNC args ')' { $$ = new FunctionExpression(DocumentObject, $1.first, std::move($1.second), $2);} - | cond '?' exp ':' exp { $$ = new ConditionalExpression(DocumentObject, $1, $3, $5); } - | '(' exp ')' { $$ = $2; } - ; - -num: ONE { $$ = new NumberExpression(DocumentObject, Quantity($1)); } - | NUM { $$ = new NumberExpression(DocumentObject, Quantity($1)); } - | INTEGER { $$ = new NumberExpression(DocumentObject, Quantity((double)$1)); } - | CONSTANT { $$ = new ConstantExpression(DocumentObject, $1.name, Quantity($1.fvalue)); } - -args: exp { $$.push_back($1); } - | range { $$.push_back($1); } - | args ',' exp { $1.push_back($3); $$ = $1; } - | args ';' exp { $1.push_back($3); $$ = $1; } - | args ',' range { $1.push_back($3); $$ = $1; } - | args ';' range { $1.push_back($3); $$ = $1; } - ; - -range: id_or_cell ':' id_or_cell { $$ = new RangeExpression(DocumentObject, $1, $3); } - ; - -cond: exp EQ exp { $$ = new OperatorExpression(DocumentObject, $1, OperatorExpression::EQ, $3); } - | exp NEQ exp { $$ = new OperatorExpression(DocumentObject, $1, OperatorExpression::NEQ, $3); } - | exp LT exp { $$ = new OperatorExpression(DocumentObject, $1, OperatorExpression::LT, $3); } - | exp GT exp { $$ = new OperatorExpression(DocumentObject, $1, OperatorExpression::GT, $3); } - | exp GTE exp { $$ = new OperatorExpression(DocumentObject, $1, OperatorExpression::GTE, $3); } - | exp LTE exp { $$ = new OperatorExpression(DocumentObject, $1, OperatorExpression::LTE, $3); } - | '(' cond ')' { $$ = $2; } - ; - -us_building_unit: USUNIT { $$ = new UnitExpression(DocumentObject, $1.scaler, $1.unitStr ); } -other_unit: UNIT { $$ = new UnitExpression(DocumentObject, $1.scaler, $1.unitStr ); } - -unit_exp: other_unit { $$ = $1; } - | us_building_unit { $$ = $1; } - | unit_exp '/' unit_exp { $$ = new OperatorExpression(DocumentObject, $1, OperatorExpression::DIV, $3); } - | unit_exp '*' unit_exp { $$ = new OperatorExpression(DocumentObject, $1, OperatorExpression::MUL, $3); } - | unit_exp '^' integer { $$ = new OperatorExpression(DocumentObject, $1, OperatorExpression::POW, new NumberExpression(DocumentObject, Quantity((double)$3))); } - | unit_exp '^' MINUSSIGN integer { $$ = new OperatorExpression(DocumentObject, $1, OperatorExpression::POW, new OperatorExpression(DocumentObject, new NumberExpression(DocumentObject, Quantity((double)$4)), OperatorExpression::NEG, new NumberExpression(DocumentObject, Quantity(-1)))); } - | '(' unit_exp ')' { $$ = $2; } - ; - -integer: INTEGER { $$ = $1; } - | ONE { $$ = $1; } - ; - -id_or_cell - : IDENTIFIER { $$ = std::move($1); } - | CELLADDRESS { $$ = std::move($1); } - ; - -identifier - : id_or_cell { $$ = ObjectIdentifier(DocumentObject); $$ << ObjectIdentifier::SimpleComponent($1); } - | iden { $$ = std::move($1); } - ; - -iden - : '.' STRING '.' id_or_cell { /* Path to property of a sub-object of the current object*/ - $$ = ObjectIdentifier(DocumentObject,true); - $$.setDocumentObjectName(DocumentObject,false,ObjectIdentifier::String(std::move($2),true),true); - $$.addComponent(ObjectIdentifier::SimpleComponent($4)); - } - | '.' id_or_cell { /* Path to property of the current document object */ - $$ = ObjectIdentifier(DocumentObject,true); - $$.setDocumentObjectName(DocumentObject); - $$.addComponent(ObjectIdentifier::SimpleComponent($2)); - } - | object '.' STRING '.' id_or_cell { /* Path to property of a sub-object */ - $$ = ObjectIdentifier(DocumentObject); - $$.setDocumentObjectName(std::move($1), true, ObjectIdentifier::String(std::move($3),true),true); - $$.addComponent(ObjectIdentifier::SimpleComponent($5)); - $$.resolveAmbiguity(); - } - | object '.' id_or_cell { /* Path to property of a given document object */ - $$ = ObjectIdentifier(DocumentObject); - $1.checkImport(DocumentObject); - $$.addComponent(ObjectIdentifier::SimpleComponent($1)); - $$.addComponent(ObjectIdentifier::SimpleComponent($3)); - $$.resolveAmbiguity(); - } - | document '#' object '.' id_or_cell { /* Path to property from an external document, within a named document object */ - $$ = ObjectIdentifier(DocumentObject); - $$.setDocumentName(std::move($1), true); - $$.setDocumentObjectName(std::move($3), true); - $$.addComponent(ObjectIdentifier::SimpleComponent($5)); - $$.resolveAmbiguity(); - } - | document '#' object '.' STRING '.' id_or_cell - { $$ = ObjectIdentifier(DocumentObject); - $$.setDocumentName(std::move($1), true); - $$.setDocumentObjectName(std::move($3), true, ObjectIdentifier::String(std::move($5),true)); - $$.addComponent(ObjectIdentifier::SimpleComponent($7)); - $$.resolveAmbiguity(); - } - | iden '.' IDENTIFIER { $$= std::move($1); $$.addComponent(ObjectIdentifier::SimpleComponent($3)); } - ; - -indexer - : '[' exp ']' { $$ = Expression::createComponent($2); } - | '[' exp ':' ']' { $$ = Expression::createComponent($2,0,0,true); } - | '[' ':' exp ']' { $$ = Expression::createComponent(0,$3); } - | '[' ':' ':' exp ']' { $$ = Expression::createComponent(0,0,$4); } - | '[' exp ':' exp ']' { $$ = Expression::createComponent($2,$4);} - | '[' exp ':' ':' exp ']' { $$ = Expression::createComponent($2,0,$5); } - | '[' ':' exp ':' exp ']' { $$ = Expression::createComponent(0,$3,$5); } - | '[' exp ':' exp ':' exp ']' { $$ = Expression::createComponent($2,$4,$6);} - ; - -indexable - : identifier indexer { $$ = new VariableExpression(DocumentObject,$1); $$->addComponent($2); } - | indexable indexer { $1->addComponent(std::move($2)); $$ = $1; } - | indexable '.' IDENTIFIER { $1->addComponent(Expression::createComponent($3)); $$ = $1; } - ; - -document - : STRING { $$ = ObjectIdentifier::String(std::move($1), true); } - | IDENTIFIER { $$ = ObjectIdentifier::String(std::move($1), false, true);} - ; - -object - : STRING { $$ = ObjectIdentifier::String(std::move($1), true); } - | id_or_cell { $$ = ObjectIdentifier::String(std::move($1), false);} - ; - -%% +/*************************************************************************** + * Copyright (c) 2010 Jürgen Riegel * + * Copyright (c) 2015 Eivind Kvedalen * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +/* Parser for the FreeCAD Expression language */ + +%{ +#define YYSTYPE App::ExpressionParser::semantic_type + +std::stack functions; /**< Function identifier */ + +#define yyparse ExpressionParser_yyparse +#define yyerror ExpressionParser_yyerror +%} + + %token FUNC + %token ONE + %token NUM + %token IDENTIFIER + %token UNIT USUNIT + %token INTEGER + %token CONSTANT + %token CELLADDRESS + %token EQ NEQ LT GT GTE LTE + %token STRING MINUSSIGN PROPERTY_REF + %token DOCUMENT OBJECT + %token EXPONENT + %type args + %type input unit_num us_building_unit other_unit exp unit_exp cond indexable + %type UNIT USUNIT + %type id_or_cell STRING IDENTIFIER CELLADDRESS + %type INTEGER + %type PROPERTY_REF + %type ONE + %type NUM + %type CONSTANT + %type num + %type range + %type identifier iden + %type indexer + %type FUNC + %type document + %type object + %type integer + %precedence EQ NEQ LT GT GTE LTE + %precedence ':' + %left MINUSSIGN '+' + %left '*' '/' '%' + %precedence NUM_AND_UNIT + %left '^' + %precedence NEG + %precedence POS + +%destructor { delete $$; } num range exp cond unit_exp indexable +%destructor { delete $$; } +%destructor { std::vector::const_iterator i = $$.begin(); while (i != $$.end()) { delete *i; ++i; } } args + +%start input +%% + + +input: exp { ScanResult = $1; valueExpression = true; } + | unit_exp { ScanResult = $1; unitExpression = true; } + ; + +unit_num: num unit_exp %prec NUM_AND_UNIT { $$ = new OperatorExpression(DocumentObject, $1, OperatorExpression::UNIT, $2); } + | num us_building_unit num us_building_unit %prec NUM_AND_UNIT { $$ = new OperatorExpression(DocumentObject, new OperatorExpression(DocumentObject, $1, OperatorExpression::UNIT, $2), OperatorExpression::ADD, new OperatorExpression(DocumentObject, $3, OperatorExpression::UNIT, $4));} + ; + +exp: num { $$ = $1; } + | unit_num { $$ = $1; } + | STRING { $$ = new StringExpression(DocumentObject, $1); } + | identifier { $$ = new VariableExpression(DocumentObject, $1); } + | MINUSSIGN exp %prec NEG { $$ = new OperatorExpression(DocumentObject, $2, OperatorExpression::NEG, new NumberExpression(DocumentObject, Quantity(-1))); } + | '+' exp %prec POS { $$ = new OperatorExpression(DocumentObject, $2, OperatorExpression::POS, new NumberExpression(DocumentObject, Quantity(1))); } + | exp '+' exp { $$ = new OperatorExpression(DocumentObject, $1, OperatorExpression::ADD, $3); } + | exp MINUSSIGN exp { $$ = new OperatorExpression(DocumentObject, $1, OperatorExpression::SUB, $3); } + | exp '*' exp { $$ = new OperatorExpression(DocumentObject, $1, OperatorExpression::MUL, $3); } + | exp '/' exp { $$ = new OperatorExpression(DocumentObject, $1, OperatorExpression::DIV, $3); } + | exp '%' exp { $$ = new OperatorExpression(DocumentObject, $1, OperatorExpression::MOD, $3); } + | exp '/' unit_exp { $$ = new OperatorExpression(DocumentObject, $1, OperatorExpression::DIV, $3); } + | exp '^' exp { $$ = new OperatorExpression(DocumentObject, $1, OperatorExpression::POW, $3); } + | indexable { $$ = $1; } + | FUNC args ')' { $$ = new FunctionExpression(DocumentObject, $1.first, std::move($1.second), $2);} + | cond '?' exp ':' exp { $$ = new ConditionalExpression(DocumentObject, $1, $3, $5); } + | '(' exp ')' { $$ = $2; } + ; + +num: ONE { $$ = new NumberExpression(DocumentObject, Quantity($1)); } + | NUM { $$ = new NumberExpression(DocumentObject, Quantity($1)); } + | INTEGER { $$ = new NumberExpression(DocumentObject, Quantity((double)$1)); } + | CONSTANT { $$ = new ConstantExpression(DocumentObject, $1.name, Quantity($1.fvalue)); } + +args: exp { $$.push_back($1); } + | range { $$.push_back($1); } + | args ',' exp { $1.push_back($3); $$ = $1; } + | args ';' exp { $1.push_back($3); $$ = $1; } + | args ',' range { $1.push_back($3); $$ = $1; } + | args ';' range { $1.push_back($3); $$ = $1; } + ; + +range: id_or_cell ':' id_or_cell { $$ = new RangeExpression(DocumentObject, $1, $3); } + ; + +cond: exp EQ exp { $$ = new OperatorExpression(DocumentObject, $1, OperatorExpression::EQ, $3); } + | exp NEQ exp { $$ = new OperatorExpression(DocumentObject, $1, OperatorExpression::NEQ, $3); } + | exp LT exp { $$ = new OperatorExpression(DocumentObject, $1, OperatorExpression::LT, $3); } + | exp GT exp { $$ = new OperatorExpression(DocumentObject, $1, OperatorExpression::GT, $3); } + | exp GTE exp { $$ = new OperatorExpression(DocumentObject, $1, OperatorExpression::GTE, $3); } + | exp LTE exp { $$ = new OperatorExpression(DocumentObject, $1, OperatorExpression::LTE, $3); } + | '(' cond ')' { $$ = $2; } + ; + +us_building_unit: USUNIT { $$ = new UnitExpression(DocumentObject, $1.scaler, $1.unitStr ); } +other_unit: UNIT { $$ = new UnitExpression(DocumentObject, $1.scaler, $1.unitStr ); } + +unit_exp: other_unit { $$ = $1; } + | us_building_unit { $$ = $1; } + | unit_exp '/' unit_exp { $$ = new OperatorExpression(DocumentObject, $1, OperatorExpression::DIV, $3); } + | unit_exp '*' unit_exp { $$ = new OperatorExpression(DocumentObject, $1, OperatorExpression::MUL, $3); } + | unit_exp '^' integer { $$ = new OperatorExpression(DocumentObject, $1, OperatorExpression::POW, new NumberExpression(DocumentObject, Quantity((double)$3))); } + | unit_exp '^' MINUSSIGN integer { $$ = new OperatorExpression(DocumentObject, $1, OperatorExpression::POW, new OperatorExpression(DocumentObject, new NumberExpression(DocumentObject, Quantity((double)$4)), OperatorExpression::NEG, new NumberExpression(DocumentObject, Quantity(-1)))); } + | '(' unit_exp ')' { $$ = $2; } + ; + +integer: INTEGER { $$ = $1; } + | ONE { $$ = $1; } + ; + +id_or_cell + : IDENTIFIER { $$ = std::move($1); } + | CELLADDRESS { $$ = std::move($1); } + ; + +identifier + : id_or_cell { $$ = ObjectIdentifier(DocumentObject); $$ << ObjectIdentifier::SimpleComponent($1); } + | iden { $$ = std::move($1); } + ; + +iden + : '.' STRING '.' id_or_cell { /* Path to property of a sub-object of the current object*/ + $$ = ObjectIdentifier(DocumentObject,true); + $$.setDocumentObjectName(DocumentObject,false,ObjectIdentifier::String(std::move($2),true),true); + $$.addComponent(ObjectIdentifier::SimpleComponent($4)); + } + | '.' id_or_cell { /* Path to property of the current document object */ + $$ = ObjectIdentifier(DocumentObject,true); + $$.setDocumentObjectName(DocumentObject); + $$.addComponent(ObjectIdentifier::SimpleComponent($2)); + } + | object '.' STRING '.' id_or_cell { /* Path to property of a sub-object */ + $$ = ObjectIdentifier(DocumentObject); + $$.setDocumentObjectName(std::move($1), true, ObjectIdentifier::String(std::move($3),true),true); + $$.addComponent(ObjectIdentifier::SimpleComponent($5)); + $$.resolveAmbiguity(); + } + | object '.' id_or_cell { /* Path to property of a given document object */ + $$ = ObjectIdentifier(DocumentObject); + $1.checkImport(DocumentObject); + $$.addComponent(ObjectIdentifier::SimpleComponent($1)); + $$.addComponent(ObjectIdentifier::SimpleComponent($3)); + $$.resolveAmbiguity(); + } + | document '#' object '.' id_or_cell { /* Path to property from an external document, within a named document object */ + $$ = ObjectIdentifier(DocumentObject); + $$.setDocumentName(std::move($1), true); + $$.setDocumentObjectName(std::move($3), true); + $$.addComponent(ObjectIdentifier::SimpleComponent($5)); + $$.resolveAmbiguity(); + } + | document '#' object '.' STRING '.' id_or_cell + { $$ = ObjectIdentifier(DocumentObject); + $$.setDocumentName(std::move($1), true); + $$.setDocumentObjectName(std::move($3), true, ObjectIdentifier::String(std::move($5),true)); + $$.addComponent(ObjectIdentifier::SimpleComponent($7)); + $$.resolveAmbiguity(); + } + | iden '.' IDENTIFIER { $$= std::move($1); $$.addComponent(ObjectIdentifier::SimpleComponent($3)); } + ; + +indexer + : '[' exp ']' { $$ = Expression::createComponent($2); } + | '[' exp ':' ']' { $$ = Expression::createComponent($2,0,0,true); } + | '[' ':' exp ']' { $$ = Expression::createComponent(0,$3); } + | '[' ':' ':' exp ']' { $$ = Expression::createComponent(0,0,$4); } + | '[' exp ':' exp ']' { $$ = Expression::createComponent($2,$4);} + | '[' exp ':' ':' exp ']' { $$ = Expression::createComponent($2,0,$5); } + | '[' ':' exp ':' exp ']' { $$ = Expression::createComponent(0,$3,$5); } + | '[' exp ':' exp ':' exp ']' { $$ = Expression::createComponent($2,$4,$6);} + ; + +indexable + : identifier indexer { $$ = new VariableExpression(DocumentObject,$1); $$->addComponent($2); } + | indexable indexer { $1->addComponent(std::move($2)); $$ = $1; } + | indexable '.' IDENTIFIER { $1->addComponent(Expression::createComponent($3)); $$ = $1; } + ; + +document + : STRING { $$ = ObjectIdentifier::String(std::move($1), true); } + | IDENTIFIER { $$ = ObjectIdentifier::String(std::move($1), false, true);} + ; + +object + : STRING { $$ = ObjectIdentifier::String(std::move($1), true); } + | id_or_cell { $$ = ObjectIdentifier::String(std::move($1), false);} + ; + +%% diff --git a/src/App/ExpressionParser.h b/src/App/ExpressionParser.h index 3836d64a99..f9b8b7d8d5 100644 --- a/src/App/ExpressionParser.h +++ b/src/App/ExpressionParser.h @@ -649,7 +649,7 @@ public: }; #define YYSTYPE semantic_type -#include "ExpressionParser.tab.h" +#include "Expression.tab.h" #undef YYTOKENTYPE #undef YYSTYPE #undef YYSTYPE_ISDECLARED diff --git a/src/App/ExpressionParser.sh b/src/App/ExpressionParser.sh index bb12396b7a..dfa85af868 100755 --- a/src/App/ExpressionParser.sh +++ b/src/App/ExpressionParser.sh @@ -1,6 +1,8 @@ #!/usr/bin/env sh -cd "$(dirname "$0")" - -flex -v -olex.ExpressionParser.c ExpressionParser.l -bison -d -v -Wall -oExpressionParser.tab.c ExpressionParser.y +(cd "$(dirname "$0")" && \ + flex -v -oExpression.lex.c Expression.l && \ + bison -d -v -Wall -oExpression.tab.c Expression.y && \ + sed -i '1s|^|// clang-format off\n|' Expression.tab.c && \ + sed -i '1s|^|// clang-format off\n|' Expression.lex.c \ +)