home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / APPS / hl10osrc.lzh / Lib / ParseExpr.tab.cc < prev    next >
Text File  |  1994-04-23  |  23KB  |  846 lines

  1. // This may look like C code, but it is really -*- C++ -*-
  2.  
  3. // A Bison++ parser, made from ParseExpr.y 
  4.  
  5. #ifndef stdin
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #endif
  9.  
  10. #line 20 "ParseExpr.y"
  11.  
  12. #include <stream.h>
  13. #include <common.h>
  14. #include <ctype.h>
  15. #include <Card.h>
  16. #include <PTree.h>
  17.  
  18. static Tree* result = 0;
  19.  
  20. static const struct {
  21.     const char* n;
  22.     Fields f;
  23. } FieldNames[] = {
  24.     { "TYPE", TypeField },
  25.     { "AUTHOR", AuthorField },
  26.     { "TITLE", TitleField },
  27.     { "PUBLISHER", PublisherField },
  28.     { "CITY", CityField },
  29.     { "VOLUME", VolumeField },
  30.     { "YEAR", YearField }
  31. };
  32.  
  33. const NumFields = sizeof(FieldNames) / sizeof(FieldNames[0]);
  34.  
  35. enum TypeErrors {OK, TyOK, NoConstant, NoField, MisMatch};
  36.  
  37. static TypeErrors TypeCheck(Node* a, Node* b)
  38. {
  39.     if (a->type == FieldNode && b->type == FieldNode) return(NoConstant);
  40.     else if (a->type != FieldNode && b->type != FieldNode) return(NoField);
  41.     else if (a->type != FieldNode) return(TypeCheck(b,a));
  42.     else switch (a->value._field) {
  43.         case TypeField: if (b->type == CardTypeNode) return(TyOK);
  44.                 else return(MisMatch);
  45.                 break;
  46.         case AuthorField:
  47.         case TitleField:
  48.         case PublisherField:
  49.         case CityField:    if (b->type == StringNode) return(OK);
  50.                 else return(MisMatch);
  51.                 break;
  52.         case VolumeField:
  53.         case YearField:    if (b->type == IntNode) return(OK);
  54.                 else return(MisMatch);
  55.                 break;
  56.     }
  57. }
  58.  
  59. #define MakeNode(v) (new Node(v))
  60. #define MakeTree(o,l,r) (new Tree(o,l,r))
  61.  
  62. #if YYDEBUG != 0
  63. int yydebug = 0;
  64. #endif
  65.  
  66. #ifdef MESSYDOS
  67. #include "prsexptb.h"
  68. #else
  69. #include "ParseExpr.tab.h"
  70. #endif
  71.  
  72. const int    ParseExpr::INTEGER    = 258;
  73. const int    ParseExpr::STRING    = 259;
  74. const int    ParseExpr::FIELD    = 260;
  75. const int    ParseExpr::CARDTYPE    = 261;
  76. const int    ParseExpr::BADWORD    = 262;
  77. const int    ParseExpr::NOTEQ    = 263;
  78. const int    ParseExpr::LESSEQ    = 264;
  79. const int    ParseExpr::GREATEREQ    = 265;
  80.  
  81.  
  82. #define    YYFINAL        31
  83. #define    YYFLAG        -32768
  84. #define    YYNTBASE    19
  85.  
  86. #define YYTRANSLATE(x) ((unsigned)(x) <= 265 ? yytranslate[x] : 22)
  87.  
  88. static const char yytranslate[] = {     0,
  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,    16,     2,     2,     2,     2,    14,     2,    17,
  93.     18,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  94.      2,     2,     2,     2,     2,     2,     2,     2,     2,    11,
  95.     13,    12,     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,    15,     2,     2,     2,     2,     2,     2,
  102.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  103.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  104.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  105.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  106.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  107.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  108.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  109.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  110.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  111.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  112.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  113.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  114.      2,     2,     2,     2,     2,     1,     2,     3,     4,     5,
  115.      6,     7,     8,     9,    10
  116. };
  117.  
  118. static const short yyrline[] = {     0,
  119.    103,   107,   109,   111,   113,   115,   128,   141,   155,   169,
  120.    183,   199,   201,   203,   205,   207
  121. };
  122.  
  123. static const char * const yytname[] = {     0,
  124. "error","$illegal.","INTEGER","STRING","FIELD","CARDTYPE","BADWORD","NOTEQ","LESSEQ","GREATEREQ",
  125. "'<'","'>'","'='","'&'","'|'","'!'","'('","')'","result"
  126. };
  127.  
  128. static const short yyr1[] = {     0,
  129.     19,    20,    20,    20,    20,    20,    20,    20,    20,    20,
  130.     20,    21,    21,    21,    21,    21
  131. };
  132.  
  133. static const short yyr2[] = {     0,
  134.      1,     3,     2,     3,     3,     3,     3,     3,     3,     3,
  135.      3,     1,     1,     1,     1,     1
  136. };
  137.  
  138. static const short yydefact[] = {     0,
  139.     13,    12,    14,    15,    16,     0,     0,     1,     0,     3,
  140.      0,     0,     0,     0,     0,     0,     0,     0,     0,     2,
  141.      5,     4,     7,    10,    11,     8,     9,     6,     0,     0,
  142.      0
  143. };
  144.  
  145. static const short yydefgoto[] = {    29,
  146.      8,     9
  147. };
  148.  
  149. static const short yypact[] = {    -3,
  150. -32768,-32768,-32768,-32768,-32768,    -3,    -3,    -7,     7,-32768,
  151.     19,    -3,    -3,    25,    25,    25,    25,    25,    25,-32768,
  152. -32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,     9,    10,
  153. -32768
  154. };
  155.  
  156. static const short yypgoto[] = {-32768,
  157.     -1,     8
  158. };
  159.  
  160.  
  161. #define    YYLAST        37
  162.  
  163.  
  164. static const short yytable[] = {     1,
  165.      2,     3,     4,     5,    10,    11,    12,    13,    30,    31,
  166.     21,    22,     6,     7,    14,    15,    16,    17,    18,    19,
  167.      0,    23,    24,    25,    26,    27,    28,     1,     2,     3,
  168.      4,     5,    12,    13,     0,     0,    20
  169. };
  170.  
  171. static const short yycheck[] = {     3,
  172.      4,     5,     6,     7,     6,     7,    14,    15,     0,     0,
  173.     12,    13,    16,    17,     8,     9,    10,    11,    12,    13,
  174.     -1,    14,    15,    16,    17,    18,    19,     3,     4,     5,
  175.      6,     7,    14,    15,    -1,    -1,    18
  176. };
  177. #define YYPURE 1
  178.  
  179. // This may look like C code, but it is really -*- C++ -*-
  180.  
  181. /* Skeleton output parser for bison++,
  182.    Copyright (C) 1984 Bob Corbett and Richard Stallman
  183.    Copyright (C) 1989 Larry M. Augustin
  184.  
  185.    Adapted from the original for C++ by Larry M. Augustin.
  186.  
  187.    This program is free software; you can redistribute it and/or modify
  188.    it under the terms of the GNU General Public License as published by
  189.    the Free Software Foundation; either version 1, or (at your option)
  190.    any later version.
  191.  
  192.    This program is distributed in the hope that it will be useful,
  193.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  194.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  195.    GNU General Public License for more details.
  196.  
  197.    You should have received a copy of the GNU General Public License
  198.    along with this program; if not, write to the Free Software
  199.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  200.  
  201.  
  202. /* This is the parser code that is written into each bison parser
  203.   when the %semantic_parser declaration is not specified in the grammar.
  204.   It was written by Richard Stallman by simplifying the hairy parser
  205.   used when %semantic_parser is specified.  */
  206.  
  207. /* Note: there must be only one dollar sign in this file.
  208.    It is replaced by the list of actions, each action
  209.    as one case of the switch.  */
  210.  
  211. #define yyerrok        (yyerrstatus = 0)
  212. #define yyclearin    (yychar = YYEMPTY)
  213. #define YYEMPTY        -2
  214. #define YYEOF        0
  215. #define YYFAIL        goto yyerrlab;
  216. #define YYACCEPT    return(0)
  217. #define YYABORT     return(1)
  218. #define YYERROR        goto yyerrlab
  219.  
  220. #define YYTERROR    1
  221. #define YYERRCODE    256
  222.  
  223. #ifndef YYIMPURE
  224. #define YYLEX        yylex()
  225. #endif
  226.  
  227. #ifndef YYPURE
  228. #define YYLEX        yylex(&yylval, &yylloc)
  229. #endif
  230.  
  231. /*  YYMAXDEPTH indicates the initial size of the parser's stacks    */
  232.  
  233. #ifndef    YYMAXDEPTH
  234. #define YYMAXDEPTH 200
  235. #endif
  236.  
  237. /*  YYMAXLIMIT is the maximum size the stacks can grow to
  238.     (effective only if the built-in stack extension method is used).  */
  239.  
  240. #ifndef YYMAXLIMIT
  241. #define YYMAXLIMIT 10000
  242. #endif
  243.  
  244. int ParseExpr::yyparse() {
  245.   register int yystate;
  246.   register int yyn;
  247.   register short *yyssp;
  248.   register ParseExpr_YYSTYPE *yyvsp;
  249.   ParseExpr_YYLTYPE *yylsp;
  250.   int yyerrstatus;  // number of tokens to shift before error messages enabled
  251.   int yychar1;        // lookahead token as an internal (translated) token number
  252.  
  253.   short    yyssa[YYMAXDEPTH];    //  the state stack
  254.   ParseExpr_YYSTYPE yyvsa[YYMAXDEPTH];    //  the semantic value stack
  255.   ParseExpr_YYLTYPE yylsa[YYMAXDEPTH];    //  the location stack
  256.  
  257.   short *yyss = yyssa;       //  refer to the stacks thru separate pointers
  258.   ParseExpr_YYSTYPE *yyvs = yyvsa;   //  to allow yyoverflow to reallocate them elsewhere
  259.   ParseExpr_YYLTYPE *yyls = yylsa;
  260.  
  261.   int yymaxdepth = YYMAXDEPTH;
  262.  
  263. #ifndef YYPURE
  264.   int yychar;
  265.   ParseExpr_YYSTYPE yylval;
  266.   ParseExpr_YYLTYPE yylloc;
  267.   int yynerrs;
  268. #endif
  269.  
  270.   ParseExpr_YYSTYPE yyval;        /*  the variable used to return        */
  271.                 /*  semantic values from the action    */
  272.                 /*  routines                */
  273.  
  274.   int yylen;
  275.  
  276. #if YYDEBUG != 0
  277.   if (yydebug)
  278.     fprintf(stderr, "Starting parse\n");
  279. #endif
  280.  
  281.   yystate = 0;
  282.   yyerrstatus = 0;
  283.   yynerrs = 0;
  284.   yychar = YYEMPTY;        /* Cause a token to be read.  */
  285.  
  286.   /* Initialize stack pointers.
  287.      Waste one element of value and location stack
  288.      so that they stay on the same level as the state stack.  */
  289.  
  290.   yyssp = yyss - 1;
  291.   yyvsp = yyvs;
  292.   yylsp = yyls;
  293.  
  294. /* Push a new state, which is found in  yystate  .  */
  295. /* In all cases, when you get here, the value and location stacks
  296.    have just been pushed. so pushing a state here evens the stacks.  */
  297. yynewstate:
  298.  
  299.   *++yyssp = yystate;
  300.  
  301.   if (yyssp >= yyss + yymaxdepth - 1)
  302.     {
  303.       /* Give user a chance to reallocate the stack */
  304.       /* Use copies of these so that the &'s don't force the real ones into memory. */
  305.       ParseExpr_YYSTYPE *yyvs1 = yyvs;
  306.       ParseExpr_YYLTYPE *yyls1 = yyls;
  307.       short *yyss1 = yyss;
  308.  
  309.       /* Get the current used size of the three stacks, in elements.  */
  310.       int size = yyssp - yyss + 1;
  311.  
  312. #ifdef yyoverflow
  313.       /* Each stack pointer address is followed by the size of
  314.      the data in use in that stack, in bytes.  */
  315.       yyoverflow("parser stack overflow",
  316.          &yyss1, size * sizeof (*yyssp),
  317.          &yyvs1, size * sizeof (*yyvsp),
  318.          &yyls1, size * sizeof (*yylsp),
  319.          &yymaxdepth);
  320.  
  321.       yyss = yyss1; yyvs = yyvs1; yyls = yyls1;
  322. #else /* no yyoverflow */
  323.       /* Extend the stack our own way.  */
  324.       if (yymaxdepth >= YYMAXLIMIT)
  325.     yyerror("parser stack overflow");
  326.       yymaxdepth *= 2;
  327.       if (yymaxdepth > YYMAXLIMIT)
  328.     yymaxdepth = YYMAXLIMIT;
  329.       yyss = (short *) alloca (yymaxdepth * sizeof (*yyssp));
  330.       bcopy ((char *)yyss1, (char *)yyss, size * sizeof (*yyssp));
  331.       yyvs = (ParseExpr_YYSTYPE *) alloca (yymaxdepth * sizeof (*yyvsp));
  332.       bcopy ((char *)yyvs1, (char *)yyvs, size * sizeof (*yyvsp));
  333. #ifdef YYLSP_NEEDED
  334.       yyls = (ParseExpr_YYLTYPE *) alloca (yymaxdepth * sizeof (*yylsp));
  335.       bcopy ((char *)yyls1, (char *)yyls, size * sizeof (*yylsp));
  336. #endif // YYLSP_NEEDED
  337. #endif /* no yyoverflow */
  338.  
  339.       yyssp = yyss + size - 1;
  340.       yyvsp = yyvs + size - 1;
  341. #ifdef YYLSP_NEEDED
  342.       yylsp = yyls + size - 1;
  343. #endif
  344.  
  345. #if YYDEBUG != 0
  346.       if (yydebug)
  347.     fprintf(stderr, "Stack size increased to %d\n", yymaxdepth);
  348. #endif
  349.  
  350.       if (yyssp >= yyss + yymaxdepth - 1)
  351.     YYABORT;
  352.     }
  353.  
  354. #if YYDEBUG != 0
  355.   if (yydebug)
  356.     fprintf(stderr, "Entering state %d\n", yystate);
  357. #endif
  358.  
  359. /* Do appropriate processing given the current state.  */
  360. /* Read a lookahead token if we need one and don't already have one.  */
  361.  
  362.   /* First try to decide what to do without reference to lookahead token.  */
  363.  
  364.   yyn = yypact[yystate];
  365.   if (yyn == YYFLAG)
  366.     goto yydefault;
  367.  
  368.   /* Not known => get a lookahead token if don't already have one.  */
  369.  
  370.   /* yychar is either YYEMPTY or YYEOF
  371.      or a valid token in external form.  */
  372.  
  373.   if (yychar == YYEMPTY)
  374.     {
  375. #if YYDEBUG != 0
  376.       if (yydebug)
  377.     fprintf(stderr, "Reading a token: ");
  378. #endif
  379.       yychar = YYLEX;
  380.     }
  381.  
  382.   /* Convert token to internal form (in yychar1) for indexing tables with */
  383.  
  384.   if (yychar <= 0)        /* This means end of input. */
  385.     {
  386.       yychar1 = 0;
  387.       yychar = YYEOF;        /* Don't call YYLEX any more */
  388.  
  389. #if YYDEBUG != 0
  390.       if (yydebug)
  391.     fprintf(stderr, "Now at end of input.\n");
  392. #endif
  393.     }
  394.   else
  395.     {
  396.       yychar1 = YYTRANSLATE(yychar);
  397.  
  398. #if YYDEBUG != 0
  399.       if (yydebug)
  400.     fprintf(stderr, "Next token is %d (%s)\n", yychar, yytname[yychar1]);
  401. #endif
  402.     }
  403.  
  404.   yyn += yychar1;
  405.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
  406.     goto yydefault;
  407.  
  408.   yyn = yytable[yyn];
  409.  
  410.   /* yyn is what to do for this token type in this state.
  411.      Negative => reduce, -yyn is rule number.
  412.      Positive => shift, yyn is new state.
  413.        New state is final state => don't bother to shift,
  414.        just return success.
  415.      0, or most negative number => error.  */
  416.  
  417.   if (yyn < 0)
  418.     {
  419.       if (yyn == YYFLAG)
  420.     goto yyerrlab;
  421.       yyn = -yyn;
  422.       goto yyreduce;
  423.     }
  424.   else if (yyn == 0)
  425.     goto yyerrlab;
  426.  
  427.   if (yyn == YYFINAL)
  428.     YYACCEPT;
  429.  
  430.   /* Shift the lookahead token.  */
  431.  
  432. #if YYDEBUG != 0
  433.   if (yydebug)
  434.     fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
  435. #endif
  436.  
  437.   /* Discard the token being shifted unless it is eof.  */
  438.   if (yychar != YYEOF)
  439.     yychar = YYEMPTY;
  440.  
  441.   *++yyvsp = yylval;
  442. #ifdef YYLSP_NEEDED
  443.   *++yylsp = yylloc;
  444. #endif
  445.  
  446.   /* count tokens shifted since error; after three, turn off error status.  */
  447.   if (yyerrstatus) yyerrstatus--;
  448.  
  449.   yystate = yyn;
  450.   goto yynewstate;
  451.  
  452. /* Do the default action for the current state.  */
  453. yydefault:
  454.  
  455.   yyn = yydefact[yystate];
  456.   if (yyn == 0)
  457.     goto yyerrlab;
  458.  
  459. /* Do a reduction.  yyn is the number of a rule to reduce with.  */
  460. yyreduce:
  461.   yylen = yyr2[yyn];
  462.   yyval = yyvsp[1-yylen]; /* implement default value of the action */
  463.  
  464. #if YYDEBUG != 0
  465.   if (yydebug)
  466.     {
  467.       if (yylen == 1)
  468.     fprintf (stderr, "Reducing 1 value via line %d, ",
  469.          yyrline[yyn]);
  470.       else
  471.     fprintf (stderr, "Reducing %d values via line %d, ",
  472.          yylen, yyrline[yyn]);
  473.     }
  474. #endif
  475.  
  476.  
  477.   switch (yyn) {
  478.  
  479. case 1:
  480. #line 104 "ParseExpr.y"
  481. { result = yyvsp[0].trval; ;
  482.     break;}
  483. case 2:
  484. #line 108 "ParseExpr.y"
  485. { yyval.trval = yyvsp[-1].trval; ;
  486.     break;}
  487. case 3:
  488. #line 110 "ParseExpr.y"
  489. { yyval.trval = MakeTree(Not,MakeNode(yyvsp[0].trval),0); ;
  490.     break;}
  491. case 4:
  492. #line 112 "ParseExpr.y"
  493. { yyval.trval = MakeTree(Or,MakeNode(yyvsp[-2].trval),MakeNode(yyvsp[0].trval)); ;
  494.     break;}
  495. case 5:
  496. #line 114 "ParseExpr.y"
  497. { yyval.trval = MakeTree(And,MakeNode(yyvsp[-2].trval),MakeNode(yyvsp[0].trval)); ;
  498.     break;}
  499. case 6:
  500. #line 116 "ParseExpr.y"
  501. {
  502.                 switch (TypeCheck(yyvsp[-2].nval,yyvsp[0].nval)) {
  503.                     case NoConstant: yyerror("Missing constant!");
  504.                              YYABORT;
  505.                     case NoField: yyerror("Missing field!");
  506.                               YYABORT;
  507.                     case MisMatch: yyerror("Type mismatch!");
  508.                                YYABORT;
  509.                     case TyOK:
  510.                     case OK: yyval.trval = MakeTree(Equal,yyvsp[-2].nval,yyvsp[0].nval);
  511.                 }
  512.             ;
  513.     break;}
  514. case 7:
  515. #line 129 "ParseExpr.y"
  516. {
  517.                 switch (TypeCheck(yyvsp[-2].nval,yyvsp[0].nval)) {
  518.                     case NoConstant: yyerror("Missing constant!");
  519.                              YYABORT;
  520.                     case NoField: yyerror("Missing field!");
  521.                               YYABORT;
  522.                     case MisMatch: yyerror("Type mismatch!");
  523.                                YYABORT;
  524.                     case TyOK:
  525.                     case OK: yyval.trval = MakeTree(NotEqual,yyvsp[-2].nval,yyvsp[0].nval);
  526.                 }
  527.             ;
  528.     break;}
  529. case 8:
  530. #line 142 "ParseExpr.y"
  531. {
  532.                 switch (TypeCheck(yyvsp[-2].nval,yyvsp[0].nval)) {
  533.                     case NoConstant: yyerror("Missing constant!");
  534.                              YYABORT;
  535.                     case NoField: yyerror("Missing field!");
  536.                               YYABORT;
  537.                     case MisMatch: yyerror("Type mismatch!");
  538.                                YYABORT;
  539.                     case TyOK: yyerror("< not allowed for Type");
  540.                            YYABORT;
  541.                     case OK: yyval.trval = MakeTree(Less,yyvsp[-2].nval,yyvsp[0].nval);
  542.                 }
  543.             ;
  544.     break;}
  545. case 9:
  546. #line 156 "ParseExpr.y"
  547. {
  548.                 switch (TypeCheck(yyvsp[-2].nval,yyvsp[0].nval)) {
  549.                     case NoConstant: yyerror("Missing constant!");
  550.                              YYABORT;
  551.                     case NoField: yyerror("Missing field!");
  552.                               YYABORT;
  553.                     case MisMatch: yyerror("Type mismatch!");
  554.                                YYABORT;
  555.                     case TyOK: yyerror("> not allowed for Type");
  556.                            YYABORT;
  557.                     case OK: yyval.trval = MakeTree(Greater,yyvsp[-2].nval,yyvsp[0].nval);
  558.                 }
  559.             ;
  560.     break;}
  561. case 10:
  562. #line 170 "ParseExpr.y"
  563. {
  564.                 switch (TypeCheck(yyvsp[-2].nval,yyvsp[0].nval)) {
  565.                     case NoConstant: yyerror("Missing constant!");
  566.                              YYABORT;
  567.                     case NoField: yyerror("Missing field!");
  568.                               YYABORT;
  569.                     case MisMatch: yyerror("Type mismatch!");
  570.                                YYABORT;
  571.                     case TyOK: yyerror("<= not allowed for Type");
  572.                            YYABORT;
  573.                     case OK: yyval.trval = MakeTree(LessEqual,yyvsp[-2].nval,yyvsp[0].nval);
  574.                 }
  575.             ;
  576.     break;}
  577. case 11:
  578. #line 184 "ParseExpr.y"
  579. {
  580.                 switch (TypeCheck(yyvsp[-2].nval,yyvsp[0].nval)) {
  581.                     case NoConstant: yyerror("Missing constant!");
  582.                              YYABORT;
  583.                     case NoField: yyerror("Missing field!");
  584.                               YYABORT;
  585.                     case MisMatch: yyerror("Type mismatch!");
  586.                                YYABORT;
  587.                     case TyOK: yyerror(">= not allowed for Type");
  588.                            YYABORT;
  589.                     case OK: yyval.trval = MakeTree(GreaterEqual,yyvsp[-2].nval,yyvsp[0].nval);
  590.                 }
  591.             ;
  592.     break;}
  593. case 12:
  594. #line 200 "ParseExpr.y"
  595. { yyval.nval = MakeNode(yyvsp[0].sval); ;
  596.     break;}
  597. case 13:
  598. #line 202 "ParseExpr.y"
  599. { yyval.nval = MakeNode(yyvsp[0].ival); ;
  600.     break;}
  601. case 14:
  602. #line 204 "ParseExpr.y"
  603. { yyval.nval = MakeNode(yyvsp[0].fval); ;
  604.     break;}
  605. case 15:
  606. #line 206 "ParseExpr.y"
  607. { yyval.nval = MakeNode(yyvsp[0].tval); ;
  608.     break;}
  609. case 16:
  610. #line 208 "ParseExpr.y"
  611. { yyerror("Unknown word"); YYABORT; ;
  612.     break;}
  613. }
  614.    /* the action file gets copied in in place of this dollarsign */
  615.  
  616.  
  617.   yyvsp -= yylen;
  618.   yyssp -= yylen;
  619. #ifdef YYLSP_NEEDED
  620.   yylsp -= yylen;
  621. #endif
  622.  
  623. #if YYDEBUG != 0
  624.   if (yydebug)
  625.     {
  626.       short *ssp1 = yyss - 1;
  627.       fprintf (stderr, "state stack now");
  628.       while (ssp1 != yyssp)
  629.     fprintf (stderr, " %d", *++ssp1);
  630.       fprintf (stderr, "\n");
  631.     }
  632. #endif
  633.  
  634.   *++yyvsp = yyval;
  635.  
  636. #ifdef YYLSP_NEEDED
  637.   yylsp++;
  638.   if (yylen == 0)
  639.     {
  640.       yylsp->first_line = yylloc.first_line;
  641.       yylsp->first_column = yylloc.first_column;
  642.       yylsp->last_line = (yylsp-1)->last_line;
  643.       yylsp->last_column = (yylsp-1)->last_column;
  644.       yylsp->text = 0;
  645.     }
  646.   else
  647.     {
  648.       yylsp->last_line = (yylsp+yylen-1)->last_line;
  649.       yylsp->last_column = (yylsp+yylen-1)->last_column;
  650.     }
  651. #endif
  652.  
  653.   /* Now "shift" the result of the reduction.
  654.      Determine what state that goes to,
  655.      based on the state we popped back to
  656.      and the rule number reduced by.  */
  657.  
  658.   yyn = yyr1[yyn];
  659.  
  660.   yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
  661.   if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
  662.     yystate = yytable[yystate];
  663.   else
  664.     yystate = yydefgoto[yyn - YYNTBASE];
  665.  
  666.   goto yynewstate;
  667.  
  668. yyerrlab:   /* here on detecting error */
  669.  
  670.   if (! yyerrstatus)
  671.     /* If not already recovering from an error, report this error.  */
  672.     {
  673.       ++yynerrs;
  674.       yyerror("parse error");
  675.     }
  676.  
  677.   if (yyerrstatus == 3)
  678.     {
  679.       /* if just tried and failed to reuse lookahead token after an error, discard it.  */
  680.  
  681.       /* return failure if at end of input */
  682.       if (yychar == YYEOF)
  683.     YYABORT;
  684.  
  685. #if YYDEBUG != 0
  686.       if (yydebug)
  687.     fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
  688. #endif
  689.  
  690.       yychar = YYEMPTY;
  691.     }
  692.  
  693.   /* Else will try to reuse lookahead token
  694.      after shifting the error token.  */
  695.  
  696.   yyerrstatus = 3;        /* Each real token shifted decrements this */
  697.  
  698.   goto yyerrhandle;
  699.  
  700. yyerrdefault:  /* current state does not do anything special for the error token. */
  701.  
  702. #if 0
  703.   /* This is wrong; only states that explicitly want error tokens
  704.      should shift them.  */
  705.   yyn = yydefact[yystate];  /* If its default is to accept any token, ok.  Otherwise pop it.*/
  706.   if (yyn) goto yydefault;
  707. #endif
  708.  
  709. yyerrpop:   /* pop the current state because it cannot handle the error token */
  710.  
  711.   if (yyssp == yyss) YYABORT;
  712.   yyvsp--;
  713.   yystate = *--yyssp;
  714. #ifdef YYLSP_NEEDED
  715.   yylsp--;
  716. #endif
  717.  
  718. #if YYDEBUG != 0
  719.   if (yydebug)
  720.     {
  721.       short *ssp1 = yyss - 1;
  722.       fprintf (stderr, "Error: state stack now");
  723.       while (ssp1 != yyssp)
  724.     fprintf (stderr, " %d", *++ssp1);
  725.       fprintf (stderr, "\n");
  726.     }
  727. #endif
  728.  
  729. yyerrhandle:
  730.  
  731.   yyn = yypact[yystate];
  732.   if (yyn == YYFLAG)
  733.     goto yyerrdefault;
  734.  
  735.   yyn += YYTERROR;
  736.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
  737.     goto yyerrdefault;
  738.  
  739.   yyn = yytable[yyn];
  740.   if (yyn < 0)
  741.     {
  742.       if (yyn == YYFLAG)
  743.     goto yyerrpop;
  744.       yyn = -yyn;
  745.       goto yyreduce;
  746.     }
  747.   else if (yyn == 0)
  748.     goto yyerrpop;
  749.  
  750.   if (yyn == YYFINAL)
  751.     YYACCEPT;
  752.  
  753. #if YYDEBUG != 0
  754.   if (yydebug)
  755.     fprintf(stderr, "Shifting error token, ");
  756. #endif
  757.  
  758.   *++yyvsp = yylval;
  759. #ifdef YYLSP_NEEDED
  760.   *++yylsp = yylloc;
  761. #endif
  762.  
  763.   yystate = yyn;
  764.   goto yynewstate;
  765. }
  766. #line 211 "ParseExpr.y"
  767.  
  768.  
  769. static char* original;
  770. static char* curpointer;
  771.  
  772. Tree* ParseOnly(char* string)
  773. {
  774.     ParseExpr parser;
  775.     original = string;
  776.     curpointer = original;
  777.     if (parser.yyparse() == 0) return(result);
  778.     else return(0);
  779. }
  780.  
  781. void ParseExpr::yyerror(char* message)
  782. {
  783.     cout << message << "\n";
  784.     cout << original << "\n";
  785.     for (int pos = curpointer-original; pos > 0; pos--) cout << '.';
  786.     cout << "^\n";
  787. }
  788.  
  789. int ParseExpr::yylex()
  790. {
  791.     static char word[256];
  792.     
  793.     while (*curpointer != 0 && *curpointer <= ' ') curpointer++;
  794.     if (*curpointer == 0) return(YYEOF);
  795.     else if (isdigit(*curpointer)) {
  796.         char* p = word;
  797.         while (isdigit(*curpointer)) *p++ = *curpointer++;
  798.         *p++ = 0;
  799.         yylval.ival = atoi(word);
  800.         return(INTEGER);
  801.     } else if (*curpointer == '"') {
  802.         curpointer++;
  803.         char* p = word;
  804.         while (*curpointer != '"') {
  805.             if (*curpointer == '\\') curpointer++;
  806.             *p++ = *curpointer++;
  807.         }
  808.         curpointer++;
  809.         *p++ = 0;
  810.         yylval.sval = new char[strlen(word)+1];
  811.         strcpy(yylval.sval,word);
  812.         return(STRING);
  813.     } else if (isalpha(*curpointer)) {
  814.         char* p = word;
  815.         while (isalpha(*curpointer)) {
  816.             char c = *curpointer++;
  817.             if (islower(c)) *p++ = toupper(c);
  818.             else *p++ = c;
  819.         }
  820.         *p++ = 0;
  821.         if (CardTypeNameP(word)) {
  822.             yylval.tval = NameType(word);
  823.             return(CARDTYPE);
  824.         } else {
  825.             for (int i = 0; i < NumFields; i++) {
  826.                 if (strcmp(word,FieldNames[i].n) == 0) {
  827.                     yylval.fval = FieldNames[i].f;
  828.                     return(FIELD);
  829.                 }
  830.             }
  831.             return(BADWORD);
  832.         }
  833.     } else if (*curpointer == '!' && *(curpointer+1) == '=') {
  834.         curpointer += 2;
  835.         return(NOTEQ);
  836.     } else if (*curpointer == '<' && *(curpointer+1) == '=') {
  837.         curpointer += 2;
  838.         return(LESSEQ);
  839.     } else if (*curpointer == '>' && *(curpointer+1) == '=') {
  840.         curpointer += 2;
  841.         return(GREATEREQ);
  842.     } else return(*curpointer++);
  843. }
  844.  
  845.  
  846.