swissChili | 729acd5 | 2024-03-05 11:52:45 -0500 | [diff] [blame^] | 1 | /* A Bison parser, made by GNU Bison 3.8.2. */ |
| 2 | |
| 3 | /* Bison implementation for Yacc-like parsers in C |
| 4 | |
| 5 | Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation, |
| 6 | Inc. |
| 7 | |
| 8 | This program is free software: you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation, either version 3 of the License, or |
| 11 | (at your option) any later version. |
| 12 | |
| 13 | This program is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with this program. If not, see <https://www.gnu.org/licenses/>. */ |
| 20 | |
| 21 | /* As a special exception, you may create a larger work that contains |
| 22 | part or all of the Bison parser skeleton and distribute that work |
| 23 | under terms of your choice, so long as that work isn't itself a |
| 24 | parser generator using the skeleton or a modified version thereof |
| 25 | as a parser skeleton. Alternatively, if you modify or redistribute |
| 26 | the parser skeleton itself, you may (at your option) remove this |
| 27 | special exception, which will cause the skeleton and the resulting |
| 28 | Bison output files to be licensed under the GNU General Public |
| 29 | License without this special exception. |
| 30 | |
| 31 | This special exception was added by the Free Software Foundation in |
| 32 | version 2.2 of Bison. */ |
| 33 | |
| 34 | /* C LALR(1) parser skeleton written by Richard Stallman, by |
| 35 | simplifying the original so-called "semantic" parser. */ |
| 36 | |
| 37 | /* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual, |
| 38 | especially those whose name start with YY_ or yy_. They are |
| 39 | private implementation details that can be changed or removed. */ |
| 40 | |
| 41 | /* All symbols defined below should begin with yy or YY, to avoid |
| 42 | infringing on user name space. This should be done even for local |
| 43 | variables, as they might otherwise be expanded by user macros. |
| 44 | There are some unavoidable exceptions within include files to |
| 45 | define necessary library symbols; they are noted "INFRINGES ON |
| 46 | USER NAME SPACE" below. */ |
| 47 | |
| 48 | /* Identify Bison output, and Bison version. */ |
| 49 | #define YYBISON 30802 |
| 50 | |
| 51 | /* Bison version string. */ |
| 52 | #define YYBISON_VERSION "3.8.2" |
| 53 | |
| 54 | /* Skeleton name. */ |
| 55 | #define YYSKELETON_NAME "yacc.c" |
| 56 | |
| 57 | /* Pure parsers. */ |
| 58 | #define YYPURE 2 |
| 59 | |
| 60 | /* Push parsers. */ |
| 61 | #define YYPUSH 0 |
| 62 | |
| 63 | /* Pull parsers. */ |
| 64 | #define YYPULL 1 |
| 65 | |
| 66 | /* Substitute the type names. */ |
| 67 | #define YYSTYPE UNITSSTYPE |
| 68 | /* Substitute the variable and function names. */ |
| 69 | #define yyparse unitsparse |
| 70 | #define yylex unitslex |
| 71 | #define yyerror unitserror |
| 72 | #define yydebug unitsdebug |
| 73 | #define yynerrs unitsnerrs |
| 74 | |
| 75 | /* First part of user prologue. */ |
| 76 | #line 24 "parse.y" |
| 77 | |
| 78 | #include<stdio.h> |
| 79 | #include<float.h> |
| 80 | #include "units.h" |
| 81 | |
| 82 | struct commtype { |
| 83 | int location; |
| 84 | const char *data; |
| 85 | struct unittype *result; |
| 86 | int errorcode; |
| 87 | }; |
| 88 | |
| 89 | static int err; /* value used by parser to store return values */ |
| 90 | |
| 91 | /* |
| 92 | The CHECK macro aborts parse if an error has occurred. It optionally |
| 93 | destroys a variable. Call with CHECK(0) if no variables need destruction |
| 94 | on error. |
| 95 | */ |
| 96 | |
| 97 | #define CHECK(var) if (err) { comm->errorcode=err; \ |
| 98 | if (var) destroyunit(var); \ |
| 99 | YYABORT; } |
| 100 | |
| 101 | int yylex(); |
| 102 | void yyerror(struct commtype *comm, char *); |
| 103 | |
| 104 | #define MAXMEM 100 |
| 105 | int unitcount=0; /* Counts the number of units allocated by the parser */ |
| 106 | |
| 107 | struct function { |
| 108 | char *name; |
| 109 | double (*func)(double); |
| 110 | int type; |
| 111 | }; |
| 112 | |
| 113 | #define DIMENSIONLESS 0 |
| 114 | #define ANGLEIN 1 |
| 115 | #define ANGLEOUT 2 |
| 116 | #define NATURAL 3 |
| 117 | |
| 118 | struct unittype * |
| 119 | getnewunit() |
| 120 | { |
| 121 | struct unittype *unit; |
| 122 | |
| 123 | if (unitcount>=MAXMEM) |
| 124 | return 0; |
| 125 | unit = (struct unittype *) |
| 126 | mymalloc(sizeof(struct unittype),"(getnewunit)"); |
| 127 | if (!unit) |
| 128 | return 0; |
| 129 | initializeunit(unit); |
| 130 | unitcount++; |
| 131 | return unit; |
| 132 | } |
| 133 | |
| 134 | |
| 135 | void |
| 136 | destroyunit(struct unittype *unit) |
| 137 | { |
| 138 | freeunit(unit); |
| 139 | free(unit); |
| 140 | unitcount--; |
| 141 | } |
| 142 | |
| 143 | |
| 144 | struct unittype * |
| 145 | makenumunit(double num,int *myerr) |
| 146 | { |
| 147 | struct unittype *ret; |
| 148 | ret=getnewunit(); |
| 149 | if (!ret){ |
| 150 | *myerr = E_PARSEMEM; |
| 151 | return 0; |
| 152 | } |
| 153 | ret->factor = num; |
| 154 | *myerr = 0; |
| 155 | return ret; |
| 156 | } |
| 157 | |
| 158 | int |
| 159 | logunit(struct unittype *theunit, int base) |
| 160 | { |
| 161 | if ((err=unit2num(theunit))) |
| 162 | return err; |
| 163 | if (base==2) |
| 164 | theunit->factor = log2(theunit->factor); |
| 165 | else if (base==10) |
| 166 | theunit->factor = log10(theunit->factor); |
| 167 | else |
| 168 | theunit->factor = log(theunit->factor)/log((double)base); |
| 169 | if (errno) |
| 170 | return E_FUNC; |
| 171 | return 0; |
| 172 | } |
| 173 | |
| 174 | int |
| 175 | funcunit(struct unittype *theunit, struct function const *fun) |
| 176 | { |
| 177 | struct unittype angleunit; |
| 178 | if (fun->type==ANGLEIN){ |
| 179 | err=unit2num(theunit); |
| 180 | if (err==E_NOTANUMBER){ |
| 181 | initializeunit(&angleunit); |
| 182 | angleunit.denominator[0] = dupstr("radian"); |
| 183 | angleunit.denominator[1] = 0; |
| 184 | err = multunit(theunit, &angleunit); |
| 185 | freeunit(&angleunit); |
| 186 | if (!err) |
| 187 | err = unit2num(theunit); |
| 188 | } |
| 189 | if (err) |
| 190 | return err; |
| 191 | } else if (fun->type==ANGLEOUT || fun->type == DIMENSIONLESS || fun->type == NATURAL) { |
| 192 | if ((err=unit2num(theunit))) |
| 193 | return err; |
| 194 | if (fun->type==NATURAL && (theunit->factor<0 || trunc(theunit->factor)!=theunit->factor)) |
| 195 | return E_NOTINDOMAIN; |
| 196 | } else |
| 197 | return E_BADFUNCTYPE; |
| 198 | errno = 0; |
| 199 | theunit->factor = (*(fun->func))(theunit->factor); |
| 200 | if (errno) |
| 201 | return E_FUNC; |
| 202 | if (fun->type==ANGLEOUT) { |
| 203 | theunit->numerator[0] = dupstr("radian"); |
| 204 | theunit->numerator[1] = 0; |
| 205 | } |
| 206 | return 0; |
| 207 | } |
| 208 | |
| 209 | |
| 210 | |
| 211 | #line 212 "parse.tab.c" |
| 212 | |
| 213 | # ifndef YY_CAST |
| 214 | # ifdef __cplusplus |
| 215 | # define YY_CAST(Type, Val) static_cast<Type> (Val) |
| 216 | # define YY_REINTERPRET_CAST(Type, Val) reinterpret_cast<Type> (Val) |
| 217 | # else |
| 218 | # define YY_CAST(Type, Val) ((Type) (Val)) |
| 219 | # define YY_REINTERPRET_CAST(Type, Val) ((Type) (Val)) |
| 220 | # endif |
| 221 | # endif |
| 222 | # ifndef YY_NULLPTR |
| 223 | # if defined __cplusplus |
| 224 | # if 201103L <= __cplusplus |
| 225 | # define YY_NULLPTR nullptr |
| 226 | # else |
| 227 | # define YY_NULLPTR 0 |
| 228 | # endif |
| 229 | # else |
| 230 | # define YY_NULLPTR ((void*)0) |
| 231 | # endif |
| 232 | # endif |
| 233 | |
| 234 | |
| 235 | /* Debug traces. */ |
| 236 | #ifndef UNITSDEBUG |
| 237 | # if defined YYDEBUG |
| 238 | #if YYDEBUG |
| 239 | # define UNITSDEBUG 1 |
| 240 | # else |
| 241 | # define UNITSDEBUG 0 |
| 242 | # endif |
| 243 | # else /* ! defined YYDEBUG */ |
| 244 | # define UNITSDEBUG 0 |
| 245 | # endif /* ! defined YYDEBUG */ |
| 246 | #endif /* ! defined UNITSDEBUG */ |
| 247 | #if UNITSDEBUG |
| 248 | extern int unitsdebug; |
| 249 | #endif |
| 250 | |
| 251 | /* Token kinds. */ |
| 252 | #ifndef UNITSTOKENTYPE |
| 253 | # define UNITSTOKENTYPE |
| 254 | enum unitstokentype |
| 255 | { |
| 256 | UNITSEMPTY = -2, |
| 257 | UNITSEOF = 0, /* "end of file" */ |
| 258 | UNITSerror = 256, /* error */ |
| 259 | UNITSUNDEF = 257, /* "invalid token" */ |
| 260 | REAL = 258, /* REAL */ |
| 261 | UNIT = 259, /* UNIT */ |
| 262 | REALFUNC = 260, /* REALFUNC */ |
| 263 | LOG = 261, /* LOG */ |
| 264 | UNITFUNC = 262, /* UNITFUNC */ |
| 265 | EXPONENT = 263, /* EXPONENT */ |
| 266 | MULTIPLY = 264, /* MULTIPLY */ |
| 267 | MULTSTAR = 265, /* MULTSTAR */ |
| 268 | DIVIDE = 266, /* DIVIDE */ |
| 269 | NUMDIV = 267, /* NUMDIV */ |
| 270 | SQRT = 268, /* SQRT */ |
| 271 | CUBEROOT = 269, /* CUBEROOT */ |
| 272 | MULTMINUS = 270, /* MULTMINUS */ |
| 273 | EOL = 271, /* EOL */ |
| 274 | FUNCINV = 272, /* FUNCINV */ |
| 275 | MEMERROR = 273, /* MEMERROR */ |
| 276 | BADNUMBER = 274, /* BADNUMBER */ |
| 277 | NUMOVERFLOW = 275, /* NUMOVERFLOW */ |
| 278 | NUMUNDERFLOW = 276, /* NUMUNDERFLOW */ |
| 279 | UNITEND = 277, /* UNITEND */ |
| 280 | LASTUNSET = 278, /* LASTUNSET */ |
| 281 | ADD = 279, /* ADD */ |
| 282 | MINUS = 280, /* MINUS */ |
| 283 | UNARY = 281 /* UNARY */ |
| 284 | }; |
| 285 | typedef enum unitstokentype unitstoken_kind_t; |
| 286 | #endif |
| 287 | |
| 288 | /* Value type. */ |
| 289 | #if ! defined UNITSSTYPE && ! defined UNITSSTYPE_IS_DECLARED |
| 290 | union UNITSSTYPE |
| 291 | { |
| 292 | #line 164 "parse.y" |
| 293 | |
| 294 | double number; |
| 295 | int integer; |
| 296 | struct unittype *unit; |
| 297 | struct function *realfunc; |
| 298 | struct func *unitfunc; |
| 299 | |
| 300 | #line 301 "parse.tab.c" |
| 301 | |
| 302 | }; |
| 303 | typedef union UNITSSTYPE UNITSSTYPE; |
| 304 | # define UNITSSTYPE_IS_TRIVIAL 1 |
| 305 | # define UNITSSTYPE_IS_DECLARED 1 |
| 306 | #endif |
| 307 | |
| 308 | |
| 309 | |
| 310 | |
| 311 | int unitsparse (struct commtype *comm); |
| 312 | |
| 313 | |
| 314 | |
| 315 | /* Symbol kind. */ |
| 316 | enum yysymbol_kind_t |
| 317 | { |
| 318 | YYSYMBOL_YYEMPTY = -2, |
| 319 | YYSYMBOL_YYEOF = 0, /* "end of file" */ |
| 320 | YYSYMBOL_YYerror = 1, /* error */ |
| 321 | YYSYMBOL_YYUNDEF = 2, /* "invalid token" */ |
| 322 | YYSYMBOL_REAL = 3, /* REAL */ |
| 323 | YYSYMBOL_UNIT = 4, /* UNIT */ |
| 324 | YYSYMBOL_REALFUNC = 5, /* REALFUNC */ |
| 325 | YYSYMBOL_LOG = 6, /* LOG */ |
| 326 | YYSYMBOL_UNITFUNC = 7, /* UNITFUNC */ |
| 327 | YYSYMBOL_EXPONENT = 8, /* EXPONENT */ |
| 328 | YYSYMBOL_MULTIPLY = 9, /* MULTIPLY */ |
| 329 | YYSYMBOL_MULTSTAR = 10, /* MULTSTAR */ |
| 330 | YYSYMBOL_DIVIDE = 11, /* DIVIDE */ |
| 331 | YYSYMBOL_NUMDIV = 12, /* NUMDIV */ |
| 332 | YYSYMBOL_SQRT = 13, /* SQRT */ |
| 333 | YYSYMBOL_CUBEROOT = 14, /* CUBEROOT */ |
| 334 | YYSYMBOL_MULTMINUS = 15, /* MULTMINUS */ |
| 335 | YYSYMBOL_EOL = 16, /* EOL */ |
| 336 | YYSYMBOL_FUNCINV = 17, /* FUNCINV */ |
| 337 | YYSYMBOL_MEMERROR = 18, /* MEMERROR */ |
| 338 | YYSYMBOL_BADNUMBER = 19, /* BADNUMBER */ |
| 339 | YYSYMBOL_NUMOVERFLOW = 20, /* NUMOVERFLOW */ |
| 340 | YYSYMBOL_NUMUNDERFLOW = 21, /* NUMUNDERFLOW */ |
| 341 | YYSYMBOL_UNITEND = 22, /* UNITEND */ |
| 342 | YYSYMBOL_LASTUNSET = 23, /* LASTUNSET */ |
| 343 | YYSYMBOL_ADD = 24, /* ADD */ |
| 344 | YYSYMBOL_MINUS = 25, /* MINUS */ |
| 345 | YYSYMBOL_UNARY = 26, /* UNARY */ |
| 346 | YYSYMBOL_27_ = 27, /* '(' */ |
| 347 | YYSYMBOL_28_ = 28, /* ')' */ |
| 348 | YYSYMBOL_YYACCEPT = 29, /* $accept */ |
| 349 | YYSYMBOL_input = 30, /* input */ |
| 350 | YYSYMBOL_unitexpr = 31, /* unitexpr */ |
| 351 | YYSYMBOL_divlist = 32, /* divlist */ |
| 352 | YYSYMBOL_expr = 33, /* expr */ |
| 353 | YYSYMBOL_numexpr = 34, /* numexpr */ |
| 354 | YYSYMBOL_pexpr = 35, /* pexpr */ |
| 355 | YYSYMBOL_list = 36 /* list */ |
| 356 | }; |
| 357 | typedef enum yysymbol_kind_t yysymbol_kind_t; |
| 358 | |
| 359 | |
| 360 | |
| 361 | |
| 362 | #ifdef short |
| 363 | # undef short |
| 364 | #endif |
| 365 | |
| 366 | /* On compilers that do not define __PTRDIFF_MAX__ etc., make sure |
| 367 | <limits.h> and (if available) <stdint.h> are included |
| 368 | so that the code can choose integer types of a good width. */ |
| 369 | |
| 370 | #ifndef __PTRDIFF_MAX__ |
| 371 | # include <limits.h> /* INFRINGES ON USER NAME SPACE */ |
| 372 | # if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ |
| 373 | # include <stdint.h> /* INFRINGES ON USER NAME SPACE */ |
| 374 | # define YY_STDINT_H |
| 375 | # endif |
| 376 | #endif |
| 377 | |
| 378 | /* Narrow types that promote to a signed type and that can represent a |
| 379 | signed or unsigned integer of at least N bits. In tables they can |
| 380 | save space and decrease cache pressure. Promoting to a signed type |
| 381 | helps avoid bugs in integer arithmetic. */ |
| 382 | |
| 383 | #ifdef __INT_LEAST8_MAX__ |
| 384 | typedef __INT_LEAST8_TYPE__ yytype_int8; |
| 385 | #elif defined YY_STDINT_H |
| 386 | typedef int_least8_t yytype_int8; |
| 387 | #else |
| 388 | typedef signed char yytype_int8; |
| 389 | #endif |
| 390 | |
| 391 | #ifdef __INT_LEAST16_MAX__ |
| 392 | typedef __INT_LEAST16_TYPE__ yytype_int16; |
| 393 | #elif defined YY_STDINT_H |
| 394 | typedef int_least16_t yytype_int16; |
| 395 | #else |
| 396 | typedef short yytype_int16; |
| 397 | #endif |
| 398 | |
| 399 | /* Work around bug in HP-UX 11.23, which defines these macros |
| 400 | incorrectly for preprocessor constants. This workaround can likely |
| 401 | be removed in 2023, as HPE has promised support for HP-UX 11.23 |
| 402 | (aka HP-UX 11i v2) only through the end of 2022; see Table 2 of |
| 403 | <https://h20195.www2.hpe.com/V2/getpdf.aspx/4AA4-7673ENW.pdf>. */ |
| 404 | #ifdef __hpux |
| 405 | # undef UINT_LEAST8_MAX |
| 406 | # undef UINT_LEAST16_MAX |
| 407 | # define UINT_LEAST8_MAX 255 |
| 408 | # define UINT_LEAST16_MAX 65535 |
| 409 | #endif |
| 410 | |
| 411 | #if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__ |
| 412 | typedef __UINT_LEAST8_TYPE__ yytype_uint8; |
| 413 | #elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H \ |
| 414 | && UINT_LEAST8_MAX <= INT_MAX) |
| 415 | typedef uint_least8_t yytype_uint8; |
| 416 | #elif !defined __UINT_LEAST8_MAX__ && UCHAR_MAX <= INT_MAX |
| 417 | typedef unsigned char yytype_uint8; |
| 418 | #else |
| 419 | typedef short yytype_uint8; |
| 420 | #endif |
| 421 | |
| 422 | #if defined __UINT_LEAST16_MAX__ && __UINT_LEAST16_MAX__ <= __INT_MAX__ |
| 423 | typedef __UINT_LEAST16_TYPE__ yytype_uint16; |
| 424 | #elif (!defined __UINT_LEAST16_MAX__ && defined YY_STDINT_H \ |
| 425 | && UINT_LEAST16_MAX <= INT_MAX) |
| 426 | typedef uint_least16_t yytype_uint16; |
| 427 | #elif !defined __UINT_LEAST16_MAX__ && USHRT_MAX <= INT_MAX |
| 428 | typedef unsigned short yytype_uint16; |
| 429 | #else |
| 430 | typedef int yytype_uint16; |
| 431 | #endif |
| 432 | |
| 433 | #ifndef YYPTRDIFF_T |
| 434 | # if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__ |
| 435 | # define YYPTRDIFF_T __PTRDIFF_TYPE__ |
| 436 | # define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__ |
| 437 | # elif defined PTRDIFF_MAX |
| 438 | # ifndef ptrdiff_t |
| 439 | # include <stddef.h> /* INFRINGES ON USER NAME SPACE */ |
| 440 | # endif |
| 441 | # define YYPTRDIFF_T ptrdiff_t |
| 442 | # define YYPTRDIFF_MAXIMUM PTRDIFF_MAX |
| 443 | # else |
| 444 | # define YYPTRDIFF_T long |
| 445 | # define YYPTRDIFF_MAXIMUM LONG_MAX |
| 446 | # endif |
| 447 | #endif |
| 448 | |
| 449 | #ifndef YYSIZE_T |
| 450 | # ifdef __SIZE_TYPE__ |
| 451 | # define YYSIZE_T __SIZE_TYPE__ |
| 452 | # elif defined size_t |
| 453 | # define YYSIZE_T size_t |
| 454 | # elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ |
| 455 | # include <stddef.h> /* INFRINGES ON USER NAME SPACE */ |
| 456 | # define YYSIZE_T size_t |
| 457 | # else |
| 458 | # define YYSIZE_T unsigned |
| 459 | # endif |
| 460 | #endif |
| 461 | |
| 462 | #define YYSIZE_MAXIMUM \ |
| 463 | YY_CAST (YYPTRDIFF_T, \ |
| 464 | (YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1) \ |
| 465 | ? YYPTRDIFF_MAXIMUM \ |
| 466 | : YY_CAST (YYSIZE_T, -1))) |
| 467 | |
| 468 | #define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X)) |
| 469 | |
| 470 | |
| 471 | /* Stored state numbers (used for stacks). */ |
| 472 | typedef yytype_int8 yy_state_t; |
| 473 | |
| 474 | /* State numbers in computations. */ |
| 475 | typedef int yy_state_fast_t; |
| 476 | |
| 477 | #ifndef YY_ |
| 478 | # if defined YYENABLE_NLS && YYENABLE_NLS |
| 479 | # if ENABLE_NLS |
| 480 | # include <libintl.h> /* INFRINGES ON USER NAME SPACE */ |
| 481 | # define YY_(Msgid) dgettext ("bison-runtime", Msgid) |
| 482 | # endif |
| 483 | # endif |
| 484 | # ifndef YY_ |
| 485 | # define YY_(Msgid) Msgid |
| 486 | # endif |
| 487 | #endif |
| 488 | |
| 489 | |
| 490 | #ifndef YY_ATTRIBUTE_PURE |
| 491 | # if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__) |
| 492 | # define YY_ATTRIBUTE_PURE __attribute__ ((__pure__)) |
| 493 | # else |
| 494 | # define YY_ATTRIBUTE_PURE |
| 495 | # endif |
| 496 | #endif |
| 497 | |
| 498 | #ifndef YY_ATTRIBUTE_UNUSED |
| 499 | # if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__) |
| 500 | # define YY_ATTRIBUTE_UNUSED __attribute__ ((__unused__)) |
| 501 | # else |
| 502 | # define YY_ATTRIBUTE_UNUSED |
| 503 | # endif |
| 504 | #endif |
| 505 | |
| 506 | /* Suppress unused-variable warnings by "using" E. */ |
| 507 | #if ! defined lint || defined __GNUC__ |
| 508 | # define YY_USE(E) ((void) (E)) |
| 509 | #else |
| 510 | # define YY_USE(E) /* empty */ |
| 511 | #endif |
| 512 | |
| 513 | /* Suppress an incorrect diagnostic about yylval being uninitialized. */ |
| 514 | #if defined __GNUC__ && ! defined __ICC && 406 <= __GNUC__ * 100 + __GNUC_MINOR__ |
| 515 | # if __GNUC__ * 100 + __GNUC_MINOR__ < 407 |
| 516 | # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ |
| 517 | _Pragma ("GCC diagnostic push") \ |
| 518 | _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") |
| 519 | # else |
| 520 | # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ |
| 521 | _Pragma ("GCC diagnostic push") \ |
| 522 | _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") \ |
| 523 | _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") |
| 524 | # endif |
| 525 | # define YY_IGNORE_MAYBE_UNINITIALIZED_END \ |
| 526 | _Pragma ("GCC diagnostic pop") |
| 527 | #else |
| 528 | # define YY_INITIAL_VALUE(Value) Value |
| 529 | #endif |
| 530 | #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN |
| 531 | # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN |
| 532 | # define YY_IGNORE_MAYBE_UNINITIALIZED_END |
| 533 | #endif |
| 534 | #ifndef YY_INITIAL_VALUE |
| 535 | # define YY_INITIAL_VALUE(Value) /* Nothing. */ |
| 536 | #endif |
| 537 | |
| 538 | #if defined __cplusplus && defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__ |
| 539 | # define YY_IGNORE_USELESS_CAST_BEGIN \ |
| 540 | _Pragma ("GCC diagnostic push") \ |
| 541 | _Pragma ("GCC diagnostic ignored \"-Wuseless-cast\"") |
| 542 | # define YY_IGNORE_USELESS_CAST_END \ |
| 543 | _Pragma ("GCC diagnostic pop") |
| 544 | #endif |
| 545 | #ifndef YY_IGNORE_USELESS_CAST_BEGIN |
| 546 | # define YY_IGNORE_USELESS_CAST_BEGIN |
| 547 | # define YY_IGNORE_USELESS_CAST_END |
| 548 | #endif |
| 549 | |
| 550 | |
| 551 | #define YY_ASSERT(E) ((void) (0 && (E))) |
| 552 | |
| 553 | #if !defined yyoverflow |
| 554 | |
| 555 | /* The parser invokes alloca or malloc; define the necessary symbols. */ |
| 556 | |
| 557 | # ifdef YYSTACK_USE_ALLOCA |
| 558 | # if YYSTACK_USE_ALLOCA |
| 559 | # ifdef __GNUC__ |
| 560 | # define YYSTACK_ALLOC __builtin_alloca |
| 561 | # elif defined __BUILTIN_VA_ARG_INCR |
| 562 | # include <alloca.h> /* INFRINGES ON USER NAME SPACE */ |
| 563 | # elif defined _AIX |
| 564 | # define YYSTACK_ALLOC __alloca |
| 565 | # elif defined _MSC_VER |
| 566 | # include <malloc.h> /* INFRINGES ON USER NAME SPACE */ |
| 567 | # define alloca _alloca |
| 568 | # else |
| 569 | # define YYSTACK_ALLOC alloca |
| 570 | # if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS |
| 571 | # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */ |
| 572 | /* Use EXIT_SUCCESS as a witness for stdlib.h. */ |
| 573 | # ifndef EXIT_SUCCESS |
| 574 | # define EXIT_SUCCESS 0 |
| 575 | # endif |
| 576 | # endif |
| 577 | # endif |
| 578 | # endif |
| 579 | # endif |
| 580 | |
| 581 | # ifdef YYSTACK_ALLOC |
| 582 | /* Pacify GCC's 'empty if-body' warning. */ |
| 583 | # define YYSTACK_FREE(Ptr) do { /* empty */; } while (0) |
| 584 | # ifndef YYSTACK_ALLOC_MAXIMUM |
| 585 | /* The OS might guarantee only one guard page at the bottom of the stack, |
| 586 | and a page size can be as small as 4096 bytes. So we cannot safely |
| 587 | invoke alloca (N) if N exceeds 4096. Use a slightly smaller number |
| 588 | to allow for a few compiler-allocated temporary stack slots. */ |
| 589 | # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */ |
| 590 | # endif |
| 591 | # else |
| 592 | # define YYSTACK_ALLOC YYMALLOC |
| 593 | # define YYSTACK_FREE YYFREE |
| 594 | # ifndef YYSTACK_ALLOC_MAXIMUM |
| 595 | # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM |
| 596 | # endif |
| 597 | # if (defined __cplusplus && ! defined EXIT_SUCCESS \ |
| 598 | && ! ((defined YYMALLOC || defined malloc) \ |
| 599 | && (defined YYFREE || defined free))) |
| 600 | # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */ |
| 601 | # ifndef EXIT_SUCCESS |
| 602 | # define EXIT_SUCCESS 0 |
| 603 | # endif |
| 604 | # endif |
| 605 | # ifndef YYMALLOC |
| 606 | # define YYMALLOC malloc |
| 607 | # if ! defined malloc && ! defined EXIT_SUCCESS |
| 608 | void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ |
| 609 | # endif |
| 610 | # endif |
| 611 | # ifndef YYFREE |
| 612 | # define YYFREE free |
| 613 | # if ! defined free && ! defined EXIT_SUCCESS |
| 614 | void free (void *); /* INFRINGES ON USER NAME SPACE */ |
| 615 | # endif |
| 616 | # endif |
| 617 | # endif |
| 618 | #endif /* !defined yyoverflow */ |
| 619 | |
| 620 | #if (! defined yyoverflow \ |
| 621 | && (! defined __cplusplus \ |
| 622 | || (defined UNITSSTYPE_IS_TRIVIAL && UNITSSTYPE_IS_TRIVIAL))) |
| 623 | |
| 624 | /* A type that is properly aligned for any stack member. */ |
| 625 | union yyalloc |
| 626 | { |
| 627 | yy_state_t yyss_alloc; |
| 628 | YYSTYPE yyvs_alloc; |
| 629 | }; |
| 630 | |
| 631 | /* The size of the maximum gap between one aligned stack and the next. */ |
| 632 | # define YYSTACK_GAP_MAXIMUM (YYSIZEOF (union yyalloc) - 1) |
| 633 | |
| 634 | /* The size of an array large to enough to hold all stacks, each with |
| 635 | N elements. */ |
| 636 | # define YYSTACK_BYTES(N) \ |
| 637 | ((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE)) \ |
| 638 | + YYSTACK_GAP_MAXIMUM) |
| 639 | |
| 640 | # define YYCOPY_NEEDED 1 |
| 641 | |
| 642 | /* Relocate STACK from its old location to the new one. The |
| 643 | local variables YYSIZE and YYSTACKSIZE give the old and new number of |
| 644 | elements in the stack, and YYPTR gives the new location of the |
| 645 | stack. Advance YYPTR to a properly aligned location for the next |
| 646 | stack. */ |
| 647 | # define YYSTACK_RELOCATE(Stack_alloc, Stack) \ |
| 648 | do \ |
| 649 | { \ |
| 650 | YYPTRDIFF_T yynewbytes; \ |
| 651 | YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ |
| 652 | Stack = &yyptr->Stack_alloc; \ |
| 653 | yynewbytes = yystacksize * YYSIZEOF (*Stack) + YYSTACK_GAP_MAXIMUM; \ |
| 654 | yyptr += yynewbytes / YYSIZEOF (*yyptr); \ |
| 655 | } \ |
| 656 | while (0) |
| 657 | |
| 658 | #endif |
| 659 | |
| 660 | #if defined YYCOPY_NEEDED && YYCOPY_NEEDED |
| 661 | /* Copy COUNT objects from SRC to DST. The source and destination do |
| 662 | not overlap. */ |
| 663 | # ifndef YYCOPY |
| 664 | # if defined __GNUC__ && 1 < __GNUC__ |
| 665 | # define YYCOPY(Dst, Src, Count) \ |
| 666 | __builtin_memcpy (Dst, Src, YY_CAST (YYSIZE_T, (Count)) * sizeof (*(Src))) |
| 667 | # else |
| 668 | # define YYCOPY(Dst, Src, Count) \ |
| 669 | do \ |
| 670 | { \ |
| 671 | YYPTRDIFF_T yyi; \ |
| 672 | for (yyi = 0; yyi < (Count); yyi++) \ |
| 673 | (Dst)[yyi] = (Src)[yyi]; \ |
| 674 | } \ |
| 675 | while (0) |
| 676 | # endif |
| 677 | # endif |
| 678 | #endif /* !YYCOPY_NEEDED */ |
| 679 | |
| 680 | /* YYFINAL -- State number of the termination state. */ |
| 681 | #define YYFINAL 39 |
| 682 | /* YYLAST -- Last index in YYTABLE. */ |
| 683 | #define YYLAST 202 |
| 684 | |
| 685 | /* YYNTOKENS -- Number of terminals. */ |
| 686 | #define YYNTOKENS 29 |
| 687 | /* YYNNTS -- Number of nonterminals. */ |
| 688 | #define YYNNTS 8 |
| 689 | /* YYNRULES -- Number of rules. */ |
| 690 | #define YYNRULES 40 |
| 691 | /* YYNSTATES -- Number of states. */ |
| 692 | #define YYNSTATES 65 |
| 693 | |
| 694 | /* YYMAXUTOK -- Last valid token kind. */ |
| 695 | #define YYMAXUTOK 281 |
| 696 | |
| 697 | |
| 698 | /* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM |
| 699 | as returned by yylex, with out-of-bounds checking. */ |
| 700 | #define YYTRANSLATE(YYX) \ |
| 701 | (0 <= (YYX) && (YYX) <= YYMAXUTOK \ |
| 702 | ? YY_CAST (yysymbol_kind_t, yytranslate[YYX]) \ |
| 703 | : YYSYMBOL_YYUNDEF) |
| 704 | |
| 705 | /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM |
| 706 | as returned by yylex. */ |
| 707 | static const yytype_int8 yytranslate[] = |
| 708 | { |
| 709 | 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 710 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 711 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 712 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 713 | 27, 28, 2, 2, 2, 2, 2, 2, 2, 2, |
| 714 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 715 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 716 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 717 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 718 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 719 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 720 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 721 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 722 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 723 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 724 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 725 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 726 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 727 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 728 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 729 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 730 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 731 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 732 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 733 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 734 | 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, |
| 735 | 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, |
| 736 | 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, |
| 737 | 25, 26 |
| 738 | }; |
| 739 | |
| 740 | #if UNITSDEBUG |
| 741 | /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ |
| 742 | static const yytype_int16 yyrline[] = |
| 743 | { |
| 744 | 0, 213, 213, 215, 216, 219, 220, 223, 224, 228, |
| 745 | 229, 230, 231, 233, 236, 238, 240, 244, 245, 248, |
| 746 | 254, 255, 256, 258, 260, 262, 263, 264, 265, 266, |
| 747 | 267, 268, 269, 272, 275, 276, 277, 278, 279, 280, |
| 748 | 281 |
| 749 | }; |
| 750 | #endif |
| 751 | |
| 752 | /** Accessing symbol of state STATE. */ |
| 753 | #define YY_ACCESSING_SYMBOL(State) YY_CAST (yysymbol_kind_t, yystos[State]) |
| 754 | |
| 755 | #if UNITSDEBUG || 0 |
| 756 | /* The user-facing name of the symbol whose (internal) number is |
| 757 | YYSYMBOL. No bounds checking. */ |
| 758 | static const char *yysymbol_name (yysymbol_kind_t yysymbol) YY_ATTRIBUTE_UNUSED; |
| 759 | |
| 760 | /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. |
| 761 | First, the terminals, then, starting at YYNTOKENS, nonterminals. */ |
| 762 | static const char *const yytname[] = |
| 763 | { |
| 764 | "\"end of file\"", "error", "\"invalid token\"", "REAL", "UNIT", |
| 765 | "REALFUNC", "LOG", "UNITFUNC", "EXPONENT", "MULTIPLY", "MULTSTAR", |
| 766 | "DIVIDE", "NUMDIV", "SQRT", "CUBEROOT", "MULTMINUS", "EOL", "FUNCINV", |
| 767 | "MEMERROR", "BADNUMBER", "NUMOVERFLOW", "NUMUNDERFLOW", "UNITEND", |
| 768 | "LASTUNSET", "ADD", "MINUS", "UNARY", "'('", "')'", "$accept", "input", |
| 769 | "unitexpr", "divlist", "expr", "numexpr", "pexpr", "list", YY_NULLPTR |
| 770 | }; |
| 771 | |
| 772 | static const char * |
| 773 | yysymbol_name (yysymbol_kind_t yysymbol) |
| 774 | { |
| 775 | return yytname[yysymbol]; |
| 776 | } |
| 777 | #endif |
| 778 | |
| 779 | #define YYPACT_NINF (-19) |
| 780 | |
| 781 | #define yypact_value_is_default(Yyn) \ |
| 782 | ((Yyn) == YYPACT_NINF) |
| 783 | |
| 784 | #define YYTABLE_NINF (-1) |
| 785 | |
| 786 | #define yytable_value_is_error(Yyn) \ |
| 787 | 0 |
| 788 | |
| 789 | /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing |
| 790 | STATE-NUM. */ |
| 791 | static const yytype_int16 yypact[] = |
| 792 | { |
| 793 | 50, -19, -19, -19, -18, -18, -18, 175, -18, -18, |
| 794 | 175, -19, 4, -19, -19, -19, -19, -19, -19, 175, |
| 795 | 75, 15, 8, 14, 12, 22, -19, 100, -19, -19, |
| 796 | -19, 100, -19, -19, 100, -19, -18, 100, 7, -19, |
| 797 | -19, -19, 75, 75, 75, 75, 75, 35, 125, 175, |
| 798 | 150, -19, -19, -19, 30, 30, 3, 3, -19, 175, |
| 799 | 175, 32, 150, 32, 32 |
| 800 | }; |
| 801 | |
| 802 | /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. |
| 803 | Performed when YYTABLE does not specify something else to do. Zero |
| 804 | means the default is an error. */ |
| 805 | static const yytype_int8 yydefact[] = |
| 806 | { |
| 807 | 0, 4, 17, 21, 0, 0, 0, 0, 0, 0, |
| 808 | 0, 2, 0, 37, 34, 35, 36, 38, 39, 0, |
| 809 | 0, 0, 0, 6, 5, 20, 25, 9, 28, 29, |
| 810 | 30, 7, 26, 27, 10, 40, 0, 11, 0, 1, |
| 811 | 3, 8, 0, 0, 0, 0, 0, 0, 0, 0, |
| 812 | 24, 31, 19, 15, 16, 14, 12, 13, 18, 0, |
| 813 | 0, 22, 23, 32, 33 |
| 814 | }; |
| 815 | |
| 816 | /* YYPGOTO[NTERM-NUM]. */ |
| 817 | static const yytype_int8 yypgoto[] = |
| 818 | { |
| 819 | -19, -19, -19, 41, -16, 5, -3, 0 |
| 820 | }; |
| 821 | |
| 822 | /* YYDEFGOTO[NTERM-NUM]. */ |
| 823 | static const yytype_int8 yydefgoto[] = |
| 824 | { |
| 825 | 0, 21, 22, 41, 24, 25, 26, 50 |
| 826 | }; |
| 827 | |
| 828 | /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If |
| 829 | positive, shift that token. If negative, reduce the rule whose |
| 830 | number is the opposite. If YYTABLE_NINF, syntax error. */ |
| 831 | static const yytype_int8 yytable[] = |
| 832 | { |
| 833 | 27, 28, 29, 30, 38, 32, 33, 31, 35, 20, |
| 834 | 34, 36, 42, 43, 44, 39, 42, 43, 44, 37, |
| 835 | 27, 42, 43, 44, 40, 7, 53, 54, 55, 56, |
| 836 | 57, 45, 46, 51, 47, 52, 45, 46, 2, 42, |
| 837 | 48, 23, 27, 27, 27, 27, 27, 0, 61, 62, |
| 838 | 0, 1, 58, 2, 3, 4, 5, 6, 0, 63, |
| 839 | 64, 7, 0, 8, 9, 10, 11, 12, 13, 14, |
| 840 | 15, 16, 17, 18, 0, 19, 0, 20, 2, 3, |
| 841 | 4, 5, 6, 0, 0, 0, 0, 0, 8, 9, |
| 842 | 10, 0, 12, 13, 14, 15, 16, 17, 18, 0, |
| 843 | 19, 0, 20, 2, 3, 4, 5, 6, 48, 0, |
| 844 | 0, 0, 0, 8, 9, 49, 0, 12, 13, 14, |
| 845 | 15, 16, 17, 18, 0, 0, 0, 20, 2, 3, |
| 846 | 4, 5, 6, 0, 0, 0, 0, 0, 8, 9, |
| 847 | 59, 0, 12, 13, 14, 15, 16, 17, 18, 0, |
| 848 | 60, 0, 20, 2, 3, 4, 5, 6, 48, 0, |
| 849 | 0, 0, 0, 8, 9, 0, 0, 12, 13, 14, |
| 850 | 15, 16, 17, 18, 0, 0, 0, 20, 2, 3, |
| 851 | 4, 5, 6, 0, 0, 0, 0, 0, 8, 9, |
| 852 | 0, 0, 12, 13, 14, 15, 16, 17, 18, 0, |
| 853 | 0, 0, 20 |
| 854 | }; |
| 855 | |
| 856 | static const yytype_int8 yycheck[] = |
| 857 | { |
| 858 | 0, 4, 5, 6, 20, 8, 9, 7, 4, 27, |
| 859 | 10, 7, 9, 10, 11, 0, 9, 10, 11, 19, |
| 860 | 20, 9, 10, 11, 16, 11, 42, 43, 44, 45, |
| 861 | 46, 24, 25, 36, 12, 28, 24, 25, 3, 9, |
| 862 | 8, 0, 42, 43, 44, 45, 46, -1, 48, 49, |
| 863 | -1, 1, 47, 3, 4, 5, 6, 7, -1, 59, |
| 864 | 60, 11, -1, 13, 14, 15, 16, 17, 18, 19, |
| 865 | 20, 21, 22, 23, -1, 25, -1, 27, 3, 4, |
| 866 | 5, 6, 7, -1, -1, -1, -1, -1, 13, 14, |
| 867 | 15, -1, 17, 18, 19, 20, 21, 22, 23, -1, |
| 868 | 25, -1, 27, 3, 4, 5, 6, 7, 8, -1, |
| 869 | -1, -1, -1, 13, 14, 15, -1, 17, 18, 19, |
| 870 | 20, 21, 22, 23, -1, -1, -1, 27, 3, 4, |
| 871 | 5, 6, 7, -1, -1, -1, -1, -1, 13, 14, |
| 872 | 15, -1, 17, 18, 19, 20, 21, 22, 23, -1, |
| 873 | 25, -1, 27, 3, 4, 5, 6, 7, 8, -1, |
| 874 | -1, -1, -1, 13, 14, -1, -1, 17, 18, 19, |
| 875 | 20, 21, 22, 23, -1, -1, -1, 27, 3, 4, |
| 876 | 5, 6, 7, -1, -1, -1, -1, -1, 13, 14, |
| 877 | -1, -1, 17, 18, 19, 20, 21, 22, 23, -1, |
| 878 | -1, -1, 27 |
| 879 | }; |
| 880 | |
| 881 | /* YYSTOS[STATE-NUM] -- The symbol kind of the accessing symbol of |
| 882 | state STATE-NUM. */ |
| 883 | static const yytype_int8 yystos[] = |
| 884 | { |
| 885 | 0, 1, 3, 4, 5, 6, 7, 11, 13, 14, |
| 886 | 15, 16, 17, 18, 19, 20, 21, 22, 23, 25, |
| 887 | 27, 30, 31, 32, 33, 34, 35, 36, 35, 35, |
| 888 | 35, 36, 35, 35, 36, 4, 7, 36, 33, 0, |
| 889 | 16, 32, 9, 10, 11, 24, 25, 12, 8, 15, |
| 890 | 36, 35, 28, 33, 33, 33, 33, 33, 34, 15, |
| 891 | 25, 36, 36, 36, 36 |
| 892 | }; |
| 893 | |
| 894 | /* YYR1[RULE-NUM] -- Symbol kind of the left-hand side of rule RULE-NUM. */ |
| 895 | static const yytype_int8 yyr1[] = |
| 896 | { |
| 897 | 0, 29, 30, 30, 30, 31, 31, 32, 32, 33, |
| 898 | 33, 33, 33, 33, 33, 33, 33, 34, 34, 35, |
| 899 | 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, |
| 900 | 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, |
| 901 | 36 |
| 902 | }; |
| 903 | |
| 904 | /* YYR2[RULE-NUM] -- Number of symbols on the right-hand side of rule RULE-NUM. */ |
| 905 | static const yytype_int8 yyr2[] = |
| 906 | { |
| 907 | 0, 2, 1, 2, 1, 1, 1, 2, 2, 1, |
| 908 | 2, 2, 3, 3, 3, 3, 3, 1, 3, 3, |
| 909 | 1, 1, 3, 3, 2, 1, 2, 2, 2, 2, |
| 910 | 2, 3, 4, 4, 1, 1, 1, 1, 1, 1, |
| 911 | 2 |
| 912 | }; |
| 913 | |
| 914 | |
| 915 | enum { YYENOMEM = -2 }; |
| 916 | |
| 917 | #define yyerrok (yyerrstatus = 0) |
| 918 | #define yyclearin (yychar = UNITSEMPTY) |
| 919 | |
| 920 | #define YYACCEPT goto yyacceptlab |
| 921 | #define YYABORT goto yyabortlab |
| 922 | #define YYERROR goto yyerrorlab |
| 923 | #define YYNOMEM goto yyexhaustedlab |
| 924 | |
| 925 | |
| 926 | #define YYRECOVERING() (!!yyerrstatus) |
| 927 | |
| 928 | #define YYBACKUP(Token, Value) \ |
| 929 | do \ |
| 930 | if (yychar == UNITSEMPTY) \ |
| 931 | { \ |
| 932 | yychar = (Token); \ |
| 933 | yylval = (Value); \ |
| 934 | YYPOPSTACK (yylen); \ |
| 935 | yystate = *yyssp; \ |
| 936 | goto yybackup; \ |
| 937 | } \ |
| 938 | else \ |
| 939 | { \ |
| 940 | yyerror (comm, YY_("syntax error: cannot back up")); \ |
| 941 | YYERROR; \ |
| 942 | } \ |
| 943 | while (0) |
| 944 | |
| 945 | /* Backward compatibility with an undocumented macro. |
| 946 | Use UNITSerror or UNITSUNDEF. */ |
| 947 | #define YYERRCODE UNITSUNDEF |
| 948 | |
| 949 | |
| 950 | /* Enable debugging if requested. */ |
| 951 | #if UNITSDEBUG |
| 952 | |
| 953 | # ifndef YYFPRINTF |
| 954 | # include <stdio.h> /* INFRINGES ON USER NAME SPACE */ |
| 955 | # define YYFPRINTF fprintf |
| 956 | # endif |
| 957 | |
| 958 | # define YYDPRINTF(Args) \ |
| 959 | do { \ |
| 960 | if (yydebug) \ |
| 961 | YYFPRINTF Args; \ |
| 962 | } while (0) |
| 963 | |
| 964 | |
| 965 | |
| 966 | |
| 967 | # define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \ |
| 968 | do { \ |
| 969 | if (yydebug) \ |
| 970 | { \ |
| 971 | YYFPRINTF (stderr, "%s ", Title); \ |
| 972 | yy_symbol_print (stderr, \ |
| 973 | Kind, Value, comm); \ |
| 974 | YYFPRINTF (stderr, "\n"); \ |
| 975 | } \ |
| 976 | } while (0) |
| 977 | |
| 978 | |
| 979 | /*-----------------------------------. |
| 980 | | Print this symbol's value on YYO. | |
| 981 | `-----------------------------------*/ |
| 982 | |
| 983 | static void |
| 984 | yy_symbol_value_print (FILE *yyo, |
| 985 | yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep, struct commtype *comm) |
| 986 | { |
| 987 | FILE *yyoutput = yyo; |
| 988 | YY_USE (yyoutput); |
| 989 | YY_USE (comm); |
| 990 | if (!yyvaluep) |
| 991 | return; |
| 992 | YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN |
| 993 | YY_USE (yykind); |
| 994 | YY_IGNORE_MAYBE_UNINITIALIZED_END |
| 995 | } |
| 996 | |
| 997 | |
| 998 | /*---------------------------. |
| 999 | | Print this symbol on YYO. | |
| 1000 | `---------------------------*/ |
| 1001 | |
| 1002 | static void |
| 1003 | yy_symbol_print (FILE *yyo, |
| 1004 | yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep, struct commtype *comm) |
| 1005 | { |
| 1006 | YYFPRINTF (yyo, "%s %s (", |
| 1007 | yykind < YYNTOKENS ? "token" : "nterm", yysymbol_name (yykind)); |
| 1008 | |
| 1009 | yy_symbol_value_print (yyo, yykind, yyvaluep, comm); |
| 1010 | YYFPRINTF (yyo, ")"); |
| 1011 | } |
| 1012 | |
| 1013 | /*------------------------------------------------------------------. |
| 1014 | | yy_stack_print -- Print the state stack from its BOTTOM up to its | |
| 1015 | | TOP (included). | |
| 1016 | `------------------------------------------------------------------*/ |
| 1017 | |
| 1018 | static void |
| 1019 | yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop) |
| 1020 | { |
| 1021 | YYFPRINTF (stderr, "Stack now"); |
| 1022 | for (; yybottom <= yytop; yybottom++) |
| 1023 | { |
| 1024 | int yybot = *yybottom; |
| 1025 | YYFPRINTF (stderr, " %d", yybot); |
| 1026 | } |
| 1027 | YYFPRINTF (stderr, "\n"); |
| 1028 | } |
| 1029 | |
| 1030 | # define YY_STACK_PRINT(Bottom, Top) \ |
| 1031 | do { \ |
| 1032 | if (yydebug) \ |
| 1033 | yy_stack_print ((Bottom), (Top)); \ |
| 1034 | } while (0) |
| 1035 | |
| 1036 | |
| 1037 | /*------------------------------------------------. |
| 1038 | | Report that the YYRULE is going to be reduced. | |
| 1039 | `------------------------------------------------*/ |
| 1040 | |
| 1041 | static void |
| 1042 | yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp, |
| 1043 | int yyrule, struct commtype *comm) |
| 1044 | { |
| 1045 | int yylno = yyrline[yyrule]; |
| 1046 | int yynrhs = yyr2[yyrule]; |
| 1047 | int yyi; |
| 1048 | YYFPRINTF (stderr, "Reducing stack by rule %d (line %d):\n", |
| 1049 | yyrule - 1, yylno); |
| 1050 | /* The symbols being reduced. */ |
| 1051 | for (yyi = 0; yyi < yynrhs; yyi++) |
| 1052 | { |
| 1053 | YYFPRINTF (stderr, " $%d = ", yyi + 1); |
| 1054 | yy_symbol_print (stderr, |
| 1055 | YY_ACCESSING_SYMBOL (+yyssp[yyi + 1 - yynrhs]), |
| 1056 | &yyvsp[(yyi + 1) - (yynrhs)], comm); |
| 1057 | YYFPRINTF (stderr, "\n"); |
| 1058 | } |
| 1059 | } |
| 1060 | |
| 1061 | # define YY_REDUCE_PRINT(Rule) \ |
| 1062 | do { \ |
| 1063 | if (yydebug) \ |
| 1064 | yy_reduce_print (yyssp, yyvsp, Rule, comm); \ |
| 1065 | } while (0) |
| 1066 | |
| 1067 | /* Nonzero means print parse trace. It is left uninitialized so that |
| 1068 | multiple parsers can coexist. */ |
| 1069 | int yydebug; |
| 1070 | #else /* !UNITSDEBUG */ |
| 1071 | # define YYDPRINTF(Args) ((void) 0) |
| 1072 | # define YY_SYMBOL_PRINT(Title, Kind, Value, Location) |
| 1073 | # define YY_STACK_PRINT(Bottom, Top) |
| 1074 | # define YY_REDUCE_PRINT(Rule) |
| 1075 | #endif /* !UNITSDEBUG */ |
| 1076 | |
| 1077 | |
| 1078 | /* YYINITDEPTH -- initial size of the parser's stacks. */ |
| 1079 | #ifndef YYINITDEPTH |
| 1080 | # define YYINITDEPTH 200 |
| 1081 | #endif |
| 1082 | |
| 1083 | /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only |
| 1084 | if the built-in stack extension method is used). |
| 1085 | |
| 1086 | Do not make this value too large; the results are undefined if |
| 1087 | YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH) |
| 1088 | evaluated with infinite-precision integer arithmetic. */ |
| 1089 | |
| 1090 | #ifndef YYMAXDEPTH |
| 1091 | # define YYMAXDEPTH 10000 |
| 1092 | #endif |
| 1093 | |
| 1094 | |
| 1095 | |
| 1096 | |
| 1097 | |
| 1098 | |
| 1099 | /*-----------------------------------------------. |
| 1100 | | Release the memory associated to this symbol. | |
| 1101 | `-----------------------------------------------*/ |
| 1102 | |
| 1103 | static void |
| 1104 | yydestruct (const char *yymsg, |
| 1105 | yysymbol_kind_t yykind, YYSTYPE *yyvaluep, struct commtype *comm) |
| 1106 | { |
| 1107 | YY_USE (yyvaluep); |
| 1108 | YY_USE (comm); |
| 1109 | if (!yymsg) |
| 1110 | yymsg = "Deleting"; |
| 1111 | YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp); |
| 1112 | |
| 1113 | YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN |
| 1114 | switch (yykind) |
| 1115 | { |
| 1116 | case YYSYMBOL_UNIT: /* UNIT */ |
| 1117 | #line 201 "parse.y" |
| 1118 | { destroyunit(((*yyvaluep).unit));} |
| 1119 | #line 1120 "parse.tab.c" |
| 1120 | break; |
| 1121 | |
| 1122 | case YYSYMBOL_unitexpr: /* unitexpr */ |
| 1123 | #line 201 "parse.y" |
| 1124 | { destroyunit(((*yyvaluep).unit));} |
| 1125 | #line 1126 "parse.tab.c" |
| 1126 | break; |
| 1127 | |
| 1128 | case YYSYMBOL_divlist: /* divlist */ |
| 1129 | #line 201 "parse.y" |
| 1130 | { destroyunit(((*yyvaluep).unit));} |
| 1131 | #line 1132 "parse.tab.c" |
| 1132 | break; |
| 1133 | |
| 1134 | case YYSYMBOL_expr: /* expr */ |
| 1135 | #line 201 "parse.y" |
| 1136 | { destroyunit(((*yyvaluep).unit));} |
| 1137 | #line 1138 "parse.tab.c" |
| 1138 | break; |
| 1139 | |
| 1140 | case YYSYMBOL_pexpr: /* pexpr */ |
| 1141 | #line 201 "parse.y" |
| 1142 | { destroyunit(((*yyvaluep).unit));} |
| 1143 | #line 1144 "parse.tab.c" |
| 1144 | break; |
| 1145 | |
| 1146 | case YYSYMBOL_list: /* list */ |
| 1147 | #line 201 "parse.y" |
| 1148 | { destroyunit(((*yyvaluep).unit));} |
| 1149 | #line 1150 "parse.tab.c" |
| 1150 | break; |
| 1151 | |
| 1152 | default: |
| 1153 | break; |
| 1154 | } |
| 1155 | YY_IGNORE_MAYBE_UNINITIALIZED_END |
| 1156 | } |
| 1157 | |
| 1158 | |
| 1159 | |
| 1160 | |
| 1161 | |
| 1162 | |
| 1163 | /*----------. |
| 1164 | | yyparse. | |
| 1165 | `----------*/ |
| 1166 | |
| 1167 | int |
| 1168 | yyparse (struct commtype *comm) |
| 1169 | { |
| 1170 | /* Lookahead token kind. */ |
| 1171 | int yychar; |
| 1172 | |
| 1173 | |
| 1174 | /* The semantic value of the lookahead symbol. */ |
| 1175 | /* Default value used for initialization, for pacifying older GCCs |
| 1176 | or non-GCC compilers. */ |
| 1177 | YY_INITIAL_VALUE (static YYSTYPE yyval_default;) |
| 1178 | YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default); |
| 1179 | |
| 1180 | /* Number of syntax errors so far. */ |
| 1181 | int yynerrs = 0; |
| 1182 | |
| 1183 | yy_state_fast_t yystate = 0; |
| 1184 | /* Number of tokens to shift before error messages enabled. */ |
| 1185 | int yyerrstatus = 0; |
| 1186 | |
| 1187 | /* Refer to the stacks through separate pointers, to allow yyoverflow |
| 1188 | to reallocate them elsewhere. */ |
| 1189 | |
| 1190 | /* Their size. */ |
| 1191 | YYPTRDIFF_T yystacksize = YYINITDEPTH; |
| 1192 | |
| 1193 | /* The state stack: array, bottom, top. */ |
| 1194 | yy_state_t yyssa[YYINITDEPTH]; |
| 1195 | yy_state_t *yyss = yyssa; |
| 1196 | yy_state_t *yyssp = yyss; |
| 1197 | |
| 1198 | /* The semantic value stack: array, bottom, top. */ |
| 1199 | YYSTYPE yyvsa[YYINITDEPTH]; |
| 1200 | YYSTYPE *yyvs = yyvsa; |
| 1201 | YYSTYPE *yyvsp = yyvs; |
| 1202 | |
| 1203 | int yyn; |
| 1204 | /* The return value of yyparse. */ |
| 1205 | int yyresult; |
| 1206 | /* Lookahead symbol kind. */ |
| 1207 | yysymbol_kind_t yytoken = YYSYMBOL_YYEMPTY; |
| 1208 | /* The variables used to return semantic value and location from the |
| 1209 | action routines. */ |
| 1210 | YYSTYPE yyval; |
| 1211 | |
| 1212 | |
| 1213 | |
| 1214 | #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)) |
| 1215 | |
| 1216 | /* The number of symbols on the RHS of the reduced rule. |
| 1217 | Keep to zero when no symbol should be popped. */ |
| 1218 | int yylen = 0; |
| 1219 | |
| 1220 | YYDPRINTF ((stderr, "Starting parse\n")); |
| 1221 | |
| 1222 | yychar = UNITSEMPTY; /* Cause a token to be read. */ |
| 1223 | |
| 1224 | goto yysetstate; |
| 1225 | |
| 1226 | |
| 1227 | /*------------------------------------------------------------. |
| 1228 | | yynewstate -- push a new state, which is found in yystate. | |
| 1229 | `------------------------------------------------------------*/ |
| 1230 | yynewstate: |
| 1231 | /* In all cases, when you get here, the value and location stacks |
| 1232 | have just been pushed. So pushing a state here evens the stacks. */ |
| 1233 | yyssp++; |
| 1234 | |
| 1235 | |
| 1236 | /*--------------------------------------------------------------------. |
| 1237 | | yysetstate -- set current state (the top of the stack) to yystate. | |
| 1238 | `--------------------------------------------------------------------*/ |
| 1239 | yysetstate: |
| 1240 | YYDPRINTF ((stderr, "Entering state %d\n", yystate)); |
| 1241 | YY_ASSERT (0 <= yystate && yystate < YYNSTATES); |
| 1242 | YY_IGNORE_USELESS_CAST_BEGIN |
| 1243 | *yyssp = YY_CAST (yy_state_t, yystate); |
| 1244 | YY_IGNORE_USELESS_CAST_END |
| 1245 | YY_STACK_PRINT (yyss, yyssp); |
| 1246 | |
| 1247 | if (yyss + yystacksize - 1 <= yyssp) |
| 1248 | #if !defined yyoverflow && !defined YYSTACK_RELOCATE |
| 1249 | YYNOMEM; |
| 1250 | #else |
| 1251 | { |
| 1252 | /* Get the current used size of the three stacks, in elements. */ |
| 1253 | YYPTRDIFF_T yysize = yyssp - yyss + 1; |
| 1254 | |
| 1255 | # if defined yyoverflow |
| 1256 | { |
| 1257 | /* Give user a chance to reallocate the stack. Use copies of |
| 1258 | these so that the &'s don't force the real ones into |
| 1259 | memory. */ |
| 1260 | yy_state_t *yyss1 = yyss; |
| 1261 | YYSTYPE *yyvs1 = yyvs; |
| 1262 | |
| 1263 | /* Each stack pointer address is followed by the size of the |
| 1264 | data in use in that stack, in bytes. This used to be a |
| 1265 | conditional around just the two extra args, but that might |
| 1266 | be undefined if yyoverflow is a macro. */ |
| 1267 | yyoverflow (YY_("memory exhausted"), |
| 1268 | &yyss1, yysize * YYSIZEOF (*yyssp), |
| 1269 | &yyvs1, yysize * YYSIZEOF (*yyvsp), |
| 1270 | &yystacksize); |
| 1271 | yyss = yyss1; |
| 1272 | yyvs = yyvs1; |
| 1273 | } |
| 1274 | # else /* defined YYSTACK_RELOCATE */ |
| 1275 | /* Extend the stack our own way. */ |
| 1276 | if (YYMAXDEPTH <= yystacksize) |
| 1277 | YYNOMEM; |
| 1278 | yystacksize *= 2; |
| 1279 | if (YYMAXDEPTH < yystacksize) |
| 1280 | yystacksize = YYMAXDEPTH; |
| 1281 | |
| 1282 | { |
| 1283 | yy_state_t *yyss1 = yyss; |
| 1284 | union yyalloc *yyptr = |
| 1285 | YY_CAST (union yyalloc *, |
| 1286 | YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize)))); |
| 1287 | if (! yyptr) |
| 1288 | YYNOMEM; |
| 1289 | YYSTACK_RELOCATE (yyss_alloc, yyss); |
| 1290 | YYSTACK_RELOCATE (yyvs_alloc, yyvs); |
| 1291 | # undef YYSTACK_RELOCATE |
| 1292 | if (yyss1 != yyssa) |
| 1293 | YYSTACK_FREE (yyss1); |
| 1294 | } |
| 1295 | # endif |
| 1296 | |
| 1297 | yyssp = yyss + yysize - 1; |
| 1298 | yyvsp = yyvs + yysize - 1; |
| 1299 | |
| 1300 | YY_IGNORE_USELESS_CAST_BEGIN |
| 1301 | YYDPRINTF ((stderr, "Stack size increased to %ld\n", |
| 1302 | YY_CAST (long, yystacksize))); |
| 1303 | YY_IGNORE_USELESS_CAST_END |
| 1304 | |
| 1305 | if (yyss + yystacksize - 1 <= yyssp) |
| 1306 | YYABORT; |
| 1307 | } |
| 1308 | #endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */ |
| 1309 | |
| 1310 | |
| 1311 | if (yystate == YYFINAL) |
| 1312 | YYACCEPT; |
| 1313 | |
| 1314 | goto yybackup; |
| 1315 | |
| 1316 | |
| 1317 | /*-----------. |
| 1318 | | yybackup. | |
| 1319 | `-----------*/ |
| 1320 | yybackup: |
| 1321 | /* Do appropriate processing given the current state. Read a |
| 1322 | lookahead token if we need one and don't already have one. */ |
| 1323 | |
| 1324 | /* First try to decide what to do without reference to lookahead token. */ |
| 1325 | yyn = yypact[yystate]; |
| 1326 | if (yypact_value_is_default (yyn)) |
| 1327 | goto yydefault; |
| 1328 | |
| 1329 | /* Not known => get a lookahead token if don't already have one. */ |
| 1330 | |
| 1331 | /* YYCHAR is either empty, or end-of-input, or a valid lookahead. */ |
| 1332 | if (yychar == UNITSEMPTY) |
| 1333 | { |
| 1334 | YYDPRINTF ((stderr, "Reading a token\n")); |
| 1335 | yychar = yylex (&yylval, comm); |
| 1336 | } |
| 1337 | |
| 1338 | if (yychar <= UNITSEOF) |
| 1339 | { |
| 1340 | yychar = UNITSEOF; |
| 1341 | yytoken = YYSYMBOL_YYEOF; |
| 1342 | YYDPRINTF ((stderr, "Now at end of input.\n")); |
| 1343 | } |
| 1344 | else if (yychar == UNITSerror) |
| 1345 | { |
| 1346 | /* The scanner already issued an error message, process directly |
| 1347 | to error recovery. But do not keep the error token as |
| 1348 | lookahead, it is too special and may lead us to an endless |
| 1349 | loop in error recovery. */ |
| 1350 | yychar = UNITSUNDEF; |
| 1351 | yytoken = YYSYMBOL_YYerror; |
| 1352 | goto yyerrlab1; |
| 1353 | } |
| 1354 | else |
| 1355 | { |
| 1356 | yytoken = YYTRANSLATE (yychar); |
| 1357 | YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); |
| 1358 | } |
| 1359 | |
| 1360 | /* If the proper action on seeing token YYTOKEN is to reduce or to |
| 1361 | detect an error, take that action. */ |
| 1362 | yyn += yytoken; |
| 1363 | if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) |
| 1364 | goto yydefault; |
| 1365 | yyn = yytable[yyn]; |
| 1366 | if (yyn <= 0) |
| 1367 | { |
| 1368 | if (yytable_value_is_error (yyn)) |
| 1369 | goto yyerrlab; |
| 1370 | yyn = -yyn; |
| 1371 | goto yyreduce; |
| 1372 | } |
| 1373 | |
| 1374 | /* Count tokens shifted since error; after three, turn off error |
| 1375 | status. */ |
| 1376 | if (yyerrstatus) |
| 1377 | yyerrstatus--; |
| 1378 | |
| 1379 | /* Shift the lookahead token. */ |
| 1380 | YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); |
| 1381 | yystate = yyn; |
| 1382 | YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN |
| 1383 | *++yyvsp = yylval; |
| 1384 | YY_IGNORE_MAYBE_UNINITIALIZED_END |
| 1385 | |
| 1386 | /* Discard the shifted token. */ |
| 1387 | yychar = UNITSEMPTY; |
| 1388 | goto yynewstate; |
| 1389 | |
| 1390 | |
| 1391 | /*-----------------------------------------------------------. |
| 1392 | | yydefault -- do the default action for the current state. | |
| 1393 | `-----------------------------------------------------------*/ |
| 1394 | yydefault: |
| 1395 | yyn = yydefact[yystate]; |
| 1396 | if (yyn == 0) |
| 1397 | goto yyerrlab; |
| 1398 | goto yyreduce; |
| 1399 | |
| 1400 | |
| 1401 | /*-----------------------------. |
| 1402 | | yyreduce -- do a reduction. | |
| 1403 | `-----------------------------*/ |
| 1404 | yyreduce: |
| 1405 | /* yyn is the number of a rule to reduce with. */ |
| 1406 | yylen = yyr2[yyn]; |
| 1407 | |
| 1408 | /* If YYLEN is nonzero, implement the default value of the action: |
| 1409 | '$$ = $1'. |
| 1410 | |
| 1411 | Otherwise, the following line sets YYVAL to garbage. |
| 1412 | This behavior is undocumented and Bison |
| 1413 | users should not rely upon it. Assigning to YYVAL |
| 1414 | unconditionally makes the parser a bit smaller, and it avoids a |
| 1415 | GCC warning that YYVAL may be used uninitialized. */ |
| 1416 | yyval = yyvsp[1-yylen]; |
| 1417 | |
| 1418 | |
| 1419 | YY_REDUCE_PRINT (yyn); |
| 1420 | switch (yyn) |
| 1421 | { |
| 1422 | case 2: /* input: EOL */ |
| 1423 | #line 213 "parse.y" |
| 1424 | { comm->result = makenumunit(1,&err); CHECK(0); |
| 1425 | comm->errorcode = 0; YYACCEPT; } |
| 1426 | #line 1427 "parse.tab.c" |
| 1427 | break; |
| 1428 | |
| 1429 | case 3: /* input: unitexpr EOL */ |
| 1430 | #line 215 "parse.y" |
| 1431 | { comm->result = (yyvsp[-1].unit); comm->errorcode = 0; YYACCEPT; } |
| 1432 | #line 1433 "parse.tab.c" |
| 1433 | break; |
| 1434 | |
| 1435 | case 4: /* input: error */ |
| 1436 | #line 216 "parse.y" |
| 1437 | { YYABORT; } |
| 1438 | #line 1439 "parse.tab.c" |
| 1439 | break; |
| 1440 | |
| 1441 | case 5: /* unitexpr: expr */ |
| 1442 | #line 219 "parse.y" |
| 1443 | { (yyval.unit) = (yyvsp[0].unit);} |
| 1444 | #line 1445 "parse.tab.c" |
| 1445 | break; |
| 1446 | |
| 1447 | case 6: /* unitexpr: divlist */ |
| 1448 | #line 220 "parse.y" |
| 1449 | { (yyval.unit) = (yyvsp[0].unit);} |
| 1450 | #line 1451 "parse.tab.c" |
| 1451 | break; |
| 1452 | |
| 1453 | case 7: /* divlist: DIVIDE list */ |
| 1454 | #line 223 "parse.y" |
| 1455 | { invertunit((yyvsp[0].unit)); (yyval.unit)=(yyvsp[0].unit);} |
| 1456 | #line 1457 "parse.tab.c" |
| 1457 | break; |
| 1458 | |
| 1459 | case 8: /* divlist: divlist divlist */ |
| 1460 | #line 224 "parse.y" |
| 1461 | {err = multunit((yyvsp[-1].unit),(yyvsp[0].unit)); destroyunit((yyvsp[0].unit)); |
| 1462 | CHECK((yyvsp[-1].unit));(yyval.unit)=(yyvsp[-1].unit);} |
| 1463 | #line 1464 "parse.tab.c" |
| 1464 | break; |
| 1465 | |
| 1466 | case 9: /* expr: list */ |
| 1467 | #line 228 "parse.y" |
| 1468 | { (yyval.unit) = (yyvsp[0].unit); } |
| 1469 | #line 1470 "parse.tab.c" |
| 1470 | break; |
| 1471 | |
| 1472 | case 10: /* expr: MULTMINUS list */ |
| 1473 | #line 229 "parse.y" |
| 1474 | { (yyval.unit) = (yyvsp[0].unit); (yyval.unit)->factor *= -1; } |
| 1475 | #line 1476 "parse.tab.c" |
| 1476 | break; |
| 1477 | |
| 1478 | case 11: /* expr: MINUS list */ |
| 1479 | #line 230 "parse.y" |
| 1480 | { (yyval.unit) = (yyvsp[0].unit); (yyval.unit)->factor *= -1; } |
| 1481 | #line 1482 "parse.tab.c" |
| 1482 | break; |
| 1483 | |
| 1484 | case 12: /* expr: expr ADD expr */ |
| 1485 | #line 231 "parse.y" |
| 1486 | { err = addunit((yyvsp[-2].unit),(yyvsp[0].unit)); destroyunit((yyvsp[0].unit)); |
| 1487 | CHECK((yyvsp[-2].unit));(yyval.unit)=(yyvsp[-2].unit);} |
| 1488 | #line 1489 "parse.tab.c" |
| 1489 | break; |
| 1490 | |
| 1491 | case 13: /* expr: expr MINUS expr */ |
| 1492 | #line 233 "parse.y" |
| 1493 | { (yyvsp[0].unit)->factor *= -1; |
| 1494 | err = addunit((yyvsp[-2].unit),(yyvsp[0].unit)); destroyunit((yyvsp[0].unit)); |
| 1495 | CHECK((yyvsp[-2].unit));(yyval.unit)=(yyvsp[-2].unit);} |
| 1496 | #line 1497 "parse.tab.c" |
| 1497 | break; |
| 1498 | |
| 1499 | case 14: /* expr: expr DIVIDE expr */ |
| 1500 | #line 236 "parse.y" |
| 1501 | { err = divunit((yyvsp[-2].unit), (yyvsp[0].unit)); destroyunit((yyvsp[0].unit)); |
| 1502 | CHECK((yyvsp[-2].unit));(yyval.unit)=(yyvsp[-2].unit);} |
| 1503 | #line 1504 "parse.tab.c" |
| 1504 | break; |
| 1505 | |
| 1506 | case 15: /* expr: expr MULTIPLY expr */ |
| 1507 | #line 238 "parse.y" |
| 1508 | { err = multunit((yyvsp[-2].unit),(yyvsp[0].unit)); destroyunit((yyvsp[0].unit)); |
| 1509 | CHECK((yyvsp[-2].unit));(yyval.unit)=(yyvsp[-2].unit);} |
| 1510 | #line 1511 "parse.tab.c" |
| 1511 | break; |
| 1512 | |
| 1513 | case 16: /* expr: expr MULTSTAR expr */ |
| 1514 | #line 240 "parse.y" |
| 1515 | { err = multunit((yyvsp[-2].unit),(yyvsp[0].unit)); destroyunit((yyvsp[0].unit)); |
| 1516 | CHECK((yyvsp[-2].unit));(yyval.unit)=(yyvsp[-2].unit);} |
| 1517 | #line 1518 "parse.tab.c" |
| 1518 | break; |
| 1519 | |
| 1520 | case 17: /* numexpr: REAL */ |
| 1521 | #line 244 "parse.y" |
| 1522 | { (yyval.number) = (yyvsp[0].number); } |
| 1523 | #line 1524 "parse.tab.c" |
| 1524 | break; |
| 1525 | |
| 1526 | case 18: /* numexpr: numexpr NUMDIV numexpr */ |
| 1527 | #line 245 "parse.y" |
| 1528 | { (yyval.number) = (yyvsp[-2].number) / (yyvsp[0].number); } |
| 1529 | #line 1530 "parse.tab.c" |
| 1530 | break; |
| 1531 | |
| 1532 | case 19: /* pexpr: '(' expr ')' */ |
| 1533 | #line 248 "parse.y" |
| 1534 | { (yyval.unit) = (yyvsp[-1].unit); } |
| 1535 | #line 1536 "parse.tab.c" |
| 1536 | break; |
| 1537 | |
| 1538 | case 20: /* list: numexpr */ |
| 1539 | #line 254 "parse.y" |
| 1540 | { (yyval.unit) = makenumunit((yyvsp[0].number),&err); CHECK(0);} |
| 1541 | #line 1542 "parse.tab.c" |
| 1542 | break; |
| 1543 | |
| 1544 | case 21: /* list: UNIT */ |
| 1545 | #line 255 "parse.y" |
| 1546 | { (yyval.unit) = (yyvsp[0].unit); } |
| 1547 | #line 1548 "parse.tab.c" |
| 1548 | break; |
| 1549 | |
| 1550 | case 22: /* list: list EXPONENT list */ |
| 1551 | #line 256 "parse.y" |
| 1552 | { err = unitpower((yyvsp[-2].unit),(yyvsp[0].unit));destroyunit((yyvsp[0].unit)); |
| 1553 | CHECK((yyvsp[-2].unit));(yyval.unit)=(yyvsp[-2].unit);} |
| 1554 | #line 1555 "parse.tab.c" |
| 1555 | break; |
| 1556 | |
| 1557 | case 23: /* list: list MULTMINUS list */ |
| 1558 | #line 258 "parse.y" |
| 1559 | { err = multunit((yyvsp[-2].unit),(yyvsp[0].unit)); destroyunit((yyvsp[0].unit)); |
| 1560 | CHECK((yyvsp[-2].unit));(yyval.unit)=(yyvsp[-2].unit);} |
| 1561 | #line 1562 "parse.tab.c" |
| 1562 | break; |
| 1563 | |
| 1564 | case 24: /* list: list list */ |
| 1565 | #line 260 "parse.y" |
| 1566 | { err = multunit((yyvsp[-1].unit),(yyvsp[0].unit)); destroyunit((yyvsp[0].unit)); |
| 1567 | CHECK((yyvsp[-1].unit));(yyval.unit)=(yyvsp[-1].unit);} |
| 1568 | #line 1569 "parse.tab.c" |
| 1569 | break; |
| 1570 | |
| 1571 | case 25: /* list: pexpr */ |
| 1572 | #line 262 "parse.y" |
| 1573 | { (yyval.unit)=(yyvsp[0].unit); } |
| 1574 | #line 1575 "parse.tab.c" |
| 1575 | break; |
| 1576 | |
| 1577 | case 26: /* list: SQRT pexpr */ |
| 1578 | #line 263 "parse.y" |
| 1579 | { err = rootunit((yyvsp[0].unit),2); CHECK((yyvsp[0].unit)); (yyval.unit)=(yyvsp[0].unit);} |
| 1580 | #line 1581 "parse.tab.c" |
| 1581 | break; |
| 1582 | |
| 1583 | case 27: /* list: CUBEROOT pexpr */ |
| 1584 | #line 264 "parse.y" |
| 1585 | { err = rootunit((yyvsp[0].unit),3); CHECK((yyvsp[0].unit)); (yyval.unit)=(yyvsp[0].unit);} |
| 1586 | #line 1587 "parse.tab.c" |
| 1587 | break; |
| 1588 | |
| 1589 | case 28: /* list: REALFUNC pexpr */ |
| 1590 | #line 265 "parse.y" |
| 1591 | { err = funcunit((yyvsp[0].unit),(yyvsp[-1].realfunc));CHECK((yyvsp[0].unit)); (yyval.unit)=(yyvsp[0].unit);} |
| 1592 | #line 1593 "parse.tab.c" |
| 1593 | break; |
| 1594 | |
| 1595 | case 29: /* list: LOG pexpr */ |
| 1596 | #line 266 "parse.y" |
| 1597 | { err = logunit((yyvsp[0].unit),(yyvsp[-1].integer)); CHECK((yyvsp[0].unit)); (yyval.unit)=(yyvsp[0].unit);} |
| 1598 | #line 1599 "parse.tab.c" |
| 1599 | break; |
| 1600 | |
| 1601 | case 30: /* list: UNITFUNC pexpr */ |
| 1602 | #line 267 "parse.y" |
| 1603 | { err = evalfunc((yyvsp[0].unit),(yyvsp[-1].unitfunc),0,0); CHECK((yyvsp[0].unit));(yyval.unit)=(yyvsp[0].unit);} |
| 1604 | #line 1605 "parse.tab.c" |
| 1605 | break; |
| 1606 | |
| 1607 | case 31: /* list: FUNCINV UNITFUNC pexpr */ |
| 1608 | #line 268 "parse.y" |
| 1609 | { err = evalfunc((yyvsp[0].unit),(yyvsp[-1].unitfunc),1,0); CHECK((yyvsp[0].unit));(yyval.unit)=(yyvsp[0].unit);} |
| 1610 | #line 1611 "parse.tab.c" |
| 1611 | break; |
| 1612 | |
| 1613 | case 32: /* list: list EXPONENT MULTMINUS list */ |
| 1614 | #line 270 "parse.y" |
| 1615 | { (yyvsp[0].unit)->factor *= -1; err = unitpower((yyvsp[-3].unit),(yyvsp[0].unit)); |
| 1616 | destroyunit((yyvsp[0].unit));CHECK((yyvsp[-3].unit));(yyval.unit)=(yyvsp[-3].unit);} |
| 1617 | #line 1618 "parse.tab.c" |
| 1618 | break; |
| 1619 | |
| 1620 | case 33: /* list: list EXPONENT MINUS list */ |
| 1621 | #line 273 "parse.y" |
| 1622 | { (yyvsp[0].unit)->factor *= -1; err = unitpower((yyvsp[-3].unit),(yyvsp[0].unit)); |
| 1623 | destroyunit((yyvsp[0].unit));CHECK((yyvsp[-3].unit));(yyval.unit)=(yyvsp[-3].unit);} |
| 1624 | #line 1625 "parse.tab.c" |
| 1625 | break; |
| 1626 | |
| 1627 | case 34: /* list: BADNUMBER */ |
| 1628 | #line 275 "parse.y" |
| 1629 | { err = E_BADNUM; CHECK(0); } |
| 1630 | #line 1631 "parse.tab.c" |
| 1631 | break; |
| 1632 | |
| 1633 | case 35: /* list: NUMOVERFLOW */ |
| 1634 | #line 276 "parse.y" |
| 1635 | { err = E_OVERFLOW; CHECK(0); } |
| 1636 | #line 1637 "parse.tab.c" |
| 1637 | break; |
| 1638 | |
| 1639 | case 36: /* list: NUMUNDERFLOW */ |
| 1640 | #line 277 "parse.y" |
| 1641 | { err = E_UNDERFLOW;CHECK(0); } |
| 1642 | #line 1643 "parse.tab.c" |
| 1643 | break; |
| 1644 | |
| 1645 | case 37: /* list: MEMERROR */ |
| 1646 | #line 278 "parse.y" |
| 1647 | { err = E_PARSEMEM; CHECK(0); } |
| 1648 | #line 1649 "parse.tab.c" |
| 1649 | break; |
| 1650 | |
| 1651 | case 38: /* list: UNITEND */ |
| 1652 | #line 279 "parse.y" |
| 1653 | { err = E_UNITEND; CHECK(0); } |
| 1654 | #line 1655 "parse.tab.c" |
| 1655 | break; |
| 1656 | |
| 1657 | case 39: /* list: LASTUNSET */ |
| 1658 | #line 280 "parse.y" |
| 1659 | { err = E_LASTUNSET;CHECK(0); } |
| 1660 | #line 1661 "parse.tab.c" |
| 1661 | break; |
| 1662 | |
| 1663 | case 40: /* list: FUNCINV UNIT */ |
| 1664 | #line 281 "parse.y" |
| 1665 | { err = E_NOTAFUNC; CHECK((yyvsp[0].unit));} |
| 1666 | #line 1667 "parse.tab.c" |
| 1667 | break; |
| 1668 | |
| 1669 | |
| 1670 | #line 1671 "parse.tab.c" |
| 1671 | |
| 1672 | default: break; |
| 1673 | } |
| 1674 | /* User semantic actions sometimes alter yychar, and that requires |
| 1675 | that yytoken be updated with the new translation. We take the |
| 1676 | approach of translating immediately before every use of yytoken. |
| 1677 | One alternative is translating here after every semantic action, |
| 1678 | but that translation would be missed if the semantic action invokes |
| 1679 | YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or |
| 1680 | if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an |
| 1681 | incorrect destructor might then be invoked immediately. In the |
| 1682 | case of YYERROR or YYBACKUP, subsequent parser actions might lead |
| 1683 | to an incorrect destructor call or verbose syntax error message |
| 1684 | before the lookahead is translated. */ |
| 1685 | YY_SYMBOL_PRINT ("-> $$ =", YY_CAST (yysymbol_kind_t, yyr1[yyn]), &yyval, &yyloc); |
| 1686 | |
| 1687 | YYPOPSTACK (yylen); |
| 1688 | yylen = 0; |
| 1689 | |
| 1690 | *++yyvsp = yyval; |
| 1691 | |
| 1692 | /* Now 'shift' the result of the reduction. Determine what state |
| 1693 | that goes to, based on the state we popped back to and the rule |
| 1694 | number reduced by. */ |
| 1695 | { |
| 1696 | const int yylhs = yyr1[yyn] - YYNTOKENS; |
| 1697 | const int yyi = yypgoto[yylhs] + *yyssp; |
| 1698 | yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp |
| 1699 | ? yytable[yyi] |
| 1700 | : yydefgoto[yylhs]); |
| 1701 | } |
| 1702 | |
| 1703 | goto yynewstate; |
| 1704 | |
| 1705 | |
| 1706 | /*--------------------------------------. |
| 1707 | | yyerrlab -- here on detecting error. | |
| 1708 | `--------------------------------------*/ |
| 1709 | yyerrlab: |
| 1710 | /* Make sure we have latest lookahead translation. See comments at |
| 1711 | user semantic actions for why this is necessary. */ |
| 1712 | yytoken = yychar == UNITSEMPTY ? YYSYMBOL_YYEMPTY : YYTRANSLATE (yychar); |
| 1713 | /* If not already recovering from an error, report this error. */ |
| 1714 | if (!yyerrstatus) |
| 1715 | { |
| 1716 | ++yynerrs; |
| 1717 | yyerror (comm, YY_("syntax error")); |
| 1718 | } |
| 1719 | |
| 1720 | if (yyerrstatus == 3) |
| 1721 | { |
| 1722 | /* If just tried and failed to reuse lookahead token after an |
| 1723 | error, discard it. */ |
| 1724 | |
| 1725 | if (yychar <= UNITSEOF) |
| 1726 | { |
| 1727 | /* Return failure if at end of input. */ |
| 1728 | if (yychar == UNITSEOF) |
| 1729 | YYABORT; |
| 1730 | } |
| 1731 | else |
| 1732 | { |
| 1733 | yydestruct ("Error: discarding", |
| 1734 | yytoken, &yylval, comm); |
| 1735 | yychar = UNITSEMPTY; |
| 1736 | } |
| 1737 | } |
| 1738 | |
| 1739 | /* Else will try to reuse lookahead token after shifting the error |
| 1740 | token. */ |
| 1741 | goto yyerrlab1; |
| 1742 | |
| 1743 | |
| 1744 | /*---------------------------------------------------. |
| 1745 | | yyerrorlab -- error raised explicitly by YYERROR. | |
| 1746 | `---------------------------------------------------*/ |
| 1747 | yyerrorlab: |
| 1748 | /* Pacify compilers when the user code never invokes YYERROR and the |
| 1749 | label yyerrorlab therefore never appears in user code. */ |
| 1750 | if (0) |
| 1751 | YYERROR; |
| 1752 | ++yynerrs; |
| 1753 | |
| 1754 | /* Do not reclaim the symbols of the rule whose action triggered |
| 1755 | this YYERROR. */ |
| 1756 | YYPOPSTACK (yylen); |
| 1757 | yylen = 0; |
| 1758 | YY_STACK_PRINT (yyss, yyssp); |
| 1759 | yystate = *yyssp; |
| 1760 | goto yyerrlab1; |
| 1761 | |
| 1762 | |
| 1763 | /*-------------------------------------------------------------. |
| 1764 | | yyerrlab1 -- common code for both syntax error and YYERROR. | |
| 1765 | `-------------------------------------------------------------*/ |
| 1766 | yyerrlab1: |
| 1767 | yyerrstatus = 3; /* Each real token shifted decrements this. */ |
| 1768 | |
| 1769 | /* Pop stack until we find a state that shifts the error token. */ |
| 1770 | for (;;) |
| 1771 | { |
| 1772 | yyn = yypact[yystate]; |
| 1773 | if (!yypact_value_is_default (yyn)) |
| 1774 | { |
| 1775 | yyn += YYSYMBOL_YYerror; |
| 1776 | if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYSYMBOL_YYerror) |
| 1777 | { |
| 1778 | yyn = yytable[yyn]; |
| 1779 | if (0 < yyn) |
| 1780 | break; |
| 1781 | } |
| 1782 | } |
| 1783 | |
| 1784 | /* Pop the current state because it cannot handle the error token. */ |
| 1785 | if (yyssp == yyss) |
| 1786 | YYABORT; |
| 1787 | |
| 1788 | |
| 1789 | yydestruct ("Error: popping", |
| 1790 | YY_ACCESSING_SYMBOL (yystate), yyvsp, comm); |
| 1791 | YYPOPSTACK (1); |
| 1792 | yystate = *yyssp; |
| 1793 | YY_STACK_PRINT (yyss, yyssp); |
| 1794 | } |
| 1795 | |
| 1796 | YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN |
| 1797 | *++yyvsp = yylval; |
| 1798 | YY_IGNORE_MAYBE_UNINITIALIZED_END |
| 1799 | |
| 1800 | |
| 1801 | /* Shift the error token. */ |
| 1802 | YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn), yyvsp, yylsp); |
| 1803 | |
| 1804 | yystate = yyn; |
| 1805 | goto yynewstate; |
| 1806 | |
| 1807 | |
| 1808 | /*-------------------------------------. |
| 1809 | | yyacceptlab -- YYACCEPT comes here. | |
| 1810 | `-------------------------------------*/ |
| 1811 | yyacceptlab: |
| 1812 | yyresult = 0; |
| 1813 | goto yyreturnlab; |
| 1814 | |
| 1815 | |
| 1816 | /*-----------------------------------. |
| 1817 | | yyabortlab -- YYABORT comes here. | |
| 1818 | `-----------------------------------*/ |
| 1819 | yyabortlab: |
| 1820 | yyresult = 1; |
| 1821 | goto yyreturnlab; |
| 1822 | |
| 1823 | |
| 1824 | /*-----------------------------------------------------------. |
| 1825 | | yyexhaustedlab -- YYNOMEM (memory exhaustion) comes here. | |
| 1826 | `-----------------------------------------------------------*/ |
| 1827 | yyexhaustedlab: |
| 1828 | yyerror (comm, YY_("memory exhausted")); |
| 1829 | yyresult = 2; |
| 1830 | goto yyreturnlab; |
| 1831 | |
| 1832 | |
| 1833 | /*----------------------------------------------------------. |
| 1834 | | yyreturnlab -- parsing is finished, clean up and return. | |
| 1835 | `----------------------------------------------------------*/ |
| 1836 | yyreturnlab: |
| 1837 | if (yychar != UNITSEMPTY) |
| 1838 | { |
| 1839 | /* Make sure we have latest lookahead translation. See comments at |
| 1840 | user semantic actions for why this is necessary. */ |
| 1841 | yytoken = YYTRANSLATE (yychar); |
| 1842 | yydestruct ("Cleanup: discarding lookahead", |
| 1843 | yytoken, &yylval, comm); |
| 1844 | } |
| 1845 | /* Do not reclaim the symbols of the rule whose action triggered |
| 1846 | this YYABORT or YYACCEPT. */ |
| 1847 | YYPOPSTACK (yylen); |
| 1848 | YY_STACK_PRINT (yyss, yyssp); |
| 1849 | while (yyssp != yyss) |
| 1850 | { |
| 1851 | yydestruct ("Cleanup: popping", |
| 1852 | YY_ACCESSING_SYMBOL (+*yyssp), yyvsp, comm); |
| 1853 | YYPOPSTACK (1); |
| 1854 | } |
| 1855 | #ifndef yyoverflow |
| 1856 | if (yyss != yyssa) |
| 1857 | YYSTACK_FREE (yyss); |
| 1858 | #endif |
| 1859 | |
| 1860 | return yyresult; |
| 1861 | } |
| 1862 | |
| 1863 | #line 284 "parse.y" |
| 1864 | |
| 1865 | |
| 1866 | double |
| 1867 | factorial(double x) |
| 1868 | { |
| 1869 | return tgamma(x+1); |
| 1870 | } |
| 1871 | |
| 1872 | struct function |
| 1873 | realfunctions[] = { {"sin", sin, ANGLEIN}, |
| 1874 | {"cos", cos, ANGLEIN}, |
| 1875 | {"tan", tan, ANGLEIN}, |
| 1876 | {"ln", log, DIMENSIONLESS}, |
| 1877 | {"log", log10, DIMENSIONLESS}, |
| 1878 | {"exp", exp, DIMENSIONLESS}, |
| 1879 | {"acos", acos, ANGLEOUT}, |
| 1880 | {"atan", atan, ANGLEOUT}, |
| 1881 | {"asin", asin, ANGLEOUT}, |
| 1882 | {"sinh", sinh, DIMENSIONLESS}, |
| 1883 | {"cosh", cosh, DIMENSIONLESS}, |
| 1884 | {"tanh", tanh, DIMENSIONLESS}, |
| 1885 | {"asinh", asinh, DIMENSIONLESS}, |
| 1886 | {"acosh", acosh, DIMENSIONLESS}, |
| 1887 | {"atanh", atanh, DIMENSIONLESS}, |
| 1888 | {"round", round, DIMENSIONLESS}, |
| 1889 | {"floor", floor, DIMENSIONLESS}, |
| 1890 | {"ceil", ceil, DIMENSIONLESS}, |
| 1891 | {"erf", erf, DIMENSIONLESS}, |
| 1892 | {"erfc", erfc, DIMENSIONLESS}, |
| 1893 | {"Gamma", tgamma, DIMENSIONLESS}, |
| 1894 | {"lnGamma", lgamma, DIMENSIONLESS}, |
| 1895 | {"factorial", factorial, NATURAL}, |
| 1896 | {0, 0, 0}}; |
| 1897 | |
| 1898 | struct { |
| 1899 | char op; |
| 1900 | int value; |
| 1901 | } optable[] = { {'*', MULTIPLY}, |
| 1902 | {'/', DIVIDE}, |
| 1903 | {'|', NUMDIV}, |
| 1904 | {'+', ADD}, |
| 1905 | {'(', '('}, |
| 1906 | {')', ')'}, |
| 1907 | {'^', EXPONENT}, |
| 1908 | {'~', FUNCINV}, |
| 1909 | {0, 0}}; |
| 1910 | |
| 1911 | struct { |
| 1912 | char *name; |
| 1913 | int value; |
| 1914 | } strtable[] = { {"sqrt", SQRT}, |
| 1915 | {"cuberoot", CUBEROOT}, |
| 1916 | {"per" , DIVIDE}, |
| 1917 | {0, 0}}; |
| 1918 | |
| 1919 | #define LASTUNIT '_' /* Last unit symbol */ |
| 1920 | |
| 1921 | |
| 1922 | int yylex(YYSTYPE *lvalp, struct commtype *comm) |
| 1923 | { |
| 1924 | int length, count; |
| 1925 | struct unittype *output; |
| 1926 | const char *inptr; |
| 1927 | char *name; |
| 1928 | |
| 1929 | char *nonunitchars = "~;+-*/|\t\n^ ()"; /* Chars not allowed in unit name --- also defined in units.c */ |
| 1930 | char *nonunitstart = ".,"; /* Can't start a unit */ |
| 1931 | char *nonunitend = ".,_"; /* Can't end a unit */ |
| 1932 | char *number_start = ".,0123456789"; /* Can be first char of a number */ |
| 1933 | |
| 1934 | if (comm->location==-1) return 0; |
| 1935 | inptr = comm->data + comm->location; /* Point to start of data */ |
| 1936 | |
| 1937 | /* Skip spaces */ |
| 1938 | while(*inptr==' ') inptr++, comm->location++; |
| 1939 | |
| 1940 | if (*inptr==0) { |
| 1941 | comm->location = -1; |
| 1942 | return EOL; /* Return failure if string has ended */ |
| 1943 | } |
| 1944 | |
| 1945 | /* Check for **, an exponent operator. */ |
| 1946 | |
| 1947 | if (0==strncmp("**",inptr,2)){ |
| 1948 | comm->location += 2; |
| 1949 | return EXPONENT; |
| 1950 | } |
| 1951 | |
| 1952 | /* Check for '-' and '*' which get special handling */ |
| 1953 | |
| 1954 | if (*inptr=='-'){ |
| 1955 | comm->location++; |
| 1956 | if (parserflags.minusminus) |
| 1957 | return MINUS; |
| 1958 | return MULTMINUS; |
| 1959 | } |
| 1960 | |
| 1961 | if (*inptr=='*'){ |
| 1962 | comm->location++; |
| 1963 | if (parserflags.oldstar) |
| 1964 | return MULTIPLY; |
| 1965 | return MULTSTAR; |
| 1966 | } |
| 1967 | |
| 1968 | /* Look for single character ops */ |
| 1969 | |
| 1970 | for(count=0; optable[count].op; count++){ |
| 1971 | if (*inptr==optable[count].op) { |
| 1972 | comm->location++; |
| 1973 | return optable[count].value; |
| 1974 | } |
| 1975 | } |
| 1976 | |
| 1977 | /* Look for numbers */ |
| 1978 | |
| 1979 | if (strchr(number_start,*inptr)){ /* prevent "nan" from being recognized */ |
| 1980 | char *endloc; |
| 1981 | errno=0; |
| 1982 | lvalp->number = strtod(inptr, &endloc); |
| 1983 | if (inptr != endloc) { |
| 1984 | comm->location += (endloc-inptr); |
| 1985 | if (*endloc && strchr(number_start,*endloc)) |
| 1986 | return BADNUMBER; |
| 1987 | else if (errno){ |
| 1988 | errno=0; |
| 1989 | if (fabs(lvalp->number)==HUGE_VAL) return NUMOVERFLOW; |
| 1990 | else return NUMUNDERFLOW; |
| 1991 | } |
| 1992 | else |
| 1993 | return REAL; |
| 1994 | } |
| 1995 | } |
| 1996 | |
| 1997 | /* Look for a word (function name or unit name) */ |
| 1998 | |
| 1999 | length = strcspn(inptr,nonunitchars); |
| 2000 | |
| 2001 | if (!length){ /* Next char is not a valid unit char */ |
| 2002 | comm->location++; |
| 2003 | return 0; |
| 2004 | } |
| 2005 | |
| 2006 | /* Check for the "last unit" symbol, with possible exponent */ |
| 2007 | |
| 2008 | if (*inptr == LASTUNIT && |
| 2009 | (length==1 || length==2 && strchr("23456789",inptr[1]))){ |
| 2010 | comm->location++; |
| 2011 | if (!lastunitset) |
| 2012 | return LASTUNSET; |
| 2013 | output = getnewunit(); |
| 2014 | if (!output) |
| 2015 | return MEMERROR; |
| 2016 | unitcopy(output, &lastunit); |
| 2017 | if (length==2){ |
| 2018 | expunit(output, inptr[1]-'0'); |
| 2019 | comm->location++; |
| 2020 | } |
| 2021 | lvalp->unit = output; |
| 2022 | return UNIT; |
| 2023 | } |
| 2024 | |
| 2025 | /* Check that unit name doesn't start or end with forbidden chars */ |
| 2026 | if (strchr(nonunitstart,*inptr)){ |
| 2027 | comm->location++; |
| 2028 | return 0; |
| 2029 | } |
| 2030 | if (strchr(nonunitend, inptr[length-1])){ |
| 2031 | comm->location+=length; |
| 2032 | return 0; |
| 2033 | } |
| 2034 | |
| 2035 | name = dupnstr(inptr, length); |
| 2036 | |
| 2037 | /* Look for string operators */ |
| 2038 | |
| 2039 | for(count=0;strtable[count].name;count++){ |
| 2040 | if (!strcmp(name,strtable[count].name)){ |
| 2041 | free(name); |
| 2042 | comm->location += length; |
| 2043 | return strtable[count].value; |
| 2044 | } |
| 2045 | } |
| 2046 | |
| 2047 | /* Look for real function names */ |
| 2048 | |
| 2049 | for(count=0;realfunctions[count].name;count++){ |
| 2050 | if (!strcmp(name,realfunctions[count].name)){ |
| 2051 | lvalp->realfunc = realfunctions+count; |
| 2052 | comm->location += length; |
| 2053 | free(name); |
| 2054 | return REALFUNC; |
| 2055 | } |
| 2056 | } |
| 2057 | |
| 2058 | /* Check for arbitrary base log */ |
| 2059 | |
| 2060 | if (!strncmp(name, "log",3)){ |
| 2061 | count = strspn(name+3,"1234567890"); |
| 2062 | if (count+3 == strlen(name)){ |
| 2063 | lvalp->integer=atoi(name+3); |
| 2064 | if (lvalp->integer>1){ /* Log base must be larger than 1 */ |
| 2065 | comm->location += length; |
| 2066 | free(name); |
| 2067 | return LOG; |
| 2068 | } |
| 2069 | } |
| 2070 | } |
| 2071 | |
| 2072 | /* Look for function parameter */ |
| 2073 | |
| 2074 | if (function_parameter && !strcmp(name,function_parameter)){ |
| 2075 | free(name); |
| 2076 | output = getnewunit(); |
| 2077 | if (!output) |
| 2078 | return MEMERROR; |
| 2079 | unitcopy(output, parameter_value); |
| 2080 | lvalp->unit = output; |
| 2081 | comm->location += length; |
| 2082 | return UNIT; |
| 2083 | } |
| 2084 | |
| 2085 | /* Look for user defined function */ |
| 2086 | |
| 2087 | lvalp->unitfunc = fnlookup(name); |
| 2088 | if (lvalp->unitfunc){ |
| 2089 | comm->location += length; |
| 2090 | free(name); |
| 2091 | return UNITFUNC; |
| 2092 | } |
| 2093 | |
| 2094 | /* Didn't find a special string, so treat it as unit name */ |
| 2095 | |
| 2096 | comm->location+=length; |
| 2097 | if (strchr("23456789",inptr[length-1]) && !hassubscript(name)) { |
| 2098 | /* ends with digit but not a subscript, so do exponent handling like m3 */ |
| 2099 | count = name[length-1] - '0'; |
| 2100 | length--; |
| 2101 | if (strchr(number_start, name[length-1])){ |
| 2102 | free(name); |
| 2103 | return UNITEND; |
| 2104 | } |
| 2105 | } else count=1; |
| 2106 | |
| 2107 | free(name); |
| 2108 | |
| 2109 | output = getnewunit(); |
| 2110 | if (!output) |
| 2111 | return MEMERROR; |
| 2112 | output->numerator[count--]=0; |
| 2113 | for(;count>=0;count--) |
| 2114 | output->numerator[count] = dupnstr(inptr, length); |
| 2115 | lvalp->unit=output; |
| 2116 | return UNIT; |
| 2117 | } |
| 2118 | |
| 2119 | |
| 2120 | void yyerror(struct commtype *comm, char *s){} |
| 2121 | |
| 2122 | |
| 2123 | int |
| 2124 | parseunit(struct unittype *output, char const *input,char **errstr,int *errloc) |
| 2125 | { |
| 2126 | struct commtype comm; |
| 2127 | int saveunitcount; |
| 2128 | |
| 2129 | saveunitcount = unitcount; |
| 2130 | initializeunit(output); |
| 2131 | comm.result = 0; |
| 2132 | comm.location = 0; |
| 2133 | comm.data = input; |
| 2134 | comm.errorcode = E_PARSE; /* Assume parse error */ |
| 2135 | errno=0; |
| 2136 | /* errno should only be set in the case of invalid function arguments */ |
| 2137 | if (yyparse(&comm) || errno){ |
| 2138 | if (comm.location==-1) |
| 2139 | comm.location = strlen(input); |
| 2140 | if (errstr){ |
| 2141 | if (comm.errorcode==E_FUNC || errno) |
| 2142 | *errstr = strerror(errno); |
| 2143 | else |
| 2144 | *errstr=errormsg[comm.errorcode]; |
| 2145 | } |
| 2146 | if (errloc) |
| 2147 | *errloc = comm.location; |
| 2148 | if (unitcount!=saveunitcount) |
| 2149 | fprintf(stderr,"units: Parser leaked memory with error: %d in %d out\n", |
| 2150 | saveunitcount, unitcount); |
| 2151 | return comm.errorcode; |
| 2152 | } else { |
| 2153 | if (errstr) |
| 2154 | *errstr = 0; |
| 2155 | multunit(output,comm.result); |
| 2156 | destroyunit(comm.result); |
| 2157 | if (unitcount!=saveunitcount) |
| 2158 | fprintf(stderr,"units: Parser leaked memory without error: %d in %d out\n", |
| 2159 | saveunitcount, unitcount); |
| 2160 | return 0; |
| 2161 | } |
| 2162 | } |
| 2163 | |
| 2164 | |