| 1 | /* $Id: CoinModelUseful2.cpp 1396 2011-03-01 10:42:29Z forrest $ */ |
| 2 | // Copyright (C) 2005, International Business Machines |
| 3 | // Corporation and others. All Rights Reserved. |
| 4 | /* A Bison parser, made by GNU Bison 1.875c. */ |
| 5 | |
| 6 | // License sounds scary but see special exception so has no problems |
| 7 | |
| 8 | /* Skeleton parser for Yacc-like parsing with Bison, |
| 9 | Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003 Free Software Foundation, Inc. |
| 10 | |
| 11 | This program is free software; you can redistribute it and/or modify |
| 12 | it under the terms of the GNU General Public License as published by |
| 13 | the Free Software Foundation; either version 2, or (at your option) |
| 14 | any later version. |
| 15 | |
| 16 | This program is distributed in the hope that it will be useful, |
| 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | GNU General Public License for more details. |
| 20 | |
| 21 | You should have received a copy of the GNU General Public License |
| 22 | along with this program; if not, write to the Free Software |
| 23 | Foundation, Inc., 59 Temple Place - Suite 330, |
| 24 | Boston, MA 02111-1307, USA. */ |
| 25 | |
| 26 | /* As a special exception, when this file is copied by Bison into a |
| 27 | Bison output file, you may use that output file without restriction. |
| 28 | This special exception was added by the Free Software Foundation |
| 29 | in version 1.24 of Bison. */ |
| 30 | |
| 31 | /* Written by Richard Stallman by simplifying the original so called |
| 32 | ``semantic'' parser. */ |
| 33 | |
| 34 | /* All symbols defined below should begin with yy or YY, to avoid |
| 35 | infringing on user name space. This should be done even for local |
| 36 | variables, as they might otherwise be expanded by user macros. |
| 37 | There are some unavoidable exceptions within include files to |
| 38 | define necessary library symbols; they are noted "INFRINGES ON |
| 39 | USER NAME SPACE" below. */ |
| 40 | |
| 41 | /* Identify Bison output. */ |
| 42 | #define YYBISON 1 |
| 43 | |
| 44 | /* Skeleton name. */ |
| 45 | #define YYSKELETON_NAME "yacc.c" |
| 46 | |
| 47 | /* Pure parsers. */ |
| 48 | #define YYPURE 0 |
| 49 | |
| 50 | /* Using locations. */ |
| 51 | #define YYLSP_NEEDED 0 |
| 52 | |
| 53 | |
| 54 | |
| 55 | /* Tokens. */ |
| 56 | #ifndef YYTOKENTYPE |
| 57 | # define YYTOKENTYPE |
| 58 | /* Put the tokens into the symbol table, so that GDB and other debuggers |
| 59 | know about them. */ |
| 60 | enum yytokentype { |
| 61 | NUM = 258, |
| 62 | VAR = 259, |
| 63 | FNCT = 260, |
| 64 | NEG = 261 |
| 65 | }; |
| 66 | #endif |
| 67 | #define NUM 258 |
| 68 | #define VAR 259 |
| 69 | #define FNCT 260 |
| 70 | #define NEG 261 |
| 71 | |
| 72 | #include <cstdlib> |
| 73 | |
| 74 | #include "CoinModel.hpp" |
| 75 | #include "CoinHelperFunctions.hpp" |
| 76 | |
| 77 | |
| 78 | /* Copy the first part of user declarations. */ |
| 79 | |
| 80 | #include <cmath> /* For math functions, cos(), sin(), etc. */ |
| 81 | |
| 82 | #include <cstdio> |
| 83 | #include <ctype.h> |
| 84 | #include <cstring> |
| 85 | #include <cassert> |
| 86 | static void yyerror (char const *); |
| 87 | |
| 88 | |
| 89 | /* Enabling traces. */ |
| 90 | #ifndef YYDEBUG |
| 91 | # define YYDEBUG 0 |
| 92 | #endif |
| 93 | |
| 94 | /* Enabling verbose error messages. */ |
| 95 | #ifdef YYERROR_VERBOSE |
| 96 | # undef YYERROR_VERBOSE |
| 97 | # define YYERROR_VERBOSE 1 |
| 98 | #else |
| 99 | # define YYERROR_VERBOSE 0 |
| 100 | #endif |
| 101 | |
| 102 | #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED) |
| 103 | typedef union YYSTYPE { |
| 104 | double val; /* For returning numbers. */ |
| 105 | symrec *tptr; /* For returning symbol-table pointers. */ |
| 106 | } YYSTYPE; |
| 107 | /* Line 191 of yacc.c. */ |
| 108 | # define yystype YYSTYPE /* obsolescent; will be withdrawn */ |
| 109 | # define YYSTYPE_IS_DECLARED 1 |
| 110 | # define YYSTYPE_IS_TRIVIAL 1 |
| 111 | #endif |
| 112 | |
| 113 | |
| 114 | |
| 115 | /* Copy the second part of user declarations. */ |
| 116 | |
| 117 | |
| 118 | /* Line 214 of yacc.c. */ |
| 119 | |
| 120 | #if ! defined (yyoverflow) || YYERROR_VERBOSE |
| 121 | |
| 122 | /* The parser invokes alloca or malloc; define the necessary symbols. */ |
| 123 | |
| 124 | # ifdef YYSTACK_USE_ALLOCA |
| 125 | # if YYSTACK_USE_ALLOCA |
| 126 | # define YYSTACK_ALLOC alloca |
| 127 | # endif |
| 128 | # else |
| 129 | # if defined (alloca) || defined (_ALLOCA_H) |
| 130 | # define YYSTACK_ALLOC alloca |
| 131 | # else |
| 132 | # ifdef __GNUC__ |
| 133 | # define YYSTACK_ALLOC __builtin_alloca |
| 134 | # endif |
| 135 | # endif |
| 136 | # endif |
| 137 | |
| 138 | # ifdef YYSTACK_ALLOC |
| 139 | /* Pacify GCC's `empty if-body' warning. */ |
| 140 | # define YYSTACK_FREE(Ptr) do { /* empty */; } while (0) |
| 141 | # else |
| 142 | # if defined (__STDC__) || defined (__cplusplus) |
| 143 | # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */ |
| 144 | # define YYSIZE_T size_t |
| 145 | # endif |
| 146 | # define YYSTACK_ALLOC malloc |
| 147 | # define YYSTACK_FREE free |
| 148 | # endif |
| 149 | #endif /* ! defined (yyoverflow) || YYERROR_VERBOSE */ |
| 150 | |
| 151 | |
| 152 | #if (! defined (yyoverflow) \ |
| 153 | && (! defined (__cplusplus) \ |
| 154 | || (defined (YYSTYPE_IS_TRIVIAL) && YYSTYPE_IS_TRIVIAL))) |
| 155 | |
| 156 | /* A type that is properly aligned for any stack member. */ |
| 157 | union yyalloc |
| 158 | { |
| 159 | short yyss; |
| 160 | YYSTYPE yyvs; |
| 161 | }; |
| 162 | |
| 163 | /* The size of the maximum gap between one aligned stack and the next. */ |
| 164 | # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1) |
| 165 | |
| 166 | /* The size of an array large to enough to hold all stacks, each with |
| 167 | N elements. */ |
| 168 | # define YYSTACK_BYTES(N) \ |
| 169 | ((N) * (sizeof (short) + sizeof (YYSTYPE)) \ |
| 170 | + YYSTACK_GAP_MAXIMUM) |
| 171 | |
| 172 | /* Copy COUNT objects from FROM to TO. The source and destination do |
| 173 | not overlap. */ |
| 174 | # ifndef YYCOPY |
| 175 | # if defined (__GNUC__) && 1 < __GNUC__ |
| 176 | # define YYCOPY(To, From, Count) \ |
| 177 | __builtin_memcpy (To, From, (Count) * sizeof (*(From))) |
| 178 | # else |
| 179 | # define YYCOPY(To, From, Count) \ |
| 180 | do \ |
| 181 | { \ |
| 182 | YYSIZE_T yyi; \ |
| 183 | for (yyi = 0; yyi < (Count); yyi++) \ |
| 184 | (To)[yyi] = (From)[yyi]; \ |
| 185 | } \ |
| 186 | while (0) |
| 187 | # endif |
| 188 | # endif |
| 189 | |
| 190 | /* Relocate STACK from its old location to the new one. The |
| 191 | local variables YYSIZE and YYSTACKSIZE give the old and new number of |
| 192 | elements in the stack, and YYPTR gives the new location of the |
| 193 | stack. Advance YYPTR to a properly aligned location for the next |
| 194 | stack. */ |
| 195 | # define YYSTACK_RELOCATE(Stack) \ |
| 196 | do \ |
| 197 | { \ |
| 198 | YYSIZE_T yynewbytes; \ |
| 199 | YYCOPY (&yyptr->Stack, Stack, yysize); \ |
| 200 | Stack = &yyptr->Stack; \ |
| 201 | yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ |
| 202 | yyptr += yynewbytes / sizeof (*yyptr); \ |
| 203 | } \ |
| 204 | while (0) |
| 205 | |
| 206 | #endif |
| 207 | |
| 208 | #if defined (__STDC__) || defined (__cplusplus) |
| 209 | typedef signed char yysigned_char; |
| 210 | #else |
| 211 | typedef short yysigned_char; |
| 212 | #endif |
| 213 | |
| 214 | /* YYFINAL -- State number of the termination state. */ |
| 215 | #define YYFINAL 2 |
| 216 | /* YYLAST -- Last index in YYTABLE. */ |
| 217 | #define YYLAST 64 |
| 218 | |
| 219 | /* YYNTOKENS -- Number of terminals. */ |
| 220 | #define YYNTOKENS 16 |
| 221 | /* YYNNTS -- Number of nonterminals. */ |
| 222 | #define YYNNTS 4 |
| 223 | /* YYNRULES -- Number of rules. */ |
| 224 | #define YYNRULES 17 |
| 225 | /* YYNRULES -- Number of states. */ |
| 226 | #define YYNSTATES 32 |
| 227 | |
| 228 | /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ |
| 229 | #define YYUNDEFTOK 2 |
| 230 | #define YYMAXUTOK 261 |
| 231 | |
| 232 | #define YYTRANSLATE(YYX) \ |
| 233 | (static_cast<unsigned int> ((YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)) |
| 234 | |
| 235 | /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */ |
| 236 | static const unsigned char yytranslate[] = |
| 237 | { |
| 238 | 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 239 | 13, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 240 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 241 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 242 | 14, 15, 9, 8, 2, 7, 2, 10, 2, 2, |
| 243 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 244 | 2, 6, 2, 2, 2, 2, 2, 2, 2, 2, |
| 245 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 246 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 247 | 2, 2, 2, 2, 12, 2, 2, 2, 2, 2, |
| 248 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 249 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 250 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 251 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 252 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 253 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 254 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 255 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 256 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 257 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 258 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 259 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 260 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 261 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 262 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 263 | 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, |
| 264 | 5, 11 |
| 265 | }; |
| 266 | |
| 267 | #if YYDEBUG |
| 268 | /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in |
| 269 | YYRHS. */ |
| 270 | static const unsigned char yyprhs[] = |
| 271 | { |
| 272 | 0, 0, 3, 4, 7, 9, 12, 15, 17, 19, |
| 273 | 23, 28, 32, 36, 40, 44, 47, 51 |
| 274 | }; |
| 275 | |
| 276 | /* YYRHS -- A `-1'-separated list of the rules' RHS. */ |
| 277 | static const yysigned_char yyrhs[] = |
| 278 | { |
| 279 | 17, 0, -1, -1, 17, 18, -1, 13, -1, 19, |
| 280 | 13, -1, 1, 13, -1, 3, -1, 4, -1, 4, |
| 281 | 6, 19, -1, 5, 14, 19, 15, -1, 19, 8, |
| 282 | 19, -1, 19, 7, 19, -1, 19, 9, 19, -1, |
| 283 | 19, 10, 19, -1, 7, 19, -1, 19, 12, 19, |
| 284 | -1, 14, 19, 15, -1 |
| 285 | }; |
| 286 | |
| 287 | /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ |
| 288 | static const unsigned char yyrline[] = |
| 289 | { |
| 290 | 0, 23, 23, 24, 28, 29, 30, 33, 34, 35, |
| 291 | 36, 37, 38, 39, 40, 41, 42, 43 |
| 292 | }; |
| 293 | #endif |
| 294 | |
| 295 | #if YYDEBUG || YYERROR_VERBOSE |
| 296 | /* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. |
| 297 | First, the terminals, then, starting at YYNTOKENS, nonterminals. */ |
| 298 | static const char *const yytname[] = |
| 299 | { |
| 300 | "$end" , "error" , "$undefined" , "NUM" , "VAR" , "FNCT" , "'='" , "'-'" , |
| 301 | "'+'" , "'*'" , "'/'" , "NEG" , "'^'" , "'\\n'" , "'('" , "')'" , "$accept" , |
| 302 | "input" , "line" , "exp" , 0 |
| 303 | }; |
| 304 | #endif |
| 305 | |
| 306 | # ifdef YYPRINT |
| 307 | /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to |
| 308 | token YYLEX-NUM. */ |
| 309 | static const unsigned short yytoknum[] = |
| 310 | { |
| 311 | 0, 256, 257, 258, 259, 260, 61, 45, 43, 42, |
| 312 | 47, 261, 94, 10, 40, 41 |
| 313 | }; |
| 314 | # endif |
| 315 | |
| 316 | /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ |
| 317 | static const unsigned char yyr1[] = |
| 318 | { |
| 319 | 0, 16, 17, 17, 18, 18, 18, 19, 19, 19, |
| 320 | 19, 19, 19, 19, 19, 19, 19, 19 |
| 321 | }; |
| 322 | |
| 323 | /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ |
| 324 | static const unsigned char yyr2[] = |
| 325 | { |
| 326 | 0, 2, 0, 2, 1, 2, 2, 1, 1, 3, |
| 327 | 4, 3, 3, 3, 3, 2, 3, 3 |
| 328 | }; |
| 329 | |
| 330 | /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state |
| 331 | STATE-NUM when YYTABLE doesn't specify something else to do. Zero |
| 332 | means the default is an error. */ |
| 333 | static const unsigned char yydefact[] = |
| 334 | { |
| 335 | 2, 0, 1, 0, 7, 8, 0, 0, 4, 0, |
| 336 | 3, 0, 6, 0, 0, 15, 0, 0, 0, 0, |
| 337 | 0, 0, 5, 9, 0, 17, 12, 11, 13, 14, |
| 338 | 16, 10 |
| 339 | }; |
| 340 | |
| 341 | /* YYDEFGOTO[NTERM-NUM]. */ |
| 342 | static const yysigned_char yydefgoto[] = |
| 343 | { |
| 344 | -1, 1, 10, 11 |
| 345 | }; |
| 346 | |
| 347 | /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing |
| 348 | STATE-NUM. */ |
| 349 | #define YYPACT_NINF -13 |
| 350 | static const yysigned_char yypact[] = |
| 351 | { |
| 352 | -13, 15, -13, -12, -13, -3, -10, 20, -13, 20, |
| 353 | -13, 41, -13, 20, 20, -4, 23, 20, 20, 20, |
| 354 | 20, 20, -13, 48, 32, -13, 52, 52, -4, -4, |
| 355 | -4, -13 |
| 356 | }; |
| 357 | |
| 358 | /* YYPGOTO[NTERM-NUM]. */ |
| 359 | static const yysigned_char yypgoto[] = |
| 360 | { |
| 361 | -13, -13, -13, -7 |
| 362 | }; |
| 363 | |
| 364 | /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If |
| 365 | positive, shift that token. If negative, reduce the rule which |
| 366 | number is the opposite. If zero, do what YYDEFACT says. |
| 367 | If YYTABLE_NINF, syntax error. */ |
| 368 | #define YYTABLE_NINF -1 |
| 369 | static const unsigned char yytable[] = |
| 370 | { |
| 371 | 15, 12, 16, 13, 14, 0, 23, 24, 21, 0, |
| 372 | 26, 27, 28, 29, 30, 2, 3, 0, 4, 5, |
| 373 | 6, 0, 7, 4, 5, 6, 0, 7, 8, 9, |
| 374 | 17, 18, 19, 20, 9, 21, 0, 0, 25, 17, |
| 375 | 18, 19, 20, 0, 21, 0, 0, 31, 17, 18, |
| 376 | 19, 20, 0, 21, 22, 17, 18, 19, 20, 0, |
| 377 | 21, 19, 20, 0, 21 |
| 378 | }; |
| 379 | |
| 380 | static const yysigned_char yycheck[] = |
| 381 | { |
| 382 | 7, 13, 9, 6, 14, -1, 13, 14, 12, -1, |
| 383 | 17, 18, 19, 20, 21, 0, 1, -1, 3, 4, |
| 384 | 5, -1, 7, 3, 4, 5, -1, 7, 13, 14, |
| 385 | 7, 8, 9, 10, 14, 12, -1, -1, 15, 7, |
| 386 | 8, 9, 10, -1, 12, -1, -1, 15, 7, 8, |
| 387 | 9, 10, -1, 12, 13, 7, 8, 9, 10, -1, |
| 388 | 12, 9, 10, -1, 12 |
| 389 | }; |
| 390 | |
| 391 | /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing |
| 392 | symbol of state STATE-NUM. */ |
| 393 | static const unsigned char yystos[] = |
| 394 | { |
| 395 | 0, 17, 0, 1, 3, 4, 5, 7, 13, 14, |
| 396 | 18, 19, 13, 6, 14, 19, 19, 7, 8, 9, |
| 397 | 10, 12, 13, 19, 19, 15, 19, 19, 19, 19, |
| 398 | 19, 15 |
| 399 | }; |
| 400 | |
| 401 | #if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__) |
| 402 | # define YYSIZE_T size_t |
| 403 | #endif |
| 404 | #if ! defined (YYSIZE_T) && defined (size_t) |
| 405 | # define YYSIZE_T size_t |
| 406 | #endif |
| 407 | #if ! defined (YYSIZE_T) |
| 408 | # if defined (__STDC__) || defined (__cplusplus) |
| 409 | # include <stddef.h> /* INFRINGES ON USER NAME SPACE */ |
| 410 | # define YYSIZE_T size_t |
| 411 | # endif |
| 412 | #endif |
| 413 | #if ! defined (YYSIZE_T) |
| 414 | # define YYSIZE_T unsigned int |
| 415 | #endif |
| 416 | |
| 417 | #define yyerrok (yyerrstatus = 0) |
| 418 | #define yyclearin (yychar = YYEMPTY) |
| 419 | #define YYEMPTY (-2) |
| 420 | #define YYEOF 0 |
| 421 | |
| 422 | #define YYACCEPT goto yyacceptlab |
| 423 | #define YYABORT goto yyabortlab |
| 424 | #define YYERROR goto yyerrorlab |
| 425 | |
| 426 | |
| 427 | /* Like YYERROR except do call yyerror. This remains here temporarily |
| 428 | to ease the transition to the new meaning of YYERROR, for GCC. |
| 429 | Once GCC version 2 has supplanted version 1, this can go. */ |
| 430 | |
| 431 | #define YYFAIL goto yyerrlab |
| 432 | |
| 433 | #define YYRECOVERING() (!!yyerrstatus) |
| 434 | |
| 435 | #define YYBACKUP(Token, Value) \ |
| 436 | do \ |
| 437 | if (yychar == YYEMPTY && yylen == 1) \ |
| 438 | { \ |
| 439 | yychar = (Token); \ |
| 440 | yylval = (Value); \ |
| 441 | yytoken = YYTRANSLATE (yychar); \ |
| 442 | YYPOPSTACK; \ |
| 443 | goto yybackup; \ |
| 444 | } \ |
| 445 | else \ |
| 446 | { \ |
| 447 | yyerror ("syntax error: cannot back up",error);\ |
| 448 | YYERROR; \ |
| 449 | } \ |
| 450 | while (0) |
| 451 | |
| 452 | #define YYTERROR 1 |
| 453 | #define YYERRCODE 256 |
| 454 | |
| 455 | /* YYLLOC_DEFAULT -- Compute the default location (before the actions |
| 456 | are run). */ |
| 457 | |
| 458 | #ifndef YYLLOC_DEFAULT |
| 459 | # define YYLLOC_DEFAULT(Current, Rhs, N) \ |
| 460 | ((Current).first_line = (Rhs)[1].first_line, \ |
| 461 | (Current).first_column = (Rhs)[1].first_column, \ |
| 462 | (Current).last_line = (Rhs)[N].last_line, \ |
| 463 | (Current).last_column = (Rhs)[N].last_column) |
| 464 | #endif |
| 465 | |
| 466 | /* YYLEX -- calling `yylex' with the right arguments. */ |
| 467 | |
| 468 | |
| 469 | /* Enable debugging if requested. */ |
| 470 | #if YYDEBUG |
| 471 | |
| 472 | # ifndef YYFPRINTF |
| 473 | # include <stdio.h> /* INFRINGES ON USER NAME SPACE */ |
| 474 | # define YYFPRINTF fprintf |
| 475 | # endif |
| 476 | |
| 477 | # define YYDPRINTF(Args) \ |
| 478 | do { \ |
| 479 | if (yydebug) \ |
| 480 | YYFPRINTF Args; \ |
| 481 | } while (0) |
| 482 | |
| 483 | # define YYDSYMPRINT(Args) \ |
| 484 | do { \ |
| 485 | if (yydebug) \ |
| 486 | yysymprint Args; \ |
| 487 | } while (0) |
| 488 | |
| 489 | # define YYDSYMPRINTF(Title, Token, Value, Location) \ |
| 490 | do { \ |
| 491 | if (yydebug) \ |
| 492 | { \ |
| 493 | YYFPRINTF (stderr, "%s ", Title); \ |
| 494 | yysymprint (stderr, \ |
| 495 | Token, Value); \ |
| 496 | YYFPRINTF (stderr, "\n"); \ |
| 497 | } \ |
| 498 | } while (0) |
| 499 | |
| 500 | /*------------------------------------------------------------------. |
| 501 | | yy_stack_print -- Print the state stack from its BOTTOM up to its | |
| 502 | | TOP (included). | |
| 503 | `------------------------------------------------------------------*/ |
| 504 | |
| 505 | #if defined (__STDC__) || defined (__cplusplus) |
| 506 | static void |
| 507 | yy_stack_print (short *bottom, short *top) |
| 508 | #else |
| 509 | static void |
| 510 | yy_stack_print (bottom, top) |
| 511 | short *bottom; |
| 512 | short *top; |
| 513 | #endif |
| 514 | { |
| 515 | YYFPRINTF (stderr, "Stack now" ); |
| 516 | for (/* Nothing. */; bottom <= top; ++bottom) |
| 517 | YYFPRINTF (stderr, " %d" , *bottom); |
| 518 | YYFPRINTF (stderr, "\n" ); |
| 519 | } |
| 520 | |
| 521 | # define YY_STACK_PRINT(Bottom, Top) \ |
| 522 | do { \ |
| 523 | if (yydebug) \ |
| 524 | yy_stack_print ((Bottom), (Top)); \ |
| 525 | } while (0) |
| 526 | |
| 527 | |
| 528 | /*------------------------------------------------. |
| 529 | | Report that the YYRULE is going to be reduced. | |
| 530 | `------------------------------------------------*/ |
| 531 | |
| 532 | #if defined (__STDC__) || defined (__cplusplus) |
| 533 | static void |
| 534 | yy_reduce_print (int yyrule) |
| 535 | #else |
| 536 | static void |
| 537 | yy_reduce_print (yyrule) |
| 538 | int yyrule; |
| 539 | #endif |
| 540 | { |
| 541 | int yyi; |
| 542 | unsigned int yylno = yyrline[yyrule]; |
| 543 | YYFPRINTF (stderr, "Reducing stack by rule %d (line %u), " , |
| 544 | yyrule - 1, yylno); |
| 545 | /* Print the symbols being reduced, and their result. */ |
| 546 | for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++) |
| 547 | YYFPRINTF (stderr, "%s " , yytname [yyrhs[yyi]]); |
| 548 | YYFPRINTF (stderr, "-> %s\n" , yytname [yyr1[yyrule]]); |
| 549 | } |
| 550 | |
| 551 | # define YY_REDUCE_PRINT(Rule) \ |
| 552 | do { \ |
| 553 | if (yydebug) \ |
| 554 | yy_reduce_print (Rule); \ |
| 555 | } while (0) |
| 556 | |
| 557 | /* Nonzero means print parse trace. It is left uninitialized so that |
| 558 | multiple parsers can coexist. */ |
| 559 | static int yydebug; |
| 560 | #else /* !YYDEBUG */ |
| 561 | # define YYDPRINTF(Args) |
| 562 | # define YYDSYMPRINT(Args) |
| 563 | # define YYDSYMPRINTF(Title, Token, Value, Location) |
| 564 | # define YY_STACK_PRINT(Bottom, Top) |
| 565 | # define YY_REDUCE_PRINT(Rule) |
| 566 | #endif /* !YYDEBUG */ |
| 567 | |
| 568 | |
| 569 | /* YYINITDEPTH -- initial size of the parser's stacks. */ |
| 570 | #ifndef YYINITDEPTH |
| 571 | # define YYINITDEPTH 200 |
| 572 | #endif |
| 573 | |
| 574 | /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only |
| 575 | if the built-in stack extension method is used). |
| 576 | |
| 577 | Do not make this value too large; the results are undefined if |
| 578 | SIZE_MAX < YYSTACK_BYTES (YYMAXDEPTH) |
| 579 | evaluated with infinite-precision integer arithmetic. */ |
| 580 | |
| 581 | #if defined (YYMAXDEPTH) && YYMAXDEPTH == 0 |
| 582 | # undef YYMAXDEPTH |
| 583 | #endif |
| 584 | |
| 585 | #ifndef YYMAXDEPTH |
| 586 | # define YYMAXDEPTH 10000 |
| 587 | #endif |
| 588 | |
| 589 | |
| 590 | |
| 591 | #if YYERROR_VERBOSE |
| 592 | |
| 593 | # ifndef yystrlen |
| 594 | # if defined (__GLIBC__) && defined (_STRING_H) |
| 595 | # define yystrlen strlen |
| 596 | # else |
| 597 | /* Return the length of YYSTR. */ |
| 598 | static YYSIZE_T |
| 599 | # if defined (__STDC__) || defined (__cplusplus) |
| 600 | yystrlen (const char *yystr) |
| 601 | # else |
| 602 | yystrlen (yystr) |
| 603 | const char *yystr; |
| 604 | # endif |
| 605 | { |
| 606 | const char *yys = yystr; |
| 607 | |
| 608 | while (*yys++ != '\0') |
| 609 | continue; |
| 610 | |
| 611 | return yys - yystr - 1; |
| 612 | } |
| 613 | # endif |
| 614 | # endif |
| 615 | |
| 616 | # ifndef yystpcpy |
| 617 | # if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE) |
| 618 | # define yystpcpy stpcpy |
| 619 | # else |
| 620 | /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in |
| 621 | YYDEST. */ |
| 622 | static char * |
| 623 | # if defined (__STDC__) || defined (__cplusplus) |
| 624 | yystpcpy (char *yydest, const char *yysrc) |
| 625 | # else |
| 626 | yystpcpy (yydest, yysrc) |
| 627 | char *yydest; |
| 628 | const char *yysrc; |
| 629 | # endif |
| 630 | { |
| 631 | char *yyd = yydest; |
| 632 | const char *yys = yysrc; |
| 633 | |
| 634 | while ((*yyd++ = *yys++) != '\0') |
| 635 | continue; |
| 636 | |
| 637 | return yyd - 1; |
| 638 | } |
| 639 | # endif |
| 640 | # endif |
| 641 | |
| 642 | #endif /* !YYERROR_VERBOSE */ |
| 643 | |
| 644 | |
| 645 | |
| 646 | #if YYDEBUG |
| 647 | /*--------------------------------. |
| 648 | | Print this symbol on YYOUTPUT. | |
| 649 | `--------------------------------*/ |
| 650 | |
| 651 | #if defined (__STDC__) || defined (__cplusplus) |
| 652 | static void |
| 653 | yysymprint (FILE *yyoutput, int yytype, YYSTYPE *yyvaluep) |
| 654 | #else |
| 655 | static void |
| 656 | yysymprint (yyoutput, yytype, yyvaluep) |
| 657 | FILE *yyoutput; |
| 658 | int yytype; |
| 659 | YYSTYPE *yyvaluep; |
| 660 | #endif |
| 661 | { |
| 662 | /* Pacify ``unused variable'' warnings. */ |
| 663 | (void) yyvaluep; |
| 664 | |
| 665 | if (yytype < YYNTOKENS) |
| 666 | { |
| 667 | YYFPRINTF (yyoutput, "token %s (" , yytname[yytype]); |
| 668 | # ifdef YYPRINT |
| 669 | YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); |
| 670 | # endif |
| 671 | } |
| 672 | else |
| 673 | YYFPRINTF (yyoutput, "nterm %s (" , yytname[yytype]); |
| 674 | |
| 675 | switch (yytype) |
| 676 | { |
| 677 | default: |
| 678 | break; |
| 679 | } |
| 680 | YYFPRINTF (yyoutput, ")" ); |
| 681 | } |
| 682 | |
| 683 | #endif /* ! YYDEBUG */ |
| 684 | /*-----------------------------------------------. |
| 685 | | Release the memory associated to this symbol. | |
| 686 | `-----------------------------------------------*/ |
| 687 | |
| 688 | #if defined (__STDC__) || defined (__cplusplus) |
| 689 | static void |
| 690 | yydestruct (int yytype, YYSTYPE *yyvaluep) |
| 691 | #else |
| 692 | static void |
| 693 | yydestruct (yytype, yyvaluep) |
| 694 | int yytype; |
| 695 | YYSTYPE *yyvaluep; |
| 696 | #endif |
| 697 | { |
| 698 | /* Pacify ``unused variable'' warnings. */ |
| 699 | (void) yyvaluep; |
| 700 | |
| 701 | //switch (yytype) |
| 702 | // { |
| 703 | |
| 704 | // default: |
| 705 | // break; |
| 706 | // } |
| 707 | } |
| 708 | |
| 709 | |
| 710 | |
| 711 | |
| 712 | static symrec * |
| 713 | putsym ( symrec * & symtable, char const *sym_name, int sym_type) |
| 714 | { |
| 715 | symrec *ptr; |
| 716 | ptr = reinterpret_cast<symrec *> (malloc (sizeof (symrec))); |
| 717 | ptr->name = reinterpret_cast<char *> (malloc (strlen (sym_name) + 1)); |
| 718 | strcpy (ptr->name,sym_name); |
| 719 | ptr->type = sym_type; |
| 720 | ptr->value.var = 0; /* Set value to 0 even if fctn. */ |
| 721 | ptr->next = reinterpret_cast<struct symrec *>(symtable); |
| 722 | symtable = ptr; |
| 723 | return ptr; |
| 724 | } |
| 725 | |
| 726 | static symrec * |
| 727 | getsym ( symrec *symtable,char const *sym_name) |
| 728 | { |
| 729 | symrec *ptr; |
| 730 | for (ptr = symtable; ptr != NULL; |
| 731 | ptr = reinterpret_cast<symrec *>(ptr->next)) |
| 732 | if (strcmp (ptr->name,sym_name) == 0) |
| 733 | return ptr; |
| 734 | return 0; |
| 735 | } |
| 736 | |
| 737 | static void |
| 738 | freesym ( symrec *symtable) |
| 739 | { |
| 740 | symrec *ptr; |
| 741 | for (ptr = symtable; ptr != NULL;) { |
| 742 | free (ptr->name); |
| 743 | symrec * ptrNext = reinterpret_cast<symrec *> (ptr->next) ; |
| 744 | free (ptr); |
| 745 | ptr=ptrNext; |
| 746 | } |
| 747 | } |
| 748 | |
| 749 | /* Called by yyparse on error. */ |
| 750 | static void |
| 751 | yyerror (char const * /*s*/) |
| 752 | { |
| 753 | // Put back if needed |
| 754 | //printf ("%s\n", s); |
| 755 | } |
| 756 | |
| 757 | struct init |
| 758 | { |
| 759 | char const *fname; |
| 760 | double (*fnct) (double); |
| 761 | }; |
| 762 | |
| 763 | inline double sin_wrapper (double x) { return sin(x) ; } |
| 764 | inline double cos_wrapper (double x) { return cos(x) ; } |
| 765 | inline double atan_wrapper (double x) { return atan(x) ; } |
| 766 | inline double log_wrapper (double x) { return log(x) ; } |
| 767 | inline double exp_wrapper (double x) { return exp(x) ; } |
| 768 | inline double sqrt_wrapper (double x) { return sqrt(x) ; } |
| 769 | inline double fabs_wrapper (double x) { return fabs(x) ; } |
| 770 | |
| 771 | struct init const arith_fncts[] = |
| 772 | { |
| 773 | {"sin" , sin_wrapper}, |
| 774 | {"cos" , cos_wrapper}, |
| 775 | {"atan" , atan_wrapper}, |
| 776 | {"ln" , log_wrapper}, |
| 777 | {"exp" , exp_wrapper}, |
| 778 | {"sqrt" , sqrt_wrapper}, |
| 779 | {"fabs" , fabs_wrapper}, |
| 780 | {"abs" , fabs_wrapper}, |
| 781 | {NULL, 0} |
| 782 | }; |
| 783 | |
| 784 | /* The symbol table: a chain of `struct symrec'. */ |
| 785 | |
| 786 | /* Put arithmetic functions in table. */ |
| 787 | static void |
| 788 | init_table ( symrec * &symtable) |
| 789 | { |
| 790 | int i; |
| 791 | symrec *ptr; |
| 792 | for (i = 0; arith_fncts[i].fname != NULL; i++) |
| 793 | { |
| 794 | ptr = putsym ( symtable,arith_fncts[i].fname, FNCT); |
| 795 | ptr->value.fnctptr = arith_fncts[i].fnct; |
| 796 | } |
| 797 | } |
| 798 | |
| 799 | |
| 800 | |
| 801 | static int |
| 802 | yylex ( symrec *&symtable, const char * line, int * position, char * & symbuf, int & length, |
| 803 | const double * associated, const CoinModelHash & string, |
| 804 | int & error, double unsetValue, |
| 805 | YYSTYPE &yylval) |
| 806 | { |
| 807 | int c; |
| 808 | int ipos=*position; |
| 809 | /* Ignore white space, get first nonwhite character. */ |
| 810 | while ((c = line[ipos]) == ' ' || c == '\t') |
| 811 | ipos++; |
| 812 | |
| 813 | if (c == EOF) |
| 814 | return 0; |
| 815 | |
| 816 | /* Char starts a number => parse the number. */ |
| 817 | if (c == '.' || isdigit (c)) |
| 818 | { |
| 819 | sscanf (line+ipos,"%lf" , &yylval.val); |
| 820 | /* Get first white or other character. */ |
| 821 | int nE=0; |
| 822 | int nDot=0; |
| 823 | if (c=='.') |
| 824 | nDot=1; |
| 825 | ipos++; // skip possible sign |
| 826 | while (true) { |
| 827 | c=line[ipos]; |
| 828 | if (isdigit(c)) { |
| 829 | } else if (!nDot&&c=='.') { |
| 830 | nDot=1; |
| 831 | } else if (c=='e'&&!nE) { |
| 832 | nE=1; |
| 833 | if (line[ipos+1]=='+'||line[ipos+1]=='-') |
| 834 | ipos++; |
| 835 | } else { |
| 836 | break; |
| 837 | } |
| 838 | ipos++; |
| 839 | } |
| 840 | *position = ipos; |
| 841 | return NUM; |
| 842 | } |
| 843 | |
| 844 | /* Char starts an identifier => read the name. */ |
| 845 | if (isalpha (c)) |
| 846 | { |
| 847 | symrec *s; |
| 848 | int i; |
| 849 | |
| 850 | /* Initially make the buffer long enough |
| 851 | for a 40-character symbol name. */ |
| 852 | if (length == 0) |
| 853 | length = 40, symbuf = reinterpret_cast<char *>(malloc (length + 1)); |
| 854 | |
| 855 | i = 0; |
| 856 | do |
| 857 | { |
| 858 | /* If buffer is full, make it bigger. */ |
| 859 | if (i == length) |
| 860 | { |
| 861 | length *= 2; |
| 862 | symbuf = reinterpret_cast<char *> (realloc (symbuf, length + 1)); |
| 863 | } |
| 864 | /* Add this character to the buffer. */ |
| 865 | symbuf[i++] = static_cast<char>(c); |
| 866 | /* Get another character. */ |
| 867 | ipos++; |
| 868 | c = line[ipos]; |
| 869 | } |
| 870 | while (isalnum (c)); |
| 871 | |
| 872 | symbuf[i] = '\0'; |
| 873 | |
| 874 | s = getsym ( symtable, symbuf); |
| 875 | if (s == 0) { |
| 876 | // Find in strings |
| 877 | int find = string.hash(symbuf); |
| 878 | double value; |
| 879 | if (find>=0) { |
| 880 | value = associated[find]; |
| 881 | //printf("symbol %s found with value of %g\n",symbuf,value); |
| 882 | if (value==unsetValue) |
| 883 | error=CoinMax(error,1); |
| 884 | } else { |
| 885 | //printf("unknown symbol %s\n",symbuf); |
| 886 | value=unsetValue; |
| 887 | error=3; |
| 888 | } |
| 889 | s = putsym (symtable, symbuf, VAR); |
| 890 | s->value.var=value; |
| 891 | } |
| 892 | yylval.tptr = s; |
| 893 | *position = ipos; |
| 894 | return s->type; |
| 895 | } |
| 896 | |
| 897 | /* Any other character is a token by itself. */ |
| 898 | if (c) { |
| 899 | *position = ipos+1; |
| 900 | return c; |
| 901 | } else { |
| 902 | *position = ipos; |
| 903 | return 10; |
| 904 | } |
| 905 | } |
| 906 | |
| 907 | |
| 908 | /*----------. |
| 909 | | yyparse. | |
| 910 | `----------*/ |
| 911 | |
| 912 | static double yyparse ( symrec *& symtable, const char * line, char * & symbuf, int & length, |
| 913 | const double * associated, const CoinModelHash & string, int & error, |
| 914 | double unsetValue, |
| 915 | int & yychar, YYSTYPE &yylval, int & yynerrs) |
| 916 | { |
| 917 | |
| 918 | int position=0; |
| 919 | int nEof=0; // Number of time send of string |
| 920 | int yystate; |
| 921 | int yyn; |
| 922 | int yyresult; |
| 923 | /* Number of tokens to shift before error messages enabled. */ |
| 924 | int yyerrstatus; |
| 925 | /* Lookahead token as an internal (translated) token number. */ |
| 926 | int yytoken = 0; |
| 927 | |
| 928 | /* Three stacks and their tools: |
| 929 | `yyss': related to states, |
| 930 | `yyvs': related to semantic values, |
| 931 | `yyls': related to locations. |
| 932 | |
| 933 | Refer to the stacks thru separate pointers, to allow yyoverflow |
| 934 | to reallocate them elsewhere. */ |
| 935 | |
| 936 | /* The state stack. */ |
| 937 | short yyssa[YYINITDEPTH]; |
| 938 | short *yyss = yyssa; |
| 939 | short *yyssp; |
| 940 | |
| 941 | /* The semantic value stack. */ |
| 942 | YYSTYPE yyvsa[YYINITDEPTH]; |
| 943 | YYSTYPE *yyvs = yyvsa; |
| 944 | YYSTYPE *yyvsp; |
| 945 | |
| 946 | |
| 947 | |
| 948 | #define YYPOPSTACK (yyvsp--, yyssp--) |
| 949 | |
| 950 | YYSIZE_T yystacksize = YYINITDEPTH; |
| 951 | |
| 952 | /* The variables used to return semantic value and location from the |
| 953 | action routines. */ |
| 954 | YYSTYPE yyval; |
| 955 | |
| 956 | |
| 957 | /* When reducing, the number of symbols on the RHS of the reduced |
| 958 | rule. */ |
| 959 | int yylen; |
| 960 | |
| 961 | YYDPRINTF ((stderr, "Starting parse\n" )); |
| 962 | |
| 963 | yystate = 0; |
| 964 | yyerrstatus = 0; |
| 965 | yynerrs = 0; |
| 966 | yychar = YYEMPTY; /* Cause a token to be read. */ |
| 967 | |
| 968 | /* Initialize stack pointers. |
| 969 | Waste one element of value and location stack |
| 970 | so that they stay on the same level as the state stack. |
| 971 | The wasted elements are never initialized. */ |
| 972 | |
| 973 | yyssp = yyss; |
| 974 | yyvsp = yyvs; |
| 975 | |
| 976 | goto yysetstate; |
| 977 | |
| 978 | /*------------------------------------------------------------. |
| 979 | | yynewstate -- Push a new state, which is found in yystate. | |
| 980 | `------------------------------------------------------------*/ |
| 981 | yynewstate: |
| 982 | /* In all cases, when you get here, the value and location stacks |
| 983 | have just been pushed. so pushing a state here evens the stacks. |
| 984 | */ |
| 985 | yyssp++; |
| 986 | |
| 987 | yysetstate: |
| 988 | *yyssp = static_cast<short>(yystate); |
| 989 | |
| 990 | if (yyss + yystacksize - 1 <= yyssp) |
| 991 | { |
| 992 | /* Get the current used size of the three stacks, in elements. */ |
| 993 | YYSIZE_T yysize = yyssp - yyss + 1; |
| 994 | |
| 995 | #ifdef yyoverflow |
| 996 | { |
| 997 | /* Give user a chance to reallocate the stack. Use copies of |
| 998 | these so that the &'s don't force the real ones into |
| 999 | memory. */ |
| 1000 | YYSTYPE *yyvs1 = yyvs; |
| 1001 | short *yyss1 = yyss; |
| 1002 | |
| 1003 | |
| 1004 | /* Each stack pointer address is followed by the size of the |
| 1005 | data in use in that stack, in bytes. This used to be a |
| 1006 | conditional around just the two extra args, but that might |
| 1007 | be undefined if yyoverflow is a macro. */ |
| 1008 | yyoverflow ("parser stack overflow" , |
| 1009 | &yyss1, yysize * sizeof (*yyssp), |
| 1010 | &yyvs1, yysize * sizeof (*yyvsp), |
| 1011 | |
| 1012 | &yystacksize); |
| 1013 | |
| 1014 | yyss = yyss1; |
| 1015 | yyvs = yyvs1; |
| 1016 | } |
| 1017 | #else /* no yyoverflow */ |
| 1018 | # ifndef YYSTACK_RELOCATE |
| 1019 | goto yyoverflowlab; |
| 1020 | # else |
| 1021 | /* Extend the stack our own way. */ |
| 1022 | if (YYMAXDEPTH <= yystacksize) |
| 1023 | goto yyoverflowlab; |
| 1024 | yystacksize *= 2; |
| 1025 | if (YYMAXDEPTH < yystacksize) |
| 1026 | yystacksize = YYMAXDEPTH; |
| 1027 | |
| 1028 | { |
| 1029 | short *yyss1 = yyss; |
| 1030 | union yyalloc *yyptr = |
| 1031 | reinterpret_cast<union yyalloc *> (YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize))); |
| 1032 | if (! yyptr) |
| 1033 | goto yyoverflowlab; |
| 1034 | YYSTACK_RELOCATE (yyss); |
| 1035 | YYSTACK_RELOCATE (yyvs); |
| 1036 | |
| 1037 | # undef YYSTACK_RELOCATE |
| 1038 | if (yyss1 != yyssa) |
| 1039 | YYSTACK_FREE (yyss1); |
| 1040 | } |
| 1041 | # endif |
| 1042 | #endif /* no yyoverflow */ |
| 1043 | |
| 1044 | yyssp = yyss + yysize - 1; |
| 1045 | yyvsp = yyvs + yysize - 1; |
| 1046 | |
| 1047 | |
| 1048 | YYDPRINTF ((stderr, "Stack size increased to %lu\n" , |
| 1049 | (unsigned long int) yystacksize)); |
| 1050 | |
| 1051 | if (yyss + yystacksize - 1 <= yyssp) |
| 1052 | YYABORT; |
| 1053 | } |
| 1054 | |
| 1055 | YYDPRINTF ((stderr, "Entering state %d\n" , yystate)); |
| 1056 | |
| 1057 | goto yybackup; |
| 1058 | |
| 1059 | /*-----------. |
| 1060 | | yybackup. | |
| 1061 | `-----------*/ |
| 1062 | yybackup: |
| 1063 | |
| 1064 | /* Do appropriate processing given the current state. */ |
| 1065 | /* Read a lookahead token if we need one and don't already have one. */ |
| 1066 | /* yyresume: */ |
| 1067 | |
| 1068 | /* First try to decide what to do without reference to lookahead token. */ |
| 1069 | |
| 1070 | yyn = yypact[yystate]; |
| 1071 | if (yyn == YYPACT_NINF) |
| 1072 | goto yydefault; |
| 1073 | |
| 1074 | /* Not known => get a lookahead token if don't already have one. */ |
| 1075 | |
| 1076 | /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ |
| 1077 | if (yychar == YYEMPTY) |
| 1078 | { |
| 1079 | YYDPRINTF ((stderr, "Reading a token: " )); |
| 1080 | yychar = yylex( symtable, line,&position,symbuf,length, |
| 1081 | associated,string,error,unsetValue,yylval); |
| 1082 | if (yychar==10) { |
| 1083 | if (nEof) |
| 1084 | yychar=0; |
| 1085 | nEof++; |
| 1086 | } |
| 1087 | } |
| 1088 | |
| 1089 | if (yychar <= YYEOF) |
| 1090 | { |
| 1091 | yychar = yytoken = YYEOF; |
| 1092 | YYDPRINTF ((stderr, "Now at end of input.\n" )); |
| 1093 | } |
| 1094 | else |
| 1095 | { |
| 1096 | yytoken = static_cast<int>(YYTRANSLATE (yychar)); |
| 1097 | YYDSYMPRINTF ("Next token is" , yytoken, &yylval, &yylloc); |
| 1098 | } |
| 1099 | |
| 1100 | /* If the proper action on seeing token YYTOKEN is to reduce or to |
| 1101 | detect an error, take that action. */ |
| 1102 | yyn += yytoken; |
| 1103 | if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) |
| 1104 | goto yydefault; |
| 1105 | yyn = yytable[yyn]; |
| 1106 | if (yyn <= 0) |
| 1107 | { |
| 1108 | if (yyn == 0 || yyn == YYTABLE_NINF) |
| 1109 | goto yyerrlab; |
| 1110 | yyn = -yyn; |
| 1111 | goto yyreduce; |
| 1112 | } |
| 1113 | |
| 1114 | if (yyn == YYFINAL) |
| 1115 | YYACCEPT; |
| 1116 | |
| 1117 | /* Shift the lookahead token. */ |
| 1118 | YYDPRINTF ((stderr, "Shifting token %s, " , yytname[yytoken])); |
| 1119 | |
| 1120 | /* Discard the token being shifted unless it is eof. */ |
| 1121 | if (yychar != YYEOF) |
| 1122 | yychar = YYEMPTY; |
| 1123 | |
| 1124 | *++yyvsp = yylval; |
| 1125 | |
| 1126 | |
| 1127 | /* Count tokens shifted since error; after three, turn off error |
| 1128 | status. */ |
| 1129 | if (yyerrstatus) |
| 1130 | yyerrstatus--; |
| 1131 | |
| 1132 | yystate = yyn; |
| 1133 | goto yynewstate; |
| 1134 | |
| 1135 | |
| 1136 | /*-----------------------------------------------------------. |
| 1137 | | yydefault -- do the default action for the current state. | |
| 1138 | `-----------------------------------------------------------*/ |
| 1139 | yydefault: |
| 1140 | yyn = yydefact[yystate]; |
| 1141 | if (yyn == 0) |
| 1142 | goto yyerrlab; |
| 1143 | goto yyreduce; |
| 1144 | |
| 1145 | |
| 1146 | /*-----------------------------. |
| 1147 | | yyreduce -- Do a reduction. | |
| 1148 | `-----------------------------*/ |
| 1149 | yyreduce: |
| 1150 | /* yyn is the number of a rule to reduce with. */ |
| 1151 | yylen = yyr2[yyn]; |
| 1152 | |
| 1153 | /* If YYLEN is nonzero, implement the default value of the action: |
| 1154 | `$$ = $1'. |
| 1155 | |
| 1156 | Otherwise, the following line sets YYVAL to garbage. |
| 1157 | This behavior is undocumented and Bison |
| 1158 | users should not rely upon it. Assigning to YYVAL |
| 1159 | unconditionally makes the parser a bit smaller, and it avoids a |
| 1160 | GCC warning that YYVAL may be used uninitialized. */ |
| 1161 | yyval = yyvsp[1-yylen]; |
| 1162 | |
| 1163 | |
| 1164 | YY_REDUCE_PRINT (yyn); |
| 1165 | switch (yyn) |
| 1166 | { |
| 1167 | case 5: |
| 1168 | { //printf ("\t%.10g\n", yyvsp[-1].val); |
| 1169 | return yyvsp[-1].val;} |
| 1170 | break; |
| 1171 | |
| 1172 | case 6: |
| 1173 | { yyerrok; ;} |
| 1174 | break; |
| 1175 | |
| 1176 | case 7: |
| 1177 | { yyval.val = yyvsp[0].val; ;} |
| 1178 | break; |
| 1179 | |
| 1180 | case 8: |
| 1181 | { yyval.val = yyvsp[0].tptr->value.var; ;} |
| 1182 | break; |
| 1183 | |
| 1184 | case 9: |
| 1185 | { yyval.val = yyvsp[0].val; yyvsp[-2].tptr->value.var = yyvsp[0].val; ;} |
| 1186 | break; |
| 1187 | |
| 1188 | case 10: |
| 1189 | { yyval.val = (*(yyvsp[-3].tptr->value.fnctptr))(yyvsp[-1].val); ;} |
| 1190 | break; |
| 1191 | |
| 1192 | case 11: |
| 1193 | { yyval.val = yyvsp[-2].val + yyvsp[0].val; ;} |
| 1194 | break; |
| 1195 | |
| 1196 | case 12: |
| 1197 | { yyval.val = yyvsp[-2].val - yyvsp[0].val; ;} |
| 1198 | break; |
| 1199 | |
| 1200 | case 13: |
| 1201 | { yyval.val = yyvsp[-2].val * yyvsp[0].val; ;} |
| 1202 | break; |
| 1203 | |
| 1204 | case 14: |
| 1205 | { yyval.val = yyvsp[-2].val / yyvsp[0].val; ;} |
| 1206 | break; |
| 1207 | |
| 1208 | case 15: |
| 1209 | { yyval.val = -yyvsp[0].val; ;} |
| 1210 | break; |
| 1211 | |
| 1212 | case 16: |
| 1213 | { yyval.val = pow (yyvsp[-2].val, yyvsp[0].val); ;} |
| 1214 | break; |
| 1215 | |
| 1216 | case 17: |
| 1217 | { yyval.val = yyvsp[-1].val; ;} |
| 1218 | break; |
| 1219 | |
| 1220 | |
| 1221 | } |
| 1222 | |
| 1223 | /* Line 993 of yacc.c. */ |
| 1224 | |
| 1225 | yyvsp -= yylen; |
| 1226 | yyssp -= yylen; |
| 1227 | |
| 1228 | |
| 1229 | YY_STACK_PRINT (yyss, yyssp); |
| 1230 | |
| 1231 | *++yyvsp = yyval; |
| 1232 | |
| 1233 | |
| 1234 | /* Now `shift' the result of the reduction. Determine what state |
| 1235 | that goes to, based on the state we popped back to and the rule |
| 1236 | number reduced by. */ |
| 1237 | |
| 1238 | yyn = yyr1[yyn]; |
| 1239 | |
| 1240 | yystate = yypgoto[yyn - YYNTOKENS] + *yyssp; |
| 1241 | if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp) |
| 1242 | yystate = yytable[yystate]; |
| 1243 | else |
| 1244 | yystate = yydefgoto[yyn - YYNTOKENS]; |
| 1245 | |
| 1246 | goto yynewstate; |
| 1247 | |
| 1248 | |
| 1249 | /*------------------------------------. |
| 1250 | | yyerrlab -- here on detecting error | |
| 1251 | `------------------------------------*/ |
| 1252 | yyerrlab: |
| 1253 | /* If not already recovering from an error, report this error. */ |
| 1254 | if (!yyerrstatus) |
| 1255 | { |
| 1256 | error = CoinMax(error,2); |
| 1257 | ++yynerrs; |
| 1258 | #if YYERROR_VERBOSE |
| 1259 | yyn = yypact[yystate]; |
| 1260 | |
| 1261 | if (YYPACT_NINF < yyn && yyn < YYLAST) |
| 1262 | { |
| 1263 | YYSIZE_T yysize = 0; |
| 1264 | int yytype = YYTRANSLATE (yychar); |
| 1265 | const char* yyprefix; |
| 1266 | char *yymsg; |
| 1267 | int yyx; |
| 1268 | |
| 1269 | /* Start YYX at -YYN if negative to avoid negative indexes in |
| 1270 | YYCHECK. */ |
| 1271 | int yyxbegin = yyn < 0 ? -yyn : 0; |
| 1272 | |
| 1273 | /* Stay within bounds of both yycheck and yytname. */ |
| 1274 | int yychecklim = YYLAST - yyn; |
| 1275 | int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; |
| 1276 | int yycount = 0; |
| 1277 | |
| 1278 | yyprefix = ", expecting " ; |
| 1279 | for (yyx = yyxbegin; yyx < yyxend; ++yyx) |
| 1280 | if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) |
| 1281 | { |
| 1282 | yysize += yystrlen (yyprefix) + yystrlen (yytname [yyx]); |
| 1283 | yycount += 1; |
| 1284 | if (yycount == 5) |
| 1285 | { |
| 1286 | yysize = 0; |
| 1287 | break; |
| 1288 | } |
| 1289 | } |
| 1290 | yysize += (sizeof ("syntax error, unexpected " ) |
| 1291 | + yystrlen (yytname[yytype])); |
| 1292 | yymsg = (char *) YYSTACK_ALLOC (yysize); |
| 1293 | if (yymsg != 0) |
| 1294 | { |
| 1295 | char *yyp = yystpcpy (yymsg, "syntax error, unexpected " ); |
| 1296 | yyp = yystpcpy (yyp, yytname[yytype]); |
| 1297 | |
| 1298 | if (yycount < 5) |
| 1299 | { |
| 1300 | yyprefix = ", expecting " ; |
| 1301 | for (yyx = yyxbegin; yyx < yyxend; ++yyx) |
| 1302 | if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) |
| 1303 | { |
| 1304 | yyp = yystpcpy (yyp, yyprefix); |
| 1305 | yyp = yystpcpy (yyp, yytname[yyx]); |
| 1306 | yyprefix = " or " ; |
| 1307 | } |
| 1308 | } |
| 1309 | yyerror (yymsg); |
| 1310 | YYSTACK_FREE (yymsg); |
| 1311 | } |
| 1312 | else |
| 1313 | yyerror ("syntax error; also virtual memory exhausted" ); |
| 1314 | } |
| 1315 | else |
| 1316 | #endif /* YYERROR_VERBOSE */ |
| 1317 | yyerror ("syntax error" ); |
| 1318 | } |
| 1319 | |
| 1320 | |
| 1321 | |
| 1322 | if (yyerrstatus == 3) |
| 1323 | { |
| 1324 | /* If just tried and failed to reuse lookahead token after an |
| 1325 | error, discard it. */ |
| 1326 | |
| 1327 | if (yychar <= YYEOF) |
| 1328 | { |
| 1329 | /* If at end of input, pop the error token, |
| 1330 | then the rest of the stack, then return failure. */ |
| 1331 | if (yychar == YYEOF) |
| 1332 | for (;;) |
| 1333 | { |
| 1334 | YYPOPSTACK; |
| 1335 | if (yyssp == yyss) |
| 1336 | YYABORT; |
| 1337 | YYDSYMPRINTF ("Error: popping" , yystos[*yyssp], yyvsp, yylsp); |
| 1338 | yydestruct (yystos[*yyssp], yyvsp); |
| 1339 | } |
| 1340 | } |
| 1341 | else |
| 1342 | { |
| 1343 | YYDSYMPRINTF ("Error: discarding" , yytoken, &yylval, &yylloc); |
| 1344 | yydestruct (yytoken, &yylval); |
| 1345 | yychar = YYEMPTY; |
| 1346 | |
| 1347 | } |
| 1348 | } |
| 1349 | |
| 1350 | /* Else will try to reuse lookahead token after shifting the error |
| 1351 | token. */ |
| 1352 | goto yyerrlab1; |
| 1353 | |
| 1354 | |
| 1355 | /*---------------------------------------------------. |
| 1356 | | yyerrorlab -- error raised explicitly by YYERROR. | |
| 1357 | `---------------------------------------------------*/ |
| 1358 | //yyerrorlab: |
| 1359 | // |
| 1360 | //#ifdef __GNUC__ |
| 1361 | // /* Pacify GCC when the user code never invokes YYERROR and the label |
| 1362 | // yyerrorlab therefore never appears in user code. */ |
| 1363 | // if (0) |
| 1364 | // goto yyerrorlab; |
| 1365 | //#endif |
| 1366 | |
| 1367 | yyvsp -= yylen; |
| 1368 | yyssp -= yylen; |
| 1369 | yystate = *yyssp; |
| 1370 | goto yyerrlab1; |
| 1371 | |
| 1372 | |
| 1373 | /*-------------------------------------------------------------. |
| 1374 | | yyerrlab1 -- common code for both syntax error and YYERROR. | |
| 1375 | `-------------------------------------------------------------*/ |
| 1376 | yyerrlab1: |
| 1377 | yyerrstatus = 3; /* Each real token shifted decrements this. */ |
| 1378 | |
| 1379 | for (;;) |
| 1380 | { |
| 1381 | yyn = yypact[yystate]; |
| 1382 | if (yyn != YYPACT_NINF) |
| 1383 | { |
| 1384 | yyn += YYTERROR; |
| 1385 | if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) |
| 1386 | { |
| 1387 | yyn = yytable[yyn]; |
| 1388 | if (0 < yyn) |
| 1389 | break; |
| 1390 | } |
| 1391 | } |
| 1392 | |
| 1393 | /* Pop the current state because it cannot handle the error token. */ |
| 1394 | if (yyssp == yyss) |
| 1395 | YYABORT; |
| 1396 | |
| 1397 | YYDSYMPRINTF ("Error: popping" , yystos[*yyssp], yyvsp, yylsp); |
| 1398 | yydestruct (yystos[yystate], yyvsp); |
| 1399 | YYPOPSTACK; |
| 1400 | yystate = *yyssp; |
| 1401 | YY_STACK_PRINT (yyss, yyssp); |
| 1402 | } |
| 1403 | |
| 1404 | if (yyn == YYFINAL) |
| 1405 | YYACCEPT; |
| 1406 | |
| 1407 | YYDPRINTF ((stderr, "Shifting error token, " )); |
| 1408 | |
| 1409 | *++yyvsp = yylval; |
| 1410 | |
| 1411 | |
| 1412 | yystate = yyn; |
| 1413 | goto yynewstate; |
| 1414 | |
| 1415 | |
| 1416 | /*-------------------------------------. |
| 1417 | | yyacceptlab -- YYACCEPT comes here. | |
| 1418 | `-------------------------------------*/ |
| 1419 | yyacceptlab: |
| 1420 | yyresult = 0; |
| 1421 | goto yyreturn; |
| 1422 | |
| 1423 | /*-----------------------------------. |
| 1424 | | yyabortlab -- YYABORT comes here. | |
| 1425 | `-----------------------------------*/ |
| 1426 | yyabortlab: |
| 1427 | yyresult = 1; |
| 1428 | goto yyreturn; |
| 1429 | |
| 1430 | #ifndef yyoverflow |
| 1431 | /*----------------------------------------------. |
| 1432 | | yyoverflowlab -- parser overflow comes here. | |
| 1433 | `----------------------------------------------*/ |
| 1434 | yyoverflowlab: |
| 1435 | yyerror ("parser stack overflow" ); |
| 1436 | yyresult = 2; |
| 1437 | /* Fall through. */ |
| 1438 | #endif |
| 1439 | |
| 1440 | yyreturn: |
| 1441 | #ifndef yyoverflow |
| 1442 | if (yyss != yyssa) |
| 1443 | YYSTACK_FREE (yyss); |
| 1444 | #endif |
| 1445 | return yyresult; |
| 1446 | } |
| 1447 | |
| 1448 | double |
| 1449 | CoinModel::getDoubleFromString(CoinYacc & info,const char * string) |
| 1450 | { |
| 1451 | if (!info.length) { |
| 1452 | info.symtable=NULL; |
| 1453 | info.symbuf=NULL; |
| 1454 | init_table ( info.symtable); |
| 1455 | info.unsetValue=unsetValue(); |
| 1456 | } |
| 1457 | int error=0; |
| 1458 | |
| 1459 | // Here to make thread safe |
| 1460 | /* The lookahead symbol. */ |
| 1461 | int yychar; |
| 1462 | |
| 1463 | /* The semantic value of the lookahead symbol. */ |
| 1464 | YYSTYPE yylval; |
| 1465 | |
| 1466 | /* Number of syntax errors so far. */ |
| 1467 | int yynerrs; |
| 1468 | |
| 1469 | double value = yyparse ( info.symtable, string,info.symbuf,info.length, |
| 1470 | associated_,string_,error,info.unsetValue, |
| 1471 | yychar, yylval, yynerrs); |
| 1472 | |
| 1473 | if (error){ |
| 1474 | // 1 means strings found but unset value |
| 1475 | // 2 syntax error |
| 1476 | // 3 string not found |
| 1477 | if (logLevel_>=1) |
| 1478 | printf("string %s returns value %g and error-code %d\n" , |
| 1479 | string,value,error); |
| 1480 | value = info.unsetValue; |
| 1481 | } else if (logLevel_>=2) { |
| 1482 | printf("%s computes as %g\n" ,string,value); |
| 1483 | } |
| 1484 | return value; |
| 1485 | } |
| 1486 | // Frees value memory |
| 1487 | void |
| 1488 | CoinModel::freeStringMemory(CoinYacc & info) |
| 1489 | { |
| 1490 | freesym( info.symtable); |
| 1491 | free(info.symbuf); |
| 1492 | info.length=0; |
| 1493 | } |
| 1494 | // Adds one string, returns index |
| 1495 | static int |
| 1496 | addString(CoinModelHash & stringX, const char * string) |
| 1497 | { |
| 1498 | int position = stringX.hash(string); |
| 1499 | if (position<0) { |
| 1500 | position = stringX.numberItems(); |
| 1501 | stringX.addHash(position,string); |
| 1502 | } |
| 1503 | return position; |
| 1504 | } |
| 1505 | double |
| 1506 | getFunctionValueFromString(const char * string, const char * x, double xValue) |
| 1507 | { |
| 1508 | CoinYacc info; |
| 1509 | double unset = -1.23456787654321e-97; |
| 1510 | info.length=0; |
| 1511 | info.symtable=NULL; |
| 1512 | info.symbuf=NULL; |
| 1513 | init_table ( info.symtable); |
| 1514 | info.unsetValue=unset; |
| 1515 | int error=0; |
| 1516 | |
| 1517 | double associated[2]; |
| 1518 | associated[0]=xValue; |
| 1519 | associated[1]=unset; |
| 1520 | |
| 1521 | CoinModelHash stringX; |
| 1522 | addString(stringX,x); |
| 1523 | addString(stringX,string); |
| 1524 | |
| 1525 | |
| 1526 | // Here to make thread safe |
| 1527 | /* The lookahead symbol. */ |
| 1528 | int yychar; |
| 1529 | |
| 1530 | /* The semantic value of the lookahead symbol. */ |
| 1531 | YYSTYPE yylval; |
| 1532 | |
| 1533 | /* Number of syntax errors so far. */ |
| 1534 | int yynerrs; |
| 1535 | |
| 1536 | double value = yyparse ( info.symtable, string,info.symbuf,info.length, |
| 1537 | associated,stringX,error,info.unsetValue, |
| 1538 | yychar, yylval, yynerrs); |
| 1539 | |
| 1540 | int logLevel_=2; |
| 1541 | if (error){ |
| 1542 | // 1 means strings found but unset value |
| 1543 | // 2 syntax error |
| 1544 | // 3 string not found |
| 1545 | if (logLevel_>=1) |
| 1546 | printf("string %s returns value %g and error-code %d\n" , |
| 1547 | string,value,error); |
| 1548 | value = unset; |
| 1549 | } else if (logLevel_>=2) { |
| 1550 | printf("%s computes as %g\n" ,string,value); |
| 1551 | } |
| 1552 | freesym( info.symtable); |
| 1553 | free(info.symbuf); |
| 1554 | return value; |
| 1555 | } |
| 1556 | |