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