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