Annotation of capa/capa51/pProj/capaFormulaParser.c, revision 1.2
1.2 ! albertel 1:
! 2: /* A Bison parser, made from capaFormula.y
! 3: by GNU Bison version 1.28 */
! 4:
! 5: #define YYBISON 1 /* Identify Bison output. */
! 6:
1.1 albertel 7: #define yyparse fml_parse
8: #define yylex fml_lex
9: #define yyerror fml_error
1.2 ! albertel 10: #define yylval fml_lval
1.1 albertel 11: #define yychar fml_char
12: #define yydebug fml_debug
13: #define yynerrs fml_nerrs
1.2 ! albertel 14: #define F_NUMBER 257
! 15: #define V_ID 258
! 16: #define F_ID 259
! 17: #define EoI 260
! 18: #define F_ERROR 261
! 19: #define F_PLUS 262
! 20: #define F_MINUS 263
! 21: #define F_MULT 264
! 22: #define F_DIV 265
! 23: #define F_MOD 266
! 24: #define F_POW 267
! 25: #define F_LPAR 268
! 26: #define F_RPAR 269
! 27: #define F_COMMA 270
! 28:
! 29: #line 7 "capaFormula.y"
! 30:
1.1 albertel 31: #include <stdio.h>
32: #include <ctype.h>
33: #include <string.h>
34: #include <math.h>
35: #include "capaParser.h" /* _symbol structure def */
36: #include "capaCommon.h"
37: #include "capaFunction.h"
1.2 ! albertel 38: #ifdef YYSTYPE
! 39: #undef YYSTYPE
! 40: #endif
! 41: #define YYSTYPE Symbol_p
1.1 albertel 42: #include "capaToken.h"
43:
44: #ifdef __hpux
45: #include <stdlib.h>
46: #include <alloca.h>
47: #endif
48:
49: #ifdef FML_DBUG
50: #define FMLDBUG_PR1(xx) { printf(xx); fflush(stdout); }
51: #define FMLDBUG_PR2(xx,yy) { printf(xx,yy); fflush(stdout); }
52: #define FMLDBUG_PR3(xx,yy,zz) { printf(xx,yy,zz); fflush(stdout); }
53: #else
54: #define FMLDBUG_PR1(xx) { }
55: #define FMLDBUG_PR2(xx,yy) { }
56: #define FMLDBUG_PR3(xx,yy,zz) { }
57: #endif
58:
59: #define ADD_op 1
60: #define SUB_op 2
61: #define MUL_op 3
62: #define DIV_op 4
63: #define IDIV_op 5
64: #define NOT_DEFINED_op 9
65:
66:
67: /* =============================================================== */
68:
69: extern int Func_idx;
70: extern Symbol FuncStack[MAX_FUNC_NEST];
1.2 ! albertel 71: void fml_error(char *msg);
1.1 albertel 72: double FormulaVal;
73: int FormulaParseOK=1;
74:
1.2 ! albertel 75: #ifndef YYSTYPE
! 76: #define YYSTYPE int
! 77: #endif
! 78: #include <stdio.h>
! 79:
! 80: #ifndef __cplusplus
! 81: #ifndef __STDC__
! 82: #define const
! 83: #endif
! 84: #endif
! 85:
! 86:
! 87:
! 88: #define YYFINAL 38
! 89: #define YYFLAG -32768
! 90: #define YYNTBASE 17
! 91:
! 92: #define YYTRANSLATE(x) ((unsigned)(x) <= 270 ? yytranslate[x] : 23)
! 93:
! 94: static const char yytranslate[] = { 0,
! 95: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
! 96: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
! 97: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
! 98: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
! 99: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
! 100: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
! 101: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
! 102: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
! 103: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
! 104: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
! 105: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
! 106: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
! 107: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
! 108: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
! 109: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
! 110: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
! 111: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
! 112: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
! 113: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
! 114: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
! 115: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
! 116: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
! 117: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
! 118: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
! 119: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
! 120: 2, 2, 2, 2, 2, 1, 3, 4, 5, 6,
! 121: 7, 8, 9, 10, 11, 12, 13, 14, 15, 16
! 122: };
! 123:
! 124: #if YYDEBUG != 0
! 125: static const short yyprhs[] = { 0,
! 126: 0, 2, 6, 10, 12, 14, 16, 20, 24, 28,
! 127: 30, 34, 36, 40, 42, 46, 51, 53, 56, 59,
! 128: 61
! 129: };
! 130:
! 131: static const short yyrhs[] = { 18,
! 132: 0, 18, 8, 19, 0, 18, 9, 19, 0, 19,
! 133: 0, 7, 0, 1, 0, 19, 10, 20, 0, 19,
! 134: 11, 20, 0, 19, 12, 20, 0, 20, 0, 20,
! 135: 13, 22, 0, 22, 0, 21, 16, 18, 0, 18,
! 136: 0, 5, 14, 15, 0, 5, 14, 21, 15, 0,
! 137: 4, 0, 9, 22, 0, 8, 22, 0, 3, 0,
! 138: 14, 18, 15, 0
1.1 albertel 139: };
1.2 ! albertel 140:
1.1 albertel 141: #endif
1.2 ! albertel 142:
! 143: #if YYDEBUG != 0
! 144: static const short yyrline[] = { 0,
! 145: 66, 84, 85, 86, 87, 88, 91, 92, 93, 94,
! 146: 97, 99, 102, 106, 112, 121, 131, 134, 148, 149,
! 147: 152
! 148: };
! 149: #endif
! 150:
! 151:
! 152: #if YYDEBUG != 0 || defined (YYERROR_VERBOSE)
! 153:
! 154: static const char * const yytname[] = { "$","error","$undefined.","F_NUMBER",
! 155: "V_ID","F_ID","EoI","F_ERROR","F_PLUS","F_MINUS","F_MULT","F_DIV","F_MOD","F_POW",
! 156: "F_LPAR","F_RPAR","F_COMMA","f_expr","block","term","basic_constr","arg_list",
! 157: "basic_item", NULL
! 158: };
! 159: #endif
! 160:
! 161: static const short yyr1[] = { 0,
! 162: 17, 18, 18, 18, 18, 18, 19, 19, 19, 19,
! 163: 20, 20, 21, 21, 22, 22, 22, 22, 22, 22,
! 164: 22
! 165: };
! 166:
! 167: static const short yyr2[] = { 0,
! 168: 1, 3, 3, 1, 1, 1, 3, 3, 3, 1,
! 169: 3, 1, 3, 1, 3, 4, 1, 2, 2, 1,
! 170: 3
! 171: };
! 172:
! 173: static const short yydefact[] = { 0,
! 174: 6, 20, 17, 0, 5, 0, 0, 0, 1, 4,
! 175: 10, 12, 0, 19, 18, 0, 0, 0, 0, 0,
! 176: 0, 0, 15, 14, 0, 21, 2, 3, 7, 8,
! 177: 9, 11, 16, 0, 13, 0, 0, 0
! 178: };
! 179:
! 180: static const short yydefgoto[] = { 36,
! 181: 9, 10, 11, 25, 12
! 182: };
! 183:
! 184: static const short yypact[] = { 20,
! 185: -32768,-32768,-32768, -7,-32768, 27, 27, 20, 37, 28,
! 186: -2,-32768, 5,-32768,-32768, 7, 27, 27, 27, 27,
! 187: 27, 27,-32768, 37, -12,-32768, 28, 28, -2, -2,
! 188: -2,-32768,-32768, 20, 37, 18, 33,-32768
! 189: };
! 190:
! 191: static const short yypgoto[] = {-32768,
! 192: -8, 30, 23,-32768, -5
! 193: };
! 194:
! 195:
! 196: #define YYLAST 48
! 197:
! 198:
! 199: static const short yytable[] = { 16,
! 200: 14, 15, 33, 34, 24, 1, 13, 2, 3, 4,
! 201: 22, 5, 6, 7, 17, 18, 32, 37, 8, 23,
! 202: 1, 26, 2, 3, 4, 35, 5, 6, 7, 2,
! 203: 3, 4, 38, 8, 6, 7, 0, 19, 20, 21,
! 204: 8, 29, 30, 31, 17, 18, 27, 28
! 205: };
! 206:
! 207: static const short yycheck[] = { 8,
! 208: 6, 7, 15, 16, 13, 1, 14, 3, 4, 5,
! 209: 13, 7, 8, 9, 8, 9, 22, 0, 14, 15,
! 210: 1, 15, 3, 4, 5, 34, 7, 8, 9, 3,
! 211: 4, 5, 0, 14, 8, 9, -1, 10, 11, 12,
! 212: 14, 19, 20, 21, 8, 9, 17, 18
! 213: };
! 214: /* -*-C-*- Note some compilers choke on comments on `#line' lines. */
! 215: #line 3 "/usr/share/misc/bison.simple"
! 216: /* This file comes from bison-1.28. */
! 217:
! 218: /* Skeleton output parser for bison,
! 219: Copyright (C) 1984, 1989, 1990 Free Software Foundation, Inc.
! 220:
! 221: This program is free software; you can redistribute it and/or modify
! 222: it under the terms of the GNU General Public License as published by
! 223: the Free Software Foundation; either version 2, or (at your option)
! 224: any later version.
! 225:
! 226: This program is distributed in the hope that it will be useful,
! 227: but WITHOUT ANY WARRANTY; without even the implied warranty of
! 228: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! 229: GNU General Public License for more details.
! 230:
! 231: You should have received a copy of the GNU General Public License
! 232: along with this program; if not, write to the Free Software
! 233: Foundation, Inc., 59 Temple Place - Suite 330,
! 234: Boston, MA 02111-1307, USA. */
! 235:
! 236: /* As a special exception, when this file is copied by Bison into a
! 237: Bison output file, you may use that output file without restriction.
! 238: This special exception was added by the Free Software Foundation
! 239: in version 1.24 of Bison. */
! 240:
! 241: /* This is the parser code that is written into each bison parser
! 242: when the %semantic_parser declaration is not specified in the grammar.
! 243: It was written by Richard Stallman by simplifying the hairy parser
! 244: used when %semantic_parser is specified. */
! 245:
! 246: #ifndef YYSTACK_USE_ALLOCA
! 247: #ifdef alloca
! 248: #define YYSTACK_USE_ALLOCA
! 249: #else /* alloca not defined */
! 250: #ifdef __GNUC__
! 251: #define YYSTACK_USE_ALLOCA
! 252: #define alloca __builtin_alloca
! 253: #else /* not GNU C. */
! 254: #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi) || (defined (__sun) && defined (__i386))
! 255: #define YYSTACK_USE_ALLOCA
! 256: #include <alloca.h>
! 257: #else /* not sparc */
! 258: /* We think this test detects Watcom and Microsoft C. */
! 259: /* This used to test MSDOS, but that is a bad idea
! 260: since that symbol is in the user namespace. */
! 261: #if (defined (_MSDOS) || defined (_MSDOS_)) && !defined (__TURBOC__)
! 262: #if 0 /* No need for malloc.h, which pollutes the namespace;
! 263: instead, just don't use alloca. */
! 264: #include <malloc.h>
! 265: #endif
! 266: #else /* not MSDOS, or __TURBOC__ */
! 267: #if defined(_AIX)
! 268: /* I don't know what this was needed for, but it pollutes the namespace.
! 269: So I turned it off. rms, 2 May 1997. */
! 270: /* #include <malloc.h> */
! 271: #pragma alloca
! 272: #define YYSTACK_USE_ALLOCA
! 273: #else /* not MSDOS, or __TURBOC__, or _AIX */
! 274: #if 0
! 275: #ifdef __hpux /* haible@ilog.fr says this works for HPUX 9.05 and up,
! 276: and on HPUX 10. Eventually we can turn this on. */
! 277: #define YYSTACK_USE_ALLOCA
! 278: #define alloca __builtin_alloca
! 279: #endif /* __hpux */
! 280: #endif
! 281: #endif /* not _AIX */
! 282: #endif /* not MSDOS, or __TURBOC__ */
! 283: #endif /* not sparc */
! 284: #endif /* not GNU C */
! 285: #endif /* alloca not defined */
! 286: #endif /* YYSTACK_USE_ALLOCA not defined */
! 287:
! 288: #ifdef YYSTACK_USE_ALLOCA
! 289: #define YYSTACK_ALLOC alloca
! 290: #else
! 291: #define YYSTACK_ALLOC malloc
! 292: #endif
! 293:
! 294: /* Note: there must be only one dollar sign in this file.
! 295: It is replaced by the list of actions, each action
! 296: as one case of the switch. */
! 297:
! 298: #define yyerrok (yyerrstatus = 0)
! 299: #define yyclearin (yychar = YYEMPTY)
! 300: #define YYEMPTY -2
! 301: #define YYEOF 0
! 302: #define YYACCEPT goto yyacceptlab
! 303: #define YYABORT goto yyabortlab
! 304: #define YYERROR goto yyerrlab1
! 305: /* Like YYERROR except do call yyerror.
! 306: This remains here temporarily to ease the
! 307: transition to the new meaning of YYERROR, for GCC.
! 308: Once GCC version 2 has supplanted version 1, this can go. */
! 309: #define YYFAIL goto yyerrlab
! 310: #define YYRECOVERING() (!!yyerrstatus)
! 311: #define YYBACKUP(token, value) \
! 312: do \
! 313: if (yychar == YYEMPTY && yylen == 1) \
! 314: { yychar = (token), yylval = (value); \
! 315: yychar1 = YYTRANSLATE (yychar); \
! 316: YYPOPSTACK; \
! 317: goto yybackup; \
! 318: } \
! 319: else \
! 320: { yyerror ("syntax error: cannot back up"); YYERROR; } \
! 321: while (0)
! 322:
! 323: #define YYTERROR 1
! 324: #define YYERRCODE 256
! 325:
! 326: #ifndef YYPURE
! 327: #define YYLEX yylex()
1.1 albertel 328: #endif
1.2 ! albertel 329:
! 330: #ifdef YYPURE
! 331: #ifdef YYLSP_NEEDED
! 332: #ifdef YYLEX_PARAM
! 333: #define YYLEX yylex(&yylval, &yylloc, YYLEX_PARAM)
1.1 albertel 334: #else
1.2 ! albertel 335: #define YYLEX yylex(&yylval, &yylloc)
! 336: #endif
! 337: #else /* not YYLSP_NEEDED */
! 338: #ifdef YYLEX_PARAM
! 339: #define YYLEX yylex(&yylval, YYLEX_PARAM)
1.1 albertel 340: #else
1.2 ! albertel 341: #define YYLEX yylex(&yylval)
! 342: #endif
! 343: #endif /* not YYLSP_NEEDED */
1.1 albertel 344: #endif
1.2 ! albertel 345:
! 346: /* If nonreentrant, generate the variables here */
! 347:
! 348: #ifndef YYPURE
! 349:
! 350: int yychar; /* the lookahead symbol */
! 351: YYSTYPE yylval; /* the semantic value of the */
! 352: /* lookahead symbol */
! 353:
! 354: #ifdef YYLSP_NEEDED
! 355: YYLTYPE yylloc; /* location data for the lookahead */
! 356: /* symbol */
1.1 albertel 357: #endif
1.2 ! albertel 358:
! 359: int yynerrs; /* number of parse errors so far */
! 360: #endif /* not YYPURE */
! 361:
! 362: #if YYDEBUG != 0
! 363: int yydebug; /* nonzero means print parse trace */
! 364: /* Since this is uninitialized, it does not stop multiple parsers
! 365: from coexisting. */
! 366: #endif
! 367:
! 368: /* YYINITDEPTH indicates the initial size of the parser's stacks */
! 369:
! 370: #ifndef YYINITDEPTH
! 371: #define YYINITDEPTH 200
! 372: #endif
! 373:
! 374: /* YYMAXDEPTH is the maximum size the stacks can grow to
! 375: (effective only if the built-in stack extension method is used). */
! 376:
! 377: #if YYMAXDEPTH == 0
! 378: #undef YYMAXDEPTH
! 379: #endif
! 380:
! 381: #ifndef YYMAXDEPTH
! 382: #define YYMAXDEPTH 10000
! 383: #endif
! 384:
! 385: /* Define __yy_memcpy. Note that the size argument
! 386: should be passed with type unsigned int, because that is what the non-GCC
! 387: definitions require. With GCC, __builtin_memcpy takes an arg
! 388: of type size_t, but it can handle unsigned int. */
! 389:
! 390: #if __GNUC__ > 1 /* GNU C and GNU C++ define this. */
! 391: #define __yy_memcpy(TO,FROM,COUNT) __builtin_memcpy(TO,FROM,COUNT)
! 392: #else /* not GNU C or C++ */
! 393: #ifndef __cplusplus
! 394:
! 395: /* This is the most reliable way to avoid incompatibilities
! 396: in available built-in functions on various systems. */
! 397: static void
! 398: __yy_memcpy (to, from, count)
! 399: char *to;
! 400: char *from;
! 401: unsigned int count;
1.1 albertel 402: {
1.2 ! albertel 403: register char *f = from;
! 404: register char *t = to;
! 405: register int i = count;
! 406:
! 407: while (i-- > 0)
! 408: *t++ = *f++;
1.1 albertel 409: }
1.2 ! albertel 410:
! 411: #else /* __cplusplus */
! 412:
! 413: /* This is the most reliable way to avoid incompatibilities
! 414: in available built-in functions on various systems. */
! 415: static void
! 416: __yy_memcpy (char *to, char *from, unsigned int count)
1.1 albertel 417: {
1.2 ! albertel 418: register char *t = to;
! 419: register char *f = from;
! 420: register int i = count;
! 421:
! 422: while (i-- > 0)
! 423: *t++ = *f++;
1.1 albertel 424: }
425:
1.2 ! albertel 426: #endif
! 427: #endif
! 428:
! 429: #line 217 "/usr/share/misc/bison.simple"
! 430:
! 431: /* The user can define YYPARSE_PARAM as the name of an argument to be passed
! 432: into yyparse. The argument should have type void *.
! 433: It should actually point to an object.
! 434: Grammar actions can access the variable by casting it
! 435: to the proper pointer type. */
! 436:
! 437: #ifdef YYPARSE_PARAM
! 438: #ifdef __cplusplus
! 439: #define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
! 440: #define YYPARSE_PARAM_DECL
! 441: #else /* not __cplusplus */
! 442: #define YYPARSE_PARAM_ARG YYPARSE_PARAM
! 443: #define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
! 444: #endif /* not __cplusplus */
! 445: #else /* not YYPARSE_PARAM */
! 446: #define YYPARSE_PARAM_ARG
! 447: #define YYPARSE_PARAM_DECL
! 448: #endif /* not YYPARSE_PARAM */
! 449:
! 450: /* Prevent warning if -Wstrict-prototypes. */
! 451: #ifdef __GNUC__
! 452: #ifdef YYPARSE_PARAM
! 453: int yyparse (void *);
! 454: #else
! 455: int yyparse (void);
! 456: #endif
! 457: #endif
! 458:
1.1 albertel 459: int
1.2 ! albertel 460: yyparse(YYPARSE_PARAM_ARG)
! 461: YYPARSE_PARAM_DECL
1.1 albertel 462: {
1.2 ! albertel 463: register int yystate;
! 464: register int yyn;
! 465: register short *yyssp;
! 466: register YYSTYPE *yyvsp;
! 467: int yyerrstatus; /* number of tokens to shift before error messages enabled */
! 468: int yychar1 = 0; /* lookahead token as an internal (translated) token number */
! 469:
! 470: short yyssa[YYINITDEPTH]; /* the state stack */
! 471: YYSTYPE yyvsa[YYINITDEPTH]; /* the semantic value stack */
! 472:
! 473: short *yyss = yyssa; /* refer to the stacks thru separate pointers */
! 474: YYSTYPE *yyvs = yyvsa; /* to allow yyoverflow to reallocate them elsewhere */
! 475:
! 476: #ifdef YYLSP_NEEDED
! 477: YYLTYPE yylsa[YYINITDEPTH]; /* the location stack */
! 478: YYLTYPE *yyls = yylsa;
! 479: YYLTYPE *yylsp;
! 480:
! 481: #define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
! 482: #else
! 483: #define YYPOPSTACK (yyvsp--, yyssp--)
! 484: #endif
! 485:
! 486: int yystacksize = YYINITDEPTH;
! 487: int yyfree_stacks = 0;
! 488:
! 489: #ifdef YYPURE
! 490: int yychar;
! 491: YYSTYPE yylval;
! 492: int yynerrs;
! 493: #ifdef YYLSP_NEEDED
! 494: YYLTYPE yylloc;
! 495: #endif
! 496: #endif
! 497:
! 498: YYSTYPE yyval; /* the variable used to return */
! 499: /* semantic values from the action */
! 500: /* routines */
! 501:
! 502: int yylen;
! 503:
! 504: #if YYDEBUG != 0
! 505: if (yydebug)
! 506: fprintf(stderr, "Starting parse\n");
! 507: #endif
! 508:
! 509: yystate = 0;
! 510: yyerrstatus = 0;
! 511: yynerrs = 0;
! 512: yychar = YYEMPTY; /* Cause a token to be read. */
! 513:
! 514: /* Initialize stack pointers.
! 515: Waste one element of value and location stack
! 516: so that they stay on the same level as the state stack.
! 517: The wasted elements are never initialized. */
! 518:
! 519: yyssp = yyss - 1;
! 520: yyvsp = yyvs;
! 521: #ifdef YYLSP_NEEDED
! 522: yylsp = yyls;
! 523: #endif
! 524:
! 525: /* Push a new state, which is found in yystate . */
! 526: /* In all cases, when you get here, the value and location stacks
! 527: have just been pushed. so pushing a state here evens the stacks. */
! 528: yynewstate:
! 529:
! 530: *++yyssp = yystate;
! 531:
! 532: if (yyssp >= yyss + yystacksize - 1)
! 533: {
! 534: /* Give user a chance to reallocate the stack */
! 535: /* Use copies of these so that the &'s don't force the real ones into memory. */
! 536: YYSTYPE *yyvs1 = yyvs;
! 537: short *yyss1 = yyss;
! 538: #ifdef YYLSP_NEEDED
! 539: YYLTYPE *yyls1 = yyls;
! 540: #endif
! 541:
! 542: /* Get the current used size of the three stacks, in elements. */
! 543: int size = yyssp - yyss + 1;
! 544:
! 545: #ifdef yyoverflow
! 546: /* Each stack pointer address is followed by the size of
! 547: the data in use in that stack, in bytes. */
! 548: #ifdef YYLSP_NEEDED
! 549: /* This used to be a conditional around just the two extra args,
! 550: but that might be undefined if yyoverflow is a macro. */
! 551: yyoverflow("parser stack overflow",
! 552: &yyss1, size * sizeof (*yyssp),
! 553: &yyvs1, size * sizeof (*yyvsp),
! 554: &yyls1, size * sizeof (*yylsp),
! 555: &yystacksize);
! 556: #else
! 557: yyoverflow("parser stack overflow",
! 558: &yyss1, size * sizeof (*yyssp),
! 559: &yyvs1, size * sizeof (*yyvsp),
! 560: &yystacksize);
! 561: #endif
! 562:
! 563: yyss = yyss1; yyvs = yyvs1;
! 564: #ifdef YYLSP_NEEDED
! 565: yyls = yyls1;
! 566: #endif
! 567: #else /* no yyoverflow */
! 568: /* Extend the stack our own way. */
! 569: if (yystacksize >= YYMAXDEPTH)
! 570: {
! 571: yyerror("parser stack overflow");
! 572: if (yyfree_stacks)
! 573: {
! 574: free (yyss);
! 575: free (yyvs);
! 576: #ifdef YYLSP_NEEDED
! 577: free (yyls);
! 578: #endif
! 579: }
! 580: return 2;
! 581: }
! 582: yystacksize *= 2;
! 583: if (yystacksize > YYMAXDEPTH)
! 584: yystacksize = YYMAXDEPTH;
! 585: #ifndef YYSTACK_USE_ALLOCA
! 586: yyfree_stacks = 1;
! 587: #endif
! 588: yyss = (short *) YYSTACK_ALLOC (yystacksize * sizeof (*yyssp));
! 589: __yy_memcpy ((char *)yyss, (char *)yyss1,
! 590: size * (unsigned int) sizeof (*yyssp));
! 591: yyvs = (YYSTYPE *) YYSTACK_ALLOC (yystacksize * sizeof (*yyvsp));
! 592: __yy_memcpy ((char *)yyvs, (char *)yyvs1,
! 593: size * (unsigned int) sizeof (*yyvsp));
! 594: #ifdef YYLSP_NEEDED
! 595: yyls = (YYLTYPE *) YYSTACK_ALLOC (yystacksize * sizeof (*yylsp));
! 596: __yy_memcpy ((char *)yyls, (char *)yyls1,
! 597: size * (unsigned int) sizeof (*yylsp));
! 598: #endif
! 599: #endif /* no yyoverflow */
! 600:
! 601: yyssp = yyss + size - 1;
! 602: yyvsp = yyvs + size - 1;
! 603: #ifdef YYLSP_NEEDED
! 604: yylsp = yyls + size - 1;
! 605: #endif
! 606:
! 607: #if YYDEBUG != 0
! 608: if (yydebug)
! 609: fprintf(stderr, "Stack size increased to %d\n", yystacksize);
! 610: #endif
! 611:
! 612: if (yyssp >= yyss + yystacksize - 1)
! 613: YYABORT;
! 614: }
! 615:
! 616: #if YYDEBUG != 0
! 617: if (yydebug)
! 618: fprintf(stderr, "Entering state %d\n", yystate);
! 619: #endif
! 620:
! 621: goto yybackup;
! 622: yybackup:
! 623:
! 624: /* Do appropriate processing given the current state. */
! 625: /* Read a lookahead token if we need one and don't already have one. */
! 626: /* yyresume: */
! 627:
! 628: /* First try to decide what to do without reference to lookahead token. */
! 629:
! 630: yyn = yypact[yystate];
! 631: if (yyn == YYFLAG)
! 632: goto yydefault;
! 633:
! 634: /* Not known => get a lookahead token if don't already have one. */
! 635:
! 636: /* yychar is either YYEMPTY or YYEOF
! 637: or a valid token in external form. */
! 638:
! 639: if (yychar == YYEMPTY)
! 640: {
! 641: #if YYDEBUG != 0
! 642: if (yydebug)
! 643: fprintf(stderr, "Reading a token: ");
! 644: #endif
! 645: yychar = YYLEX;
! 646: }
! 647:
! 648: /* Convert token to internal form (in yychar1) for indexing tables with */
! 649:
! 650: if (yychar <= 0) /* This means end of input. */
! 651: {
! 652: yychar1 = 0;
! 653: yychar = YYEOF; /* Don't call YYLEX any more */
! 654:
! 655: #if YYDEBUG != 0
! 656: if (yydebug)
! 657: fprintf(stderr, "Now at end of input.\n");
! 658: #endif
! 659: }
! 660: else
! 661: {
! 662: yychar1 = YYTRANSLATE(yychar);
! 663:
! 664: #if YYDEBUG != 0
! 665: if (yydebug)
! 666: {
! 667: fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]);
! 668: /* Give the individual parser a way to print the precise meaning
! 669: of a token, for further debugging info. */
! 670: #ifdef YYPRINT
! 671: YYPRINT (stderr, yychar, yylval);
! 672: #endif
! 673: fprintf (stderr, ")\n");
! 674: }
! 675: #endif
! 676: }
! 677:
! 678: yyn += yychar1;
! 679: if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
! 680: goto yydefault;
! 681:
! 682: yyn = yytable[yyn];
! 683:
! 684: /* yyn is what to do for this token type in this state.
! 685: Negative => reduce, -yyn is rule number.
! 686: Positive => shift, yyn is new state.
! 687: New state is final state => don't bother to shift,
! 688: just return success.
! 689: 0, or most negative number => error. */
! 690:
! 691: if (yyn < 0)
! 692: {
! 693: if (yyn == YYFLAG)
! 694: goto yyerrlab;
! 695: yyn = -yyn;
! 696: goto yyreduce;
! 697: }
! 698: else if (yyn == 0)
1.1 albertel 699: goto yyerrlab;
1.2 ! albertel 700:
! 701: if (yyn == YYFINAL)
! 702: YYACCEPT;
! 703:
! 704: /* Shift the lookahead token. */
! 705:
! 706: #if YYDEBUG != 0
! 707: if (yydebug)
! 708: fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
1.1 albertel 709: #endif
1.2 ! albertel 710:
! 711: /* Discard the token being shifted unless it is eof. */
! 712: if (yychar != YYEOF)
! 713: yychar = YYEMPTY;
! 714:
! 715: *++yyvsp = yylval;
! 716: #ifdef YYLSP_NEEDED
! 717: *++yylsp = yylloc;
1.1 albertel 718: #endif
1.2 ! albertel 719:
! 720: /* count tokens shifted since error; after three, turn off error status. */
! 721: if (yyerrstatus) yyerrstatus--;
! 722:
! 723: yystate = yyn;
! 724: goto yynewstate;
! 725:
! 726: /* Do the default action for the current state. */
! 727: yydefault:
! 728:
! 729: yyn = yydefact[yystate];
! 730: if (yyn == 0)
! 731: goto yyerrlab;
! 732:
! 733: /* Do a reduction. yyn is the number of a rule to reduce with. */
1.1 albertel 734: yyreduce:
1.2 ! albertel 735: yylen = yyr2[yyn];
! 736: if (yylen > 0)
! 737: yyval = yyvsp[1-yylen]; /* implement default value of the action */
! 738:
! 739: #if YYDEBUG != 0
! 740: if (yydebug)
1.1 albertel 741: {
1.2 ! albertel 742: int i;
! 743:
! 744: fprintf (stderr, "Reducing via rule %d (line %d), ",
! 745: yyn, yyrline[yyn]);
! 746:
! 747: /* Print the symbols being reduced, and their result. */
! 748: for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)
! 749: fprintf (stderr, "%s ", yytname[yyrhs[i]]);
! 750: fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);
! 751: }
! 752: #endif
! 753:
! 754:
! 755: switch (yyn) {
! 756:
1.1 albertel 757: case 1:
758: #line 66 "capaFormula.y"
759: { switch(yyvsp[0]->s_type) {
760: case I_VAR:
761: case I_CONSTANT: FormulaVal = (double)(yyvsp[0]->s_int);
762: break;
763: case R_VAR:
764: case R_CONSTANT: FormulaVal = yyvsp[0]->s_real;
765: break;
766: case S_VAR:
767: case S_CONSTANT: FormulaParseOK = 0;
768: break;
769: default: FormulaParseOK = 0;
770: break;
771: }
772: capa_mfree((char *)yyvsp[0]);
773: FMLDBUG_PR1("[f_expr <= block ]\n");
1.2 ! albertel 774: ;
! 775: break;}
1.1 albertel 776: case 2:
777: #line 84 "capaFormula.y"
1.2 ! albertel 778: { yyval = symbols_op(yyvsp[-2], yyvsp[0], ADD_op); ;
! 779: break;}
1.1 albertel 780: case 3:
781: #line 85 "capaFormula.y"
1.2 ! albertel 782: { yyval = symbols_op(yyvsp[-2], yyvsp[0], SUB_op); ;
! 783: break;}
1.1 albertel 784: case 4:
785: #line 86 "capaFormula.y"
1.2 ! albertel 786: { yyval = yyvsp[0]; ;
! 787: break;}
1.1 albertel 788: case 5:
789: #line 87 "capaFormula.y"
1.2 ! albertel 790: { FormulaParseOK = 0; FMLDBUG_PR1("[F_ERROR]\n"); return 0;;
! 791: break;}
1.1 albertel 792: case 6:
793: #line 88 "capaFormula.y"
1.2 ! albertel 794: { FormulaParseOK = 0; FMLDBUG_PR1("[ERROR]\n"); return 0; ;
! 795: break;}
1.1 albertel 796: case 7:
797: #line 91 "capaFormula.y"
1.2 ! albertel 798: { yyval = symbols_op(yyvsp[-2], yyvsp[0], MUL_op); ;
! 799: break;}
1.1 albertel 800: case 8:
801: #line 92 "capaFormula.y"
1.2 ! albertel 802: { yyval = symbols_op(yyvsp[-2], yyvsp[0], DIV_op); ;
! 803: break;}
1.1 albertel 804: case 9:
805: #line 93 "capaFormula.y"
1.2 ! albertel 806: { yyval = symbols_op(yyvsp[-2], yyvsp[0], IDIV_op); ;
! 807: break;}
1.1 albertel 808: case 10:
809: #line 94 "capaFormula.y"
1.2 ! albertel 810: { yyval = yyvsp[0]; ;
! 811: break;}
1.1 albertel 812: case 11:
813: #line 97 "capaFormula.y"
814: { yyval = f_symbol_pow(yyvsp[-2],yyvsp[0]);
1.2 ! albertel 815: FMLDBUG_PR3("[%.16g ^ %.16g] ",yyvsp[-2]->s_real,yyvsp[0]->s_real); ;
! 816: break;}
1.1 albertel 817: case 12:
818: #line 99 "capaFormula.y"
1.2 ! albertel 819: { yyval = yyvsp[0]; ;
! 820: break;}
1.1 albertel 821: case 13:
822: #line 102 "capaFormula.y"
823: { yyval = yyvsp[-2];
824: yyval->s_argc++;
825: yyval->s_argp = addto_arglist(yyvsp[-2]->s_argp, yyvsp[0]);
1.2 ! albertel 826: ;
! 827: break;}
1.1 albertel 828: case 14:
829: #line 106 "capaFormula.y"
830: { yyval = yyvsp[0];
831: yyval->s_argc = 1;
832: yyval->s_argp = new_arglist(yyvsp[0]);
1.2 ! albertel 833: ;
! 834: break;}
1.1 albertel 835: case 15:
836: #line 112 "capaFormula.y"
837: { int tmp;
838:
839: Func_idx--;
840: if(Func_idx >= 0 ) {
841: tmp = match_function(FuncStack[Func_idx].s_name,0);
842: yyval = do_function(tmp, 0, NULL );
843: capa_mfree(FuncStack[Func_idx].s_name);
844: }
1.2 ! albertel 845: ;
! 846: break;}
1.1 albertel 847: case 16:
848: #line 121 "capaFormula.y"
849: { int tmp;
850:
851: Func_idx--;
852: if(Func_idx >= 0 ) {
853: tmp = match_function(FuncStack[Func_idx].s_name,yyvsp[-1]->s_argc);
854: yyval = do_function(tmp, yyvsp[-1]->s_argc, yyvsp[-1]->s_argp);
855: capa_mfree(FuncStack[Func_idx].s_name);
856: free_arglist(yyvsp[-1]->s_argp);
857: }
1.2 ! albertel 858: ;
! 859: break;}
1.1 albertel 860: case 17:
861: #line 131 "capaFormula.y"
862: { FMLDBUG_PR3("[V %s = %.16g] ",yyvsp[0]->s_name, yyvsp[0]->s_real);
863: yyval = yyvsp[0];
1.2 ! albertel 864: ;
! 865: break;}
1.1 albertel 866: case 18:
867: #line 134 "capaFormula.y"
868: { yyval = yyvsp[0];
869: switch(yyvsp[0]->s_type) {
870: case I_VAR: yyval = (Symbol *)capa_malloc(sizeof(Symbol),1);
871: yyval->s_type = I_CONSTANT;
872: case I_CONSTANT: yyval->s_int = - yyvsp[0]->s_int; break;
873: case R_VAR: yyval = (Symbol *)capa_malloc(sizeof(Symbol),1);
874: yyval->s_type = R_CONSTANT;
875: case R_CONSTANT: yyval->s_real = (-1.0)*(yyvsp[0]->s_real);
876: break;
877: case S_VAR:
878: case S_CONSTANT: break;
879: default: break;
880: }
1.2 ! albertel 881: ;
! 882: break;}
1.1 albertel 883: case 19:
884: #line 148 "capaFormula.y"
1.2 ! albertel 885: { yyval = yyvsp[0]; ;
! 886: break;}
1.1 albertel 887: case 20:
888: #line 149 "capaFormula.y"
889: { FMLDBUG_PR2("[F %.16g] ",yyvsp[0]->s_real);
890: yyval = yyvsp[0];
1.2 ! albertel 891: ;
! 892: break;}
1.1 albertel 893: case 21:
894: #line 152 "capaFormula.y"
1.2 ! albertel 895: { yyval = yyvsp[-1]; ;
! 896: break;}
! 897: }
! 898: /* the action file gets copied in in place of this dollarsign */
! 899: #line 543 "/usr/share/misc/bison.simple"
! 900:
! 901: yyvsp -= yylen;
! 902: yyssp -= yylen;
! 903: #ifdef YYLSP_NEEDED
! 904: yylsp -= yylen;
! 905: #endif
! 906:
! 907: #if YYDEBUG != 0
! 908: if (yydebug)
! 909: {
! 910: short *ssp1 = yyss - 1;
! 911: fprintf (stderr, "state stack now");
! 912: while (ssp1 != yyssp)
! 913: fprintf (stderr, " %d", *++ssp1);
! 914: fprintf (stderr, "\n");
! 915: }
! 916: #endif
! 917:
! 918: *++yyvsp = yyval;
! 919:
! 920: #ifdef YYLSP_NEEDED
! 921: yylsp++;
! 922: if (yylen == 0)
! 923: {
! 924: yylsp->first_line = yylloc.first_line;
! 925: yylsp->first_column = yylloc.first_column;
! 926: yylsp->last_line = (yylsp-1)->last_line;
! 927: yylsp->last_column = (yylsp-1)->last_column;
! 928: yylsp->text = 0;
! 929: }
! 930: else
! 931: {
! 932: yylsp->last_line = (yylsp+yylen-1)->last_line;
! 933: yylsp->last_column = (yylsp+yylen-1)->last_column;
! 934: }
! 935: #endif
! 936:
! 937: /* Now "shift" the result of the reduction.
! 938: Determine what state that goes to,
! 939: based on the state we popped back to
! 940: and the rule number reduced by. */
! 941:
! 942: yyn = yyr1[yyn];
! 943:
! 944: yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
! 945: if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
! 946: yystate = yytable[yystate];
! 947: else
! 948: yystate = yydefgoto[yyn - YYNTBASE];
! 949:
! 950: goto yynewstate;
! 951:
! 952: yyerrlab: /* here on detecting error */
! 953:
! 954: if (! yyerrstatus)
! 955: /* If not already recovering from an error, report this error. */
! 956: {
! 957: ++yynerrs;
! 958:
! 959: #ifdef YYERROR_VERBOSE
! 960: yyn = yypact[yystate];
! 961:
! 962: if (yyn > YYFLAG && yyn < YYLAST)
! 963: {
! 964: int size = 0;
! 965: char *msg;
! 966: int x, count;
! 967:
! 968: count = 0;
! 969: /* Start X at -yyn if nec to avoid negative indexes in yycheck. */
! 970: for (x = (yyn < 0 ? -yyn : 0);
! 971: x < (sizeof(yytname) / sizeof(char *)); x++)
! 972: if (yycheck[x + yyn] == x)
! 973: size += strlen(yytname[x]) + 15, count++;
! 974: msg = (char *) malloc(size + 15);
! 975: if (msg != 0)
! 976: {
! 977: strcpy(msg, "parse error");
! 978:
! 979: if (count < 5)
! 980: {
! 981: count = 0;
! 982: for (x = (yyn < 0 ? -yyn : 0);
! 983: x < (sizeof(yytname) / sizeof(char *)); x++)
! 984: if (yycheck[x + yyn] == x)
! 985: {
! 986: strcat(msg, count == 0 ? ", expecting `" : " or `");
! 987: strcat(msg, yytname[x]);
! 988: strcat(msg, "'");
! 989: count++;
! 990: }
! 991: }
! 992: yyerror(msg);
! 993: free(msg);
! 994: }
! 995: else
! 996: yyerror ("parse error; also virtual memory exceeded");
! 997: }
! 998: else
! 999: #endif /* YYERROR_VERBOSE */
! 1000: yyerror("parse error");
! 1001: }
! 1002:
! 1003: goto yyerrlab1;
! 1004: yyerrlab1: /* here on error raised explicitly by an action */
! 1005:
! 1006: if (yyerrstatus == 3)
! 1007: {
! 1008: /* if just tried and failed to reuse lookahead token after an error, discard it. */
! 1009:
! 1010: /* return failure if at end of input */
! 1011: if (yychar == YYEOF)
! 1012: YYABORT;
! 1013:
! 1014: #if YYDEBUG != 0
! 1015: if (yydebug)
! 1016: fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
! 1017: #endif
! 1018:
! 1019: yychar = YYEMPTY;
! 1020: }
! 1021:
! 1022: /* Else will try to reuse lookahead token
! 1023: after shifting the error token. */
! 1024:
! 1025: yyerrstatus = 3; /* Each real token shifted decrements this */
! 1026:
! 1027: goto yyerrhandle;
! 1028:
! 1029: yyerrdefault: /* current state does not do anything special for the error token. */
! 1030:
! 1031: #if 0
! 1032: /* This is wrong; only states that explicitly want error tokens
! 1033: should shift them. */
! 1034: yyn = yydefact[yystate]; /* If its default is to accept any token, ok. Otherwise pop it.*/
! 1035: if (yyn) goto yydefault;
! 1036: #endif
! 1037:
! 1038: yyerrpop: /* pop the current state because it cannot handle the error token */
! 1039:
! 1040: if (yyssp == yyss) YYABORT;
! 1041: yyvsp--;
! 1042: yystate = *--yyssp;
! 1043: #ifdef YYLSP_NEEDED
! 1044: yylsp--;
! 1045: #endif
! 1046:
! 1047: #if YYDEBUG != 0
! 1048: if (yydebug)
! 1049: {
! 1050: short *ssp1 = yyss - 1;
! 1051: fprintf (stderr, "Error: state stack now");
! 1052: while (ssp1 != yyssp)
! 1053: fprintf (stderr, " %d", *++ssp1);
! 1054: fprintf (stderr, "\n");
! 1055: }
! 1056: #endif
! 1057:
! 1058: yyerrhandle:
! 1059:
! 1060: yyn = yypact[yystate];
! 1061: if (yyn == YYFLAG)
! 1062: goto yyerrdefault;
! 1063:
! 1064: yyn += YYTERROR;
! 1065: if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
! 1066: goto yyerrdefault;
! 1067:
! 1068: yyn = yytable[yyn];
! 1069: if (yyn < 0)
! 1070: {
! 1071: if (yyn == YYFLAG)
! 1072: goto yyerrpop;
! 1073: yyn = -yyn;
! 1074: goto yyreduce;
! 1075: }
! 1076: else if (yyn == 0)
! 1077: goto yyerrpop;
! 1078:
! 1079: if (yyn == YYFINAL)
! 1080: YYACCEPT;
! 1081:
! 1082: #if YYDEBUG != 0
! 1083: if (yydebug)
! 1084: fprintf(stderr, "Shifting error token, ");
! 1085: #endif
! 1086:
! 1087: *++yyvsp = yylval;
! 1088: #ifdef YYLSP_NEEDED
! 1089: *++yylsp = yylloc;
! 1090: #endif
! 1091:
! 1092: yystate = yyn;
! 1093: goto yynewstate;
! 1094:
! 1095: yyacceptlab:
! 1096: /* YYACCEPT comes here. */
! 1097: if (yyfree_stacks)
! 1098: {
! 1099: free (yyss);
! 1100: free (yyvs);
! 1101: #ifdef YYLSP_NEEDED
! 1102: free (yyls);
! 1103: #endif
! 1104: }
! 1105: return 0;
! 1106:
! 1107: yyabortlab:
! 1108: /* YYABORT comes here. */
! 1109: if (yyfree_stacks)
! 1110: {
! 1111: free (yyss);
! 1112: free (yyvs);
! 1113: #ifdef YYLSP_NEEDED
! 1114: free (yyls);
! 1115: #endif
! 1116: }
! 1117: return 1;
! 1118: }
! 1119: #line 154 "capaFormula.y"
! 1120:
! 1121: void
! 1122: fml_error(char *msg)
! 1123: {
! 1124: FormulaParseOK=0;
! 1125: printf("Error Parsing: %s\n",msg);
! 1126:
1.1 albertel 1127: }
1.2 ! albertel 1128: /* ---------------------------------------------------- */
! 1129: Symbol *
! 1130: f_symbol_pow(ap,bp) Symbol *ap; Symbol *bp;
! 1131: {
! 1132: Symbol *cp;
! 1133: double a, b;
! 1134: int error = 0;
! 1135:
! 1136: cp = NULL;
! 1137: switch(ap->s_type) {
! 1138: case I_VAR: a = (double)(ap->s_int);
! 1139: break;
! 1140: case I_CONSTANT: a = (double)(ap->s_int); capa_mfree((char *)ap);
! 1141: break;
! 1142: case R_VAR: a = ap->s_real;
! 1143: break;
! 1144: case R_CONSTANT: a = ap->s_real; capa_mfree((char *)ap);
! 1145: break;
! 1146: case S_VAR:
! 1147: case S_CONSTANT:
! 1148: default: error = 1; break;
! 1149: }
! 1150: switch(bp->s_type) {
! 1151: case I_VAR: b = (double)(bp->s_int);
! 1152: break;
! 1153: case I_CONSTANT: b = (double)(bp->s_int); capa_mfree((char *)bp);
! 1154: break;
! 1155: case R_VAR: b = bp->s_real;
! 1156: break;
! 1157: case R_CONSTANT: b = bp->s_real; capa_mfree((char *)bp);
! 1158: break;
! 1159: case S_VAR:
! 1160: case S_CONSTANT:
! 1161: default: error = 1; break;
! 1162: }
! 1163: if (!error) {
! 1164: cp = (Symbol *)capa_malloc(sizeof(Symbol),1);
! 1165: cp->s_type = R_CONSTANT;
! 1166: cp->s_real = pow(a,b);
! 1167:
! 1168: }
! 1169: return (cp);
! 1170: }
! 1171:
! 1172: /* ============================================================================= */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>