source: git/factory/readcf.cc @ f0596e

spielwiese
Last change on this file since f0596e was c404887, checked in by Jens Schmidt <schmidt@…>, 27 years ago
Initial revision git-svn-id: file:///usr/local/Singular/svn/trunk@446 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 23.3 KB
Line 
1
2/*  A Bison parser, made from ../source/readcf.y  */
3
4#define YYBISON 1  /* Identify Bison output.  */
5
6#define NUM     258
7#define NEG     259
8
9#line 4 "../source/readcf.y"
10
11
12#include <config.h>
13
14#include <ctype.h>
15#include <iostream.h>
16
17#include "assert.h"
18
19#include "cf_defs.h"
20#include "canonicalform.h"
21#include "parseutil.h"
22#include "variable.h"
23
24#ifndef BISONPP
25#define YYSTYPE ParseUtil
26#else
27#define YY_parse_USE_GOTO 1
28#define YY_parse_STYPE ParseUtil
29#endif
30
31static char* readString( istream& );
32
33#ifndef BISONPP
34void yyerror( char * s );
35int yylex();
36#endif
37
38static istream * defaultin = 0;
39
40static CanonicalForm * retvalue = 0;
41
42
43#ifndef YYLTYPE
44typedef
45  struct yyltype
46    {
47      int timestamp;
48      int first_line;
49      int first_column;
50      int last_line;
51      int last_column;
52      char *text;
53   }
54  yyltype;
55
56#define YYLTYPE yyltype
57#endif
58
59#ifndef YYSTYPE
60#define YYSTYPE int
61#endif
62#include <stdio.h>
63
64#ifndef __STDC__
65#define const
66#endif
67
68
69
70#define YYFINAL         25
71#define YYFLAG          -32768
72#define YYNTBASE        13
73
74#define YYTRANSLATE(x) ((unsigned)(x) <= 259 ? yytranslate[x] : 16)
75
76static const char yytranslate[] = {     0,
77     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
78     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
79     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
80     2,     2,     2,     2,     2,     2,     2,     2,     2,    11,
81    12,     6,     5,     2,     4,     2,     7,     2,     2,     2,
82     2,     2,     2,     2,     2,     2,     2,     2,    10,     2,
83     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
84     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
85     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
86     2,     2,     2,     9,     2,     2,     2,     2,     2,     2,
87     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
88     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
89     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
90     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
91     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
92     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
93     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
94     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
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,     1,     2,     3,     8
103};
104
105#if YYDEBUG != 0
106static const short yyprhs[] = {     0,
107     0,     1,     4,     6,     9,    11,    15,    19,    23,    27,
108    30,    33,    37
109};
110
111#endif
112
113static const short yyrhs[] = {    -1,
114    13,    14,     0,    10,     0,    15,    10,     0,     3,     0,
115    15,     5,    15,     0,    15,     4,    15,     0,    15,     6,
116    15,     0,    15,     7,    15,     0,     4,    15,     0,     5,
117    15,     0,    15,     9,     3,     0,    11,    15,    12,     0
118};
119
120#if YYDEBUG != 0
121static const short yyrline[] = { 0,
122    49,    50,    53,    54,    57,    58,    59,    60,    61,    62,
123    63,    64,    65
124};
125
126static const char * const yytname[] = {   "$","error","$illegal.","NUM","'-'",
127"'+'","'*'","'/'","NEG","'^'","';'","'('","')'","input","line","exp",""
128};
129#endif
130
131static const short yyr1[] = {     0,
132    13,    13,    14,    14,    15,    15,    15,    15,    15,    15,
133    15,    15,    15
134};
135
136static const short yyr2[] = {     0,
137     0,     2,     1,     2,     1,     3,     3,     3,     3,     2,
138     2,     3,     3
139};
140
141static const short yydefact[] = {     1,
142     0,     5,     0,     0,     3,     0,     2,     0,    10,    11,
143     0,     0,     0,     0,     0,     0,     4,    13,     7,     6,
144     8,     9,    12,     0,     0
145};
146
147static const short yydefgoto[] = {     1,
148     7,     8
149};
150
151static const short yypact[] = {-32768,
152    13,-32768,     3,     3,-32768,     3,-32768,    30,    -7,    -7,
153    21,     3,     3,     3,     3,     1,-32768,-32768,    35,    35,
154    -7,    -7,-32768,     5,-32768
155};
156
157static const short yypgoto[] = {-32768,
158-32768,    -3
159};
160
161
162#define YYLAST          44
163
164
165static const short yytable[] = {     9,
166    10,    16,    11,    23,    25,     2,     3,     4,    19,    20,
167    21,    22,    24,     6,     0,     2,     3,     4,     0,     0,
168     0,     0,     5,     6,    12,    13,    14,    15,     0,    16,
169     0,     0,    18,    12,    13,    14,    15,     0,    16,    17,
170    14,    15,     0,    16
171};
172
173static const short yycheck[] = {     3,
174     4,     9,     6,     3,     0,     3,     4,     5,    12,    13,
175    14,    15,     0,    11,    -1,     3,     4,     5,    -1,    -1,
176    -1,    -1,    10,    11,     4,     5,     6,     7,    -1,     9,
177    -1,    -1,    12,     4,     5,     6,     7,    -1,     9,    10,
178     6,     7,    -1,     9
179};
180/* -*-C-*-  Note some compilers choke on comments on `#line' lines.  */
181#line 3 "/usr/local/lib/bison.simple"
182
183/* Skeleton output parser for bison,
184   Copyright (C) 1984, 1989, 1990 Bob Corbett and Richard Stallman
185
186   This program is free software; you can redistribute it and/or modify
187   it under the terms of the GNU General Public License as published by
188   the Free Software Foundation; either version 1, or (at your option)
189   any later version.
190
191   This program is distributed in the hope that it will be useful,
192   but WITHOUT ANY WARRANTY; without even the implied warranty of
193   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
194   GNU General Public License for more details.
195
196   You should have received a copy of the GNU General Public License
197   along with this program; if not, write to the Free Software
198   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
199
200
201#ifndef alloca
202#ifdef __GNUC__
203#define alloca __builtin_alloca
204#else /* not GNU C.  */
205#if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__)
206#include <alloca.h>
207#else /* not sparc */
208#if defined (MSDOS) && !defined (__TURBOC__)
209#include <malloc.h>
210#else /* not MSDOS, or __TURBOC__ */
211#if defined(_AIX)
212#include <malloc.h>
213 #pragma alloca
214#endif /* not _AIX */
215#endif /* not MSDOS, or __TURBOC__ */
216#endif /* not sparc.  */
217#endif /* not GNU C.  */
218#endif /* alloca not defined.  */
219
220/* This is the parser code that is written into each bison parser
221  when the %semantic_parser declaration is not specified in the grammar.
222  It was written by Richard Stallman by simplifying the hairy parser
223  used when %semantic_parser is specified.  */
224
225/* Note: there must be only one dollar sign in this file.
226   It is replaced by the list of actions, each action
227   as one case of the switch.  */
228
229#define yyerrok         (yyerrstatus = 0)
230#define yyclearin       (yychar = YYEMPTY)
231#define YYEMPTY         -2
232#define YYEOF           0
233#define YYACCEPT        return(0)
234#define YYABORT         return(1)
235#define YYERROR         goto yyerrlab1
236/* Like YYERROR except do call yyerror.
237   This remains here temporarily to ease the
238   transition to the new meaning of YYERROR, for GCC.
239   Once GCC version 2 has supplanted version 1, this can go.  */
240#define YYFAIL          goto yyerrlab
241#define YYRECOVERING()  (!!yyerrstatus)
242#define YYBACKUP(token, value) \
243do                                                              \
244  if (yychar == YYEMPTY && yylen == 1)                          \
245    { yychar = (token), yylval = (value);                       \
246      yychar1 = YYTRANSLATE (yychar);                           \
247      YYPOPSTACK;                                               \
248      goto yybackup;                                            \
249    }                                                           \
250  else                                                          \
251    { yyerror ("syntax error: cannot back up"); YYERROR; }      \
252while (0)
253
254#define YYTERROR        1
255#define YYERRCODE       256
256
257#ifndef YYPURE
258#define YYLEX           yylex()
259#endif
260
261#ifdef YYPURE
262#ifdef YYLSP_NEEDED
263#define YYLEX           yylex(&yylval, &yylloc)
264#else
265#define YYLEX           yylex(&yylval)
266#endif
267#endif
268
269/* If nonreentrant, generate the variables here */
270
271#ifndef YYPURE
272
273int     yychar;                 /*  the lookahead symbol                */
274YYSTYPE yylval;                 /*  the semantic value of the           */
275                                /*  lookahead symbol                    */
276
277#ifdef YYLSP_NEEDED
278YYLTYPE yylloc;                 /*  location data for the lookahead     */
279                                /*  symbol                              */
280#endif
281
282int yynerrs;                    /*  number of parse errors so far       */
283#endif  /* not YYPURE */
284
285#if YYDEBUG != 0
286int yydebug;                    /*  nonzero means print parse trace     */
287/* Since this is uninitialized, it does not stop multiple parsers
288   from coexisting.  */
289#endif
290
291/*  YYINITDEPTH indicates the initial size of the parser's stacks       */
292
293#ifndef YYINITDEPTH
294#define YYINITDEPTH 200
295#endif
296
297/*  YYMAXDEPTH is the maximum size the stacks can grow to
298    (effective only if the built-in stack extension method is used).  */
299
300#if YYMAXDEPTH == 0
301#undef YYMAXDEPTH
302#endif
303
304#ifndef YYMAXDEPTH
305#define YYMAXDEPTH 10000
306#endif
307
308#if __GNUC__ > 1                /* GNU C and GNU C++ define this.  */
309#define __yy_bcopy(FROM,TO,COUNT)       __builtin_memcpy(TO,FROM,COUNT)
310#else                           /* not GNU C or C++ */
311#ifndef __cplusplus
312
313/* This is the most reliable way to avoid incompatibilities
314   in available built-in functions on various systems.  */
315static void
316__yy_bcopy (from, to, count)
317     char *from;
318     char *to;
319     int count;
320{
321  register char *f = from;
322  register char *t = to;
323  register int i = count;
324
325  while (i-- > 0)
326    *t++ = *f++;
327}
328
329#else /* __cplusplus */
330
331/* This is the most reliable way to avoid incompatibilities
332   in available built-in functions on various systems.  */
333static void
334__yy_bcopy (char *from, char *to, int count)
335{
336  register char *f = from;
337  register char *t = to;
338  register int i = count;
339
340  while (i-- > 0)
341    *t++ = *f++;
342}
343
344#endif
345#endif
346
347#line 169 "/usr/local/lib/bison.simple"
348int
349yyparse()
350{
351  register int yystate;
352  register int yyn;
353  register short *yyssp;
354  register YYSTYPE *yyvsp;
355  int yyerrstatus;      /*  number of tokens to shift before error messages enabled */
356  int yychar1;          /*  lookahead token as an internal (translated) token number */
357
358  short yyssa[YYINITDEPTH];     /*  the state stack                     */
359  YYSTYPE yyvsa[YYINITDEPTH];   /*  the semantic value stack            */
360
361  short *yyss = yyssa;          /*  refer to the stacks thru separate pointers */
362  YYSTYPE *yyvs = yyvsa;        /*  to allow yyoverflow to reallocate them elsewhere */
363
364#ifdef YYLSP_NEEDED
365  YYLTYPE yylsa[YYINITDEPTH];   /*  the location stack                  */
366  YYLTYPE *yyls = yylsa;
367  YYLTYPE *yylsp;
368
369#define YYPOPSTACK   (yyvsp--, yyssp--, yylsp--)
370#else
371#define YYPOPSTACK   (yyvsp--, yyssp--)
372#endif
373
374  int yystacksize = YYINITDEPTH;
375
376#ifdef YYPURE
377  int yychar;
378  YYSTYPE yylval;
379  int yynerrs;
380#ifdef YYLSP_NEEDED
381  YYLTYPE yylloc;
382#endif
383#endif
384
385  YYSTYPE yyval;                /*  the variable used to return         */
386                                /*  semantic values from the action     */
387                                /*  routines                            */
388
389  int yylen;
390
391#if YYDEBUG != 0
392  if (yydebug)
393    fprintf(stderr, "Starting parse\n");
394#endif
395
396  yystate = 0;
397  yyerrstatus = 0;
398  yynerrs = 0;
399  yychar = YYEMPTY;             /* Cause a token to be read.  */
400
401  /* Initialize stack pointers.
402     Waste one element of value and location stack
403     so that they stay on the same level as the state stack.  */
404
405  yyssp = yyss - 1;
406  yyvsp = yyvs;
407#ifdef YYLSP_NEEDED
408  yylsp = yyls;
409#endif
410
411/* Push a new state, which is found in  yystate  .  */
412/* In all cases, when you get here, the value and location stacks
413   have just been pushed. so pushing a state here evens the stacks.  */
414yynewstate:
415
416  *++yyssp = yystate;
417
418  if (yyssp >= yyss + yystacksize - 1)
419    {
420      /* Give user a chance to reallocate the stack */
421      /* Use copies of these so that the &'s don't force the real ones into memory. */
422      YYSTYPE *yyvs1 = yyvs;
423      short *yyss1 = yyss;
424#ifdef YYLSP_NEEDED
425      YYLTYPE *yyls1 = yyls;
426#endif
427
428      /* Get the current used size of the three stacks, in elements.  */
429      int size = yyssp - yyss + 1;
430
431#ifdef yyoverflow
432      /* Each stack pointer address is followed by the size of
433         the data in use in that stack, in bytes.  */
434      yyoverflow("parser stack overflow",
435                 &yyss1, size * sizeof (*yyssp),
436                 &yyvs1, size * sizeof (*yyvsp),
437#ifdef YYLSP_NEEDED
438                 &yyls1, size * sizeof (*yylsp),
439#endif
440                 &yystacksize);
441
442      yyss = yyss1; yyvs = yyvs1;
443#ifdef YYLSP_NEEDED
444      yyls = yyls1;
445#endif
446#else /* no yyoverflow */
447      /* Extend the stack our own way.  */
448      if (yystacksize >= YYMAXDEPTH)
449        {
450          yyerror("parser stack overflow");
451          return 2;
452        }
453      yystacksize *= 2;
454      if (yystacksize > YYMAXDEPTH)
455        yystacksize = YYMAXDEPTH;
456      yyss = (short *) alloca (yystacksize * sizeof (*yyssp));
457      __yy_bcopy ((char *)yyss1, (char *)yyss, size * sizeof (*yyssp));
458      yyvs = (YYSTYPE *) alloca (yystacksize * sizeof (*yyvsp));
459      __yy_bcopy ((char *)yyvs1, (char *)yyvs, size * sizeof (*yyvsp));
460#ifdef YYLSP_NEEDED
461      yyls = (YYLTYPE *) alloca (yystacksize * sizeof (*yylsp));
462      __yy_bcopy ((char *)yyls1, (char *)yyls, size * sizeof (*yylsp));
463#endif
464#endif /* no yyoverflow */
465
466      yyssp = yyss + size - 1;
467      yyvsp = yyvs + size - 1;
468#ifdef YYLSP_NEEDED
469      yylsp = yyls + size - 1;
470#endif
471
472#if YYDEBUG != 0
473      if (yydebug)
474        fprintf(stderr, "Stack size increased to %d\n", yystacksize);
475#endif
476
477      if (yyssp >= yyss + yystacksize - 1)
478        YYABORT;
479    }
480
481#if YYDEBUG != 0
482  if (yydebug)
483    fprintf(stderr, "Entering state %d\n", yystate);
484#endif
485
486 yybackup:
487
488/* Do appropriate processing given the current state.  */
489/* Read a lookahead token if we need one and don't already have one.  */
490/* yyresume: */
491
492  /* First try to decide what to do without reference to lookahead token.  */
493
494  yyn = yypact[yystate];
495  if (yyn == YYFLAG)
496    goto yydefault;
497
498  /* Not known => get a lookahead token if don't already have one.  */
499
500  /* yychar is either YYEMPTY or YYEOF
501     or a valid token in external form.  */
502
503  if (yychar == YYEMPTY)
504    {
505#if YYDEBUG != 0
506      if (yydebug)
507        fprintf(stderr, "Reading a token: ");
508#endif
509      yychar = YYLEX;
510    }
511
512  /* Convert token to internal form (in yychar1) for indexing tables with */
513
514  if (yychar <= 0)              /* This means end of input. */
515    {
516      yychar1 = 0;
517      yychar = YYEOF;           /* Don't call YYLEX any more */
518
519#if YYDEBUG != 0
520      if (yydebug)
521        fprintf(stderr, "Now at end of input.\n");
522#endif
523    }
524  else
525    {
526      yychar1 = YYTRANSLATE(yychar);
527
528#if YYDEBUG != 0
529      if (yydebug)
530        {
531          fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]);
532          /* Give the individual parser a way to print the precise meaning
533             of a token, for further debugging info.  */
534#ifdef YYPRINT
535          YYPRINT (stderr, yychar, yylval);
536#endif
537          fprintf (stderr, ")\n");
538        }
539#endif
540    }
541
542  yyn += yychar1;
543  if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
544    goto yydefault;
545
546  yyn = yytable[yyn];
547
548  /* yyn is what to do for this token type in this state.
549     Negative => reduce, -yyn is rule number.
550     Positive => shift, yyn is new state.
551       New state is final state => don't bother to shift,
552       just return success.
553     0, or most negative number => error.  */
554
555  if (yyn < 0)
556    {
557      if (yyn == YYFLAG)
558        goto yyerrlab;
559      yyn = -yyn;
560      goto yyreduce;
561    }
562  else if (yyn == 0)
563    goto yyerrlab;
564
565  if (yyn == YYFINAL)
566    YYACCEPT;
567
568  /* Shift the lookahead token.  */
569
570#if YYDEBUG != 0
571  if (yydebug)
572    fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
573#endif
574
575  /* Discard the token being shifted unless it is eof.  */
576  if (yychar != YYEOF)
577    yychar = YYEMPTY;
578
579  *++yyvsp = yylval;
580#ifdef YYLSP_NEEDED
581  *++yylsp = yylloc;
582#endif
583
584  /* count tokens shifted since error; after three, turn off error status.  */
585  if (yyerrstatus) yyerrstatus--;
586
587  yystate = yyn;
588  goto yynewstate;
589
590/* Do the default action for the current state.  */
591yydefault:
592
593  yyn = yydefact[yystate];
594  if (yyn == 0)
595    goto yyerrlab;
596
597/* Do a reduction.  yyn is the number of a rule to reduce with.  */
598yyreduce:
599  yylen = yyr2[yyn];
600  yyval = yyvsp[1-yylen]; /* implement default value of the action */
601
602#if YYDEBUG != 0
603  if (yydebug)
604    {
605      int i;
606
607      fprintf (stderr, "Reducing via rule %d (line %d), ",
608               yyn, yyrline[yyn]);
609
610      /* Print the symboles being reduced, and their result.  */
611      for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)
612        fprintf (stderr, "%s ", yytname[yyrhs[i]]);
613      fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);
614    }
615#endif
616
617
618  switch (yyn) {
619
620case 4:
621#line 54 "../source/readcf.y"
622{ *retvalue = yyvsp[-1].getval(); return 0; ;
623    break;}
624case 5:
625#line 57 "../source/readcf.y"
626{ yyval = yyvsp[0]; ;
627    break;}
628case 6:
629#line 58 "../source/readcf.y"
630{ yyval = yyvsp[-2].getval() + yyvsp[0].getval(); ;
631    break;}
632case 7:
633#line 59 "../source/readcf.y"
634{ yyval = yyvsp[-2].getval() - yyvsp[0].getval(); ;
635    break;}
636case 8:
637#line 60 "../source/readcf.y"
638{ yyval = yyvsp[-2].getval() * yyvsp[0].getval(); ;
639    break;}
640case 9:
641#line 61 "../source/readcf.y"
642{ yyval = yyvsp[-2].getval() / yyvsp[0].getval(); ;
643    break;}
644case 10:
645#line 62 "../source/readcf.y"
646{ yyval = -yyvsp[0].getval(); ;
647    break;}
648case 11:
649#line 63 "../source/readcf.y"
650{ yyval = yyvsp[0].getval(); ;
651    break;}
652case 12:
653#line 64 "../source/readcf.y"
654{ yyval = power( yyvsp[-2].getval(), yyvsp[0].getintval() ); ;
655    break;}
656case 13:
657#line 65 "../source/readcf.y"
658{ yyval = yyvsp[-1].getval(); ;
659    break;}
660}
661   /* the action file gets copied in in place of this dollarsign */
662#line 440 "/usr/local/lib/bison.simple"
663
664  yyvsp -= yylen;
665  yyssp -= yylen;
666#ifdef YYLSP_NEEDED
667  yylsp -= yylen;
668#endif
669
670#if YYDEBUG != 0
671  if (yydebug)
672    {
673      short *ssp1 = yyss - 1;
674      fprintf (stderr, "state stack now");
675      while (ssp1 != yyssp)
676        fprintf (stderr, " %d", *++ssp1);
677      fprintf (stderr, "\n");
678    }
679#endif
680
681  *++yyvsp = yyval;
682
683#ifdef YYLSP_NEEDED
684  yylsp++;
685  if (yylen == 0)
686    {
687      yylsp->first_line = yylloc.first_line;
688      yylsp->first_column = yylloc.first_column;
689      yylsp->last_line = (yylsp-1)->last_line;
690      yylsp->last_column = (yylsp-1)->last_column;
691      yylsp->text = 0;
692    }
693  else
694    {
695      yylsp->last_line = (yylsp+yylen-1)->last_line;
696      yylsp->last_column = (yylsp+yylen-1)->last_column;
697    }
698#endif
699
700  /* Now "shift" the result of the reduction.
701     Determine what state that goes to,
702     based on the state we popped back to
703     and the rule number reduced by.  */
704
705  yyn = yyr1[yyn];
706
707  yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
708  if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
709    yystate = yytable[yystate];
710  else
711    yystate = yydefgoto[yyn - YYNTBASE];
712
713  goto yynewstate;
714
715yyerrlab:   /* here on detecting error */
716
717  if (! yyerrstatus)
718    /* If not already recovering from an error, report this error.  */
719    {
720      ++yynerrs;
721
722#ifdef YYERROR_VERBOSE
723      yyn = yypact[yystate];
724
725      if (yyn > YYFLAG && yyn < YYLAST)
726        {
727          int size = 0;
728          char *msg;
729          int x, count;
730
731          count = 0;
732          for (x = 0; x < (sizeof(yytname) / sizeof(char *)); x++)
733            if (yycheck[x + yyn] == x)
734              size += strlen(yytname[x]) + 15, count++;
735          msg = (char *) malloc(size + 15);
736          if (msg != 0)
737            {
738              strcpy(msg, "parse error");
739
740              if (count < 5)
741                {
742                  count = 0;
743                  for (x = 0; x < (sizeof(yytname) / sizeof(char *)); x++)
744                    if (yycheck[x + yyn] == x)
745                      {
746                        strcat(msg, count == 0 ? ", expecting `" : " or `");
747                        strcat(msg, yytname[x]);
748                        strcat(msg, "'");
749                        count++;
750                      }
751                }
752              yyerror(msg);
753              free(msg);
754            }
755          else
756            yyerror ("parse error; also virtual memory exceeded");
757        }
758      else
759#endif /* YYERROR_VERBOSE */
760        yyerror("parse error");
761    }
762
763yyerrlab1:   /* here on error raised explicitly by an action */
764
765  if (yyerrstatus == 3)
766    {
767      /* if just tried and failed to reuse lookahead token after an error, discard it.  */
768
769      /* return failure if at end of input */
770      if (yychar == YYEOF)
771        YYABORT;
772
773#if YYDEBUG != 0
774      if (yydebug)
775        fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
776#endif
777
778      yychar = YYEMPTY;
779    }
780
781  /* Else will try to reuse lookahead token
782     after shifting the error token.  */
783
784  yyerrstatus = 3;              /* Each real token shifted decrements this */
785
786  goto yyerrhandle;
787
788yyerrdefault:  /* current state does not do anything special for the error token. */
789
790#if 0
791  /* This is wrong; only states that explicitly want error tokens
792     should shift them.  */
793  yyn = yydefact[yystate];  /* If its default is to accept any token, ok.  Otherwise pop it.*/
794  if (yyn) goto yydefault;
795#endif
796
797yyerrpop:   /* pop the current state because it cannot handle the error token */
798
799  if (yyssp == yyss) YYABORT;
800  yyvsp--;
801  yystate = *--yyssp;
802#ifdef YYLSP_NEEDED
803  yylsp--;
804#endif
805
806#if YYDEBUG != 0
807  if (yydebug)
808    {
809      short *ssp1 = yyss - 1;
810      fprintf (stderr, "Error: state stack now");
811      while (ssp1 != yyssp)
812        fprintf (stderr, " %d", *++ssp1);
813      fprintf (stderr, "\n");
814    }
815#endif
816
817yyerrhandle:
818
819  yyn = yypact[yystate];
820  if (yyn == YYFLAG)
821    goto yyerrdefault;
822
823  yyn += YYTERROR;
824  if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
825    goto yyerrdefault;
826
827  yyn = yytable[yyn];
828  if (yyn < 0)
829    {
830      if (yyn == YYFLAG)
831        goto yyerrpop;
832      yyn = -yyn;
833      goto yyreduce;
834    }
835  else if (yyn == 0)
836    goto yyerrpop;
837
838  if (yyn == YYFINAL)
839    YYACCEPT;
840
841#if YYDEBUG != 0
842  if (yydebug)
843    fprintf(stderr, "Shifting error token, ");
844#endif
845
846  *++yyvsp = yylval;
847#ifdef YYLSP_NEEDED
848  *++yylsp = yylloc;
849#endif
850
851  yystate = yyn;
852  goto yynewstate;
853}
854#line 68 "../source/readcf.y"
855
856
857#ifdef BISONPP
858void YY_parse_CLASS::yyerror( char * s )
859#else
860void yyerror( char * s )
861#endif
862{
863    cerr << s << endl;
864}
865
866#ifdef BISONPP
867int YY_parse_CLASS::yylex()
868#else
869int yylex()
870#endif
871{
872    int c;
873
874    while ((c = defaultin->get()) == ' ' || c == '\t' || c == '\n' ) ;
875    if ( isdigit( c ) ) {
876        defaultin->putback( c );
877        yylval = ParseUtil( readString( *defaultin ) );
878        return NUM;
879    }
880    else if ( isalpha( c ) ) {
881        if ( c == getDefaultVarName() ) {
882            int cc;
883            cc = defaultin->get();
884            if ( cc == '_' ) {
885                ParseUtil index( readString( *defaultin ) );
886#ifdef BISONPP
887                this->yylval = Variable( index.getintval() );
888#else
889                yylval = Variable( index.getintval() );
890#endif
891            }
892            else {
893                defaultin->putback( cc );
894#ifdef BISONPP
895                this->yylval = Variable( (char)c );
896#else
897                yylval = Variable( (char)c );
898#endif
899            }
900        }
901        else {
902#ifdef BISONPP
903            this->yylval = Variable( (char)c );
904#else
905            yylval = Variable( (char)c );
906#endif
907        }
908        return NUM;
909    }
910    return c;
911}
912
913CanonicalForm readCF( istream& str )
914{
915    CanonicalForm theRetvalue;
916    retvalue = new CanonicalForm();
917#ifdef BISONPP
918    YY_parse_CLASS my_parser;
919    defaultin = &str;
920    if ( my_parser.yyparse() == 0 ) {
921        theRetvalue = *retvalue;
922        delete retvalue;
923        return theRetvalue;
924    }
925    else {
926        delete retvalue;
927        return 0;
928    }
929#else
930    defaultin = &str;
931    if ( yyparse() == 0 ) {
932        theRetvalue = *retvalue;
933        delete retvalue;
934        return theRetvalue;
935    }
936    else {
937        delete retvalue;
938        return 0;
939    }
940#endif
941}
942
943char* readString( istream& s )
944{
945    static char * buffer = 0;
946    static int bufsize = 0;
947
948    if ( buffer == 0 ) {
949        bufsize = 10000;
950        buffer = new char[bufsize];
951    }
952    int i = 0, c, goon = 1;
953    while ( goon ) {
954        while ( isdigit( c = s.get() ) && i < bufsize - 2 ) {
955            buffer[i] = c;
956            i++;
957        }
958        if ( isdigit( c ) ) {
959            bufsize += 1000;
960            char * newbuffer = (char*)memcpy( new char[bufsize], buffer, bufsize - 1000 );
961            delete [] buffer;
962            buffer = newbuffer;
963            buffer[i] = c;
964            i++;
965        }
966        else {
967            goon = 0;
968            buffer[i] = '\0';
969            s.putback( c );
970        }
971    }
972    return buffer;
973}
Note: See TracBrowser for help on using the repository browser.