Skip to content
Snippets Groups Projects
ast_expr2.c 64.9 KiB
Newer Older
  • Learn to ignore specific revisions
  •   YYFPRINTF (yyoutput, ": ");
    
    Tilghman Lesher's avatar
     
    Tilghman Lesher committed
    
    # ifdef YYPRINT
      if (yytype < YYNTOKENS)
        YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
    # endif
    
      switch (yytype)
        {
          default:
            break;
        }
      YYFPRINTF (yyoutput, ")");
    }
    
    #endif /* ! YYDEBUG */
    /*-----------------------------------------------.
    | Release the memory associated to this symbol.  |
    `-----------------------------------------------*/
    
    #if defined (__STDC__) || defined (__cplusplus)
    static void
    
    Tilghman Lesher's avatar
     
    Tilghman Lesher committed
    yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp)
    
    Tilghman Lesher's avatar
     
    Tilghman Lesher committed
    yydestruct (yymsg, yytype, yyvaluep, yylocationp)
        const char *yymsg;
    
        int yytype;
        YYSTYPE *yyvaluep;
        YYLTYPE *yylocationp;
    #endif
    {
      /* Pacify ``unused variable'' warnings.  */
      (void) yyvaluep;
      (void) yylocationp;
    
    
    Tilghman Lesher's avatar
     
    Tilghman Lesher committed
      if (!yymsg)
        yymsg = "Deleting";
      YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
    
    
      switch (yytype)
        {
    
          default:
            break;
        }
    }
    
    
    /* Prevent warnings from -Wmissing-prototypes.  */
    
    #ifdef YYPARSE_PARAM
    # if defined (__STDC__) || defined (__cplusplus)
    int yyparse (void *YYPARSE_PARAM);
    # else
    int yyparse ();
    # endif
    #else /* ! YYPARSE_PARAM */
    #if defined (__STDC__) || defined (__cplusplus)
    int yyparse (void);
    #else
    int yyparse ();
    #endif
    #endif /* ! YYPARSE_PARAM */
    
    
    
    
    
    
    /*----------.
    | yyparse.  |
    `----------*/
    
    #ifdef YYPARSE_PARAM
    # if defined (__STDC__) || defined (__cplusplus)
    int yyparse (void *YYPARSE_PARAM)
    # else
    int yyparse (YYPARSE_PARAM)
      void *YYPARSE_PARAM;
    # endif
    #else /* ! YYPARSE_PARAM */
    #if defined (__STDC__) || defined (__cplusplus)
    int
    yyparse (void)
    #else
    int
    yyparse ()
    
    Tilghman Lesher's avatar
     
    Tilghman Lesher committed
      /* The look-ahead symbol.  */
    
    Tilghman Lesher's avatar
     
    Tilghman Lesher committed
    /* The semantic value of the look-ahead symbol.  */
    
    YYSTYPE yylval;
    
    /* Number of syntax errors so far.  */
    int yynerrs;
    
    Tilghman Lesher's avatar
     
    Tilghman Lesher committed
    /* Location data for the look-ahead symbol.  */
    
      int yystate;
      int yyn;
    
      int yyresult;
      /* Number of tokens to shift before error messages enabled.  */
      int yyerrstatus;
    
    Tilghman Lesher's avatar
     
    Tilghman Lesher committed
      /* Look-ahead token as an internal (translated) token number.  */
    
      int yytoken = 0;
    
      /* Three stacks and their tools:
         `yyss': related to states,
         `yyvs': related to semantic values,
         `yyls': related to locations.
    
         Refer to the stacks thru separate pointers, to allow yyoverflow
         to reallocate them elsewhere.  */
    
      /* The state stack.  */
    
      short int yyssa[YYINITDEPTH];
      short int *yyss = yyssa;
    
      short int *yyssp;
    
    
      /* The semantic value stack.  */
      YYSTYPE yyvsa[YYINITDEPTH];
      YYSTYPE *yyvs = yyvsa;
    
      YYSTYPE *yyvsp;
    
    
      /* The location stack.  */
      YYLTYPE yylsa[YYINITDEPTH];
      YYLTYPE *yyls = yylsa;
      YYLTYPE *yylsp;
    
    Tilghman Lesher's avatar
     
    Tilghman Lesher committed
      /* The locations where the error started and ended. */
      YYLTYPE yyerror_range[2];
    
    
    #define YYPOPSTACK   (yyvsp--, yyssp--, yylsp--)
    
      YYSIZE_T yystacksize = YYINITDEPTH;
    
      /* The variables used to return semantic value and location from the
         action routines.  */
      YYSTYPE yyval;
      YYLTYPE yyloc;
    
      /* When reducing, the number of symbols on the RHS of the reduced
         rule.  */
      int yylen;
    
      YYDPRINTF ((stderr, "Starting parse\n"));
    
      yystate = 0;
      yyerrstatus = 0;
      yynerrs = 0;
      yychar = YYEMPTY;		/* Cause a token to be read.  */
    
      /* Initialize stack pointers.
         Waste one element of value and location stack
         so that they stay on the same level as the state stack.
         The wasted elements are never initialized.  */
    
      yyssp = yyss;
      yyvsp = yyvs;
      yylsp = yyls;
    
    Tilghman Lesher's avatar
     
    Tilghman Lesher committed
    #if YYLTYPE_IS_TRIVIAL
      /* Initialize the default location before parsing starts.  */
      yylloc.first_line   = yylloc.last_line   = 1;
      yylloc.first_column = yylloc.last_column = 0;
    #endif
    
    
      goto yysetstate;
    
    /*------------------------------------------------------------.
    | yynewstate -- Push a new state, which is found in yystate.  |
    `------------------------------------------------------------*/
     yynewstate:
      /* In all cases, when you get here, the value and location stacks
         have just been pushed. so pushing a state here evens the stacks.
         */
      yyssp++;
    
     yysetstate:
      *yyssp = yystate;
    
      if (yyss + yystacksize - 1 <= yyssp)
        {
          /* Get the current used size of the three stacks, in elements.  */
          YYSIZE_T yysize = yyssp - yyss + 1;
    
    #ifdef yyoverflow
          {
    	/* Give user a chance to reallocate the stack. Use copies of
    	   these so that the &'s don't force the real ones into
    	   memory.  */
    	YYSTYPE *yyvs1 = yyvs;
    
    	YYLTYPE *yyls1 = yyls;
    
    	/* Each stack pointer address is followed by the size of the
    	   data in use in that stack, in bytes.  This used to be a
    	   conditional around just the two extra args, but that might
    	   be undefined if yyoverflow is a macro.  */
    
    	yyoverflow (YY_("memory exhausted"),
    
    		    &yyss1, yysize * sizeof (*yyssp),
    		    &yyvs1, yysize * sizeof (*yyvsp),
    		    &yyls1, yysize * sizeof (*yylsp),
    		    &yystacksize);
    	yyls = yyls1;
    	yyss = yyss1;
    	yyvs = yyvs1;
          }
    #else /* no yyoverflow */
    # ifndef YYSTACK_RELOCATE
    
          goto yyexhaustedlab;
    
    # else
          /* Extend the stack our own way.  */
          if (YYMAXDEPTH <= yystacksize)
    
    	goto yyexhaustedlab;
    
          yystacksize *= 2;
          if (YYMAXDEPTH < yystacksize)
    	yystacksize = YYMAXDEPTH;
    
          {
    
    	union yyalloc *yyptr =
    	  (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
    	if (! yyptr)
    
    	  goto yyexhaustedlab;
    
    	YYSTACK_RELOCATE (yyss);
    	YYSTACK_RELOCATE (yyvs);
    	YYSTACK_RELOCATE (yyls);
    #  undef YYSTACK_RELOCATE
    	if (yyss1 != yyssa)
    	  YYSTACK_FREE (yyss1);
          }
    # endif
    #endif /* no yyoverflow */
    
          yyssp = yyss + yysize - 1;
          yyvsp = yyvs + yysize - 1;
          yylsp = yyls + yysize - 1;
    
          YYDPRINTF ((stderr, "Stack size increased to %lu\n",
    		  (unsigned long int) yystacksize));
    
          if (yyss + yystacksize - 1 <= yyssp)
    	YYABORT;
        }
    
      YYDPRINTF ((stderr, "Entering state %d\n", yystate));
    
      goto yybackup;
    
    /*-----------.
    | yybackup.  |
    `-----------*/
    yybackup:
    
    /* Do appropriate processing given the current state.  */
    
    Tilghman Lesher's avatar
     
    Tilghman Lesher committed
    /* Read a look-ahead token if we need one and don't already have one.  */
    
    Tilghman Lesher's avatar
     
    Tilghman Lesher committed
      /* First try to decide what to do without reference to look-ahead token.  */
    
    
      yyn = yypact[yystate];
      if (yyn == YYPACT_NINF)
        goto yydefault;
    
    
    Tilghman Lesher's avatar
     
    Tilghman Lesher committed
      /* Not known => get a look-ahead token if don't already have one.  */
    
    Tilghman Lesher's avatar
     
    Tilghman Lesher committed
      /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol.  */
    
      if (yychar == YYEMPTY)
        {
          YYDPRINTF ((stderr, "Reading a token: "));
          yychar = YYLEX;
        }
    
      if (yychar <= YYEOF)
        {
          yychar = yytoken = YYEOF;
          YYDPRINTF ((stderr, "Now at end of input.\n"));
        }
      else
        {
          yytoken = YYTRANSLATE (yychar);
    
    Tilghman Lesher's avatar
     
    Tilghman Lesher committed
          YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
    
        }
    
      /* If the proper action on seeing token YYTOKEN is to reduce or to
         detect an error, take that action.  */
      yyn += yytoken;
      if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
        goto yydefault;
      yyn = yytable[yyn];
      if (yyn <= 0)
        {
          if (yyn == 0 || yyn == YYTABLE_NINF)
    	goto yyerrlab;
          yyn = -yyn;
          goto yyreduce;
        }
    
      if (yyn == YYFINAL)
        YYACCEPT;
    
    
    Tilghman Lesher's avatar
     
    Tilghman Lesher committed
      /* Shift the look-ahead token.  */
      YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
    
    
      /* Discard the token being shifted unless it is eof.  */
      if (yychar != YYEOF)
        yychar = YYEMPTY;
    
      *++yyvsp = yylval;
      *++yylsp = yylloc;
    
      /* Count tokens shifted since error; after three, turn off error
         status.  */
      if (yyerrstatus)
        yyerrstatus--;
    
      yystate = yyn;
      goto yynewstate;
    
    
    /*-----------------------------------------------------------.
    | yydefault -- do the default action for the current state.  |
    `-----------------------------------------------------------*/
    yydefault:
      yyn = yydefact[yystate];
      if (yyn == 0)
        goto yyerrlab;
      goto yyreduce;
    
    
    /*-----------------------------.
    | yyreduce -- Do a reduction.  |
    `-----------------------------*/
    yyreduce:
      /* yyn is the number of a rule to reduce with.  */
      yylen = yyr2[yyn];
    
      /* If YYLEN is nonzero, implement the default value of the action:
         `$$ = $1'.
    
         Otherwise, the following line sets YYVAL to garbage.
         This behavior is undocumented and Bison
         users should not rely upon it.  Assigning to YYVAL
         unconditionally makes the parser a bit smaller, and it avoids a
         GCC warning that YYVAL may be used uninitialized.  */
      yyval = yyvsp[1-yylen];
    
      /* Default location. */
    
      YYLLOC_DEFAULT (yyloc, yylsp - yylen, yylen);
    
    Tilghman Lesher's avatar
     
    Tilghman Lesher committed
    #line 165 "ast_expr2.y"
    
        { ((struct parse_io *)parseio)->val = (struct val *)calloc(sizeof(struct val),1);
    
    Tilghman Lesher's avatar
     
    Tilghman Lesher committed
                  ((struct parse_io *)parseio)->val->type = (yyvsp[0].val)->type;
                  if( (yyvsp[0].val)->type == AST_EXPR_integer )
    				  ((struct parse_io *)parseio)->val->u.i = (yyvsp[0].val)->u.i;
    
    Tilghman Lesher's avatar
     
    Tilghman Lesher committed
    				  ((struct parse_io *)parseio)->val->u.s = (yyvsp[0].val)->u.s; 
    			  free((yyvsp[0].val));
    			;}
    
    Tilghman Lesher's avatar
     
    Tilghman Lesher committed
    #line 175 "ast_expr2.y"
        { (yyval.val)= (yyvsp[0].val);;}
    
    Tilghman Lesher's avatar
     
    Tilghman Lesher committed
    #line 176 "ast_expr2.y"
        { (yyval.val) = (yyvsp[-1].val); 
    	                       (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column; 
    						   (yyloc).first_line=0; (yyloc).last_line=0;
    							DESTROY((yyvsp[-2].val)); DESTROY((yyvsp[0].val)); ;}
    
    Tilghman Lesher's avatar
     
    Tilghman Lesher committed
    #line 180 "ast_expr2.y"
        { (yyval.val) = op_or ((yyvsp[-2].val), (yyvsp[0].val));
    						DESTROY((yyvsp[-1].val));	
                             (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column; 
    						 (yyloc).first_line=0; (yyloc).last_line=0;;}
    
    Tilghman Lesher's avatar
     
    Tilghman Lesher committed
    #line 184 "ast_expr2.y"
        { (yyval.val) = op_and ((yyvsp[-2].val), (yyvsp[0].val)); 
    						DESTROY((yyvsp[-1].val));	
    	                      (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column; 
                              (yyloc).first_line=0; (yyloc).last_line=0;;}
    
    Tilghman Lesher's avatar
     
    Tilghman Lesher committed
    #line 188 "ast_expr2.y"
        { (yyval.val) = op_eq ((yyvsp[-2].val), (yyvsp[0].val));
    						DESTROY((yyvsp[-1].val));	
    	                     (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column;
    						 (yyloc).first_line=0; (yyloc).last_line=0;;}
    
    Tilghman Lesher's avatar
     
    Tilghman Lesher committed
    #line 192 "ast_expr2.y"
        { (yyval.val) = op_gt ((yyvsp[-2].val), (yyvsp[0].val));
    						DESTROY((yyvsp[-1].val));	
                             (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column;
    						 (yyloc).first_line=0; (yyloc).last_line=0;;}
    
    Tilghman Lesher's avatar
     
    Tilghman Lesher committed
    #line 196 "ast_expr2.y"
        { (yyval.val) = op_lt ((yyvsp[-2].val), (yyvsp[0].val)); 
    						DESTROY((yyvsp[-1].val));	
    	                     (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column; 
    						 (yyloc).first_line=0; (yyloc).last_line=0;;}
    
    Tilghman Lesher's avatar
     
    Tilghman Lesher committed
    #line 200 "ast_expr2.y"
        { (yyval.val) = op_ge ((yyvsp[-2].val), (yyvsp[0].val)); 
    						DESTROY((yyvsp[-1].val));	
    	                      (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column; 
    						  (yyloc).first_line=0; (yyloc).last_line=0;;}
    
    Tilghman Lesher's avatar
     
    Tilghman Lesher committed
    #line 204 "ast_expr2.y"
        { (yyval.val) = op_le ((yyvsp[-2].val), (yyvsp[0].val)); 
    						DESTROY((yyvsp[-1].val));	
    	                      (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column; 
    						  (yyloc).first_line=0; (yyloc).last_line=0;;}
    
    Tilghman Lesher's avatar
     
    Tilghman Lesher committed
    #line 208 "ast_expr2.y"
        { (yyval.val) = op_ne ((yyvsp[-2].val), (yyvsp[0].val)); 
    						DESTROY((yyvsp[-1].val));	
    	                      (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column; 
    						  (yyloc).first_line=0; (yyloc).last_line=0;;}
    
    Tilghman Lesher's avatar
     
    Tilghman Lesher committed
    #line 212 "ast_expr2.y"
        { (yyval.val) = op_plus ((yyvsp[-2].val), (yyvsp[0].val)); 
    						DESTROY((yyvsp[-1].val));	
    	                       (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column; 
    						   (yyloc).first_line=0; (yyloc).last_line=0;;}
    
    Tilghman Lesher's avatar
     
    Tilghman Lesher committed
    #line 216 "ast_expr2.y"
        { (yyval.val) = op_minus ((yyvsp[-2].val), (yyvsp[0].val)); 
    						DESTROY((yyvsp[-1].val));	
    	                        (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column; 
    							(yyloc).first_line=0; (yyloc).last_line=0;;}
    
    Tilghman Lesher's avatar
     
    Tilghman Lesher committed
    #line 220 "ast_expr2.y"
        { (yyval.val) = op_negate ((yyvsp[0].val)); 
    						DESTROY((yyvsp[-1].val));	
    	                        (yyloc).first_column = (yylsp[-1]).first_column; (yyloc).last_column = (yylsp[0]).last_column; 
    							(yyloc).first_line=0; (yyloc).last_line=0;;}
    
    Tilghman Lesher's avatar
     
    Tilghman Lesher committed
    #line 224 "ast_expr2.y"
        { (yyval.val) = op_compl ((yyvsp[0].val)); 
    						DESTROY((yyvsp[-1].val));	
    	                        (yyloc).first_column = (yylsp[-1]).first_column; (yyloc).last_column = (yylsp[0]).last_column; 
    							(yyloc).first_line=0; (yyloc).last_line=0;;}
    
    Tilghman Lesher's avatar
     
    Tilghman Lesher committed
    #line 228 "ast_expr2.y"
        { (yyval.val) = op_times ((yyvsp[-2].val), (yyvsp[0].val)); 
    						DESTROY((yyvsp[-1].val));	
    	                       (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column; 
    						   (yyloc).first_line=0; (yyloc).last_line=0;;}
    
    Tilghman Lesher's avatar
     
    Tilghman Lesher committed
    #line 232 "ast_expr2.y"
        { (yyval.val) = op_div ((yyvsp[-2].val), (yyvsp[0].val)); 
    						DESTROY((yyvsp[-1].val));	
    	                      (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column; 
    						  (yyloc).first_line=0; (yyloc).last_line=0;;}
    
    Tilghman Lesher's avatar
     
    Tilghman Lesher committed
    #line 236 "ast_expr2.y"
        { (yyval.val) = op_rem ((yyvsp[-2].val), (yyvsp[0].val)); 
    						DESTROY((yyvsp[-1].val));	
    	                      (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column; 
    						  (yyloc).first_line=0; (yyloc).last_line=0;;}
    
    Tilghman Lesher's avatar
     
    Tilghman Lesher committed
    #line 240 "ast_expr2.y"
        { (yyval.val) = op_colon ((yyvsp[-2].val), (yyvsp[0].val)); 
    						DESTROY((yyvsp[-1].val));	
    	                        (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column; 
    							(yyloc).first_line=0; (yyloc).last_line=0;;}
    
    Tilghman Lesher's avatar
     
    Tilghman Lesher committed
    #line 244 "ast_expr2.y"
        { (yyval.val) = op_eqtilde ((yyvsp[-2].val), (yyvsp[0].val)); 
    						DESTROY((yyvsp[-1].val));	
    	                        (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column; 
    							(yyloc).first_line=0; (yyloc).last_line=0;;}
    
    Tilghman Lesher's avatar
     
    Tilghman Lesher committed
    #line 248 "ast_expr2.y"
        { (yyval.val) = op_cond ((yyvsp[-4].val), (yyvsp[-2].val), (yyvsp[0].val)); 
    						DESTROY((yyvsp[-3].val));	
    						DESTROY((yyvsp[-1].val));	
    	                        (yyloc).first_column = (yylsp[-4]).first_column; (yyloc).last_column = (yylsp[-2]).last_column; 
    							(yyloc).first_line=0; (yyloc).last_line=0;;}
    
          default: break;
    
    /* Line 1126 of yacc.c.  */
    #line 1532 "ast_expr2.c"
    
    
      yyvsp -= yylen;
      yyssp -= yylen;
      yylsp -= yylen;
    
      YY_STACK_PRINT (yyss, yyssp);
    
      *++yyvsp = yyval;
      *++yylsp = yyloc;
    
      /* Now `shift' the result of the reduction.  Determine what state
         that goes to, based on the state we popped back to and the rule
         number reduced by.  */
    
      yyn = yyr1[yyn];
    
      yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
      if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
        yystate = yytable[yystate];
      else
        yystate = yydefgoto[yyn - YYNTOKENS];
    
      goto yynewstate;
    
    
    /*------------------------------------.
    | yyerrlab -- here on detecting error |
    `------------------------------------*/
    yyerrlab:
      /* If not already recovering from an error, report this error.  */
      if (!yyerrstatus)
        {
          ++yynerrs;
    #if YYERROR_VERBOSE
          yyn = yypact[yystate];
    
          if (YYPACT_NINF < yyn && yyn < YYLAST)
    	{
    	  int yytype = YYTRANSLATE (yychar);
    
    	  YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
    	  YYSIZE_T yysize = yysize0;
    	  YYSIZE_T yysize1;
    	  int yysize_overflow = 0;
    	  char *yymsg = 0;
    #	  define YYERROR_VERBOSE_ARGS_MAXIMUM 5
    	  char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
    
    #if 0
    	  /* This is so xgettext sees the translatable formats that are
    	     constructed on the fly.  */
    	  YY_("syntax error, unexpected %s");
    	  YY_("syntax error, unexpected %s, expecting %s");
    	  YY_("syntax error, unexpected %s, expecting %s or %s");
    	  YY_("syntax error, unexpected %s, expecting %s or %s or %s");
    	  YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
    #endif
    	  char *yyfmt;
    	  char const *yyf;
    	  static char const yyunexpected[] = "syntax error, unexpected %s";
    	  static char const yyexpecting[] = ", expecting %s";
    	  static char const yyor[] = " or %s";
    	  char yyformat[sizeof yyunexpected
    			+ sizeof yyexpecting - 1
    			+ ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
    			   * (sizeof yyor - 1))];
    	  char const *yyprefix = yyexpecting;
    
    
    	  /* Start YYX at -YYN if negative to avoid negative indexes in
    	     YYCHECK.  */
    
    	  int yyxbegin = yyn < 0 ? -yyn : 0;
    
    	  /* Stay within bounds of both yycheck and yytname.  */
    	  int yychecklim = YYLAST - yyn;
    	  int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
    
    	  int yycount = 1;
    
    	  yyarg[0] = yytname[yytype];
    	  yyfmt = yystpcpy (yyformat, yyunexpected);
    
    
    	  for (yyx = yyxbegin; yyx < yyxend; ++yyx)
    
    	    if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
    
    		if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
    
    		    yycount = 1;
    		    yysize = yysize0;
    		    yyformat[sizeof yyunexpected - 1] = '\0';
    
    		yyarg[yycount++] = yytname[yyx];
    		yysize1 = yysize + yytnamerr (0, yytname[yyx]);
    		yysize_overflow |= yysize1 < yysize;
    		yysize = yysize1;
    		yyfmt = yystpcpy (yyfmt, yyprefix);
    		yyprefix = yyor;
    
    	  yyf = YY_(yyformat);
    	  yysize1 = yysize + yystrlen (yyf);
    	  yysize_overflow |= yysize1 < yysize;
    	  yysize = yysize1;
    
    	  if (!yysize_overflow && yysize <= YYSTACK_ALLOC_MAXIMUM)
    	    yymsg = (char *) YYSTACK_ALLOC (yysize);
    	  if (yymsg)
    	    {
    	      /* Avoid sprintf, as that infringes on the user's name space.
    		 Don't have undefined behavior even if the translation
    		 produced a string with the wrong number of "%s"s.  */
    	      char *yyp = yymsg;
    	      int yyi = 0;
    	      while ((*yyp = *yyf))
    
    		  if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
    		    {
    		      yyp += yytnamerr (yyp, yyarg[yyi++]);
    		      yyf += 2;
    		    }
    		  else
    		    {
    		      yyp++;
    		      yyf++;
    		    }
    
    	    {
    	      yyerror (YY_("syntax error"));
    	      goto yyexhaustedlab;
    	    }
    
    	yyerror (YY_("syntax error"));
    
    Tilghman Lesher's avatar
     
    Tilghman Lesher committed
      yyerror_range[0] = yylloc;
    
    Tilghman Lesher's avatar
     
    Tilghman Lesher committed
          /* If just tried and failed to reuse look-ahead token after an
    
    	  /* Return failure if at end of input.  */
    
    Tilghman Lesher's avatar
     
    Tilghman Lesher committed
    	  yydestruct ("Error: discarding", yytoken, &yylval, &yylloc);
    
    Tilghman Lesher's avatar
     
    Tilghman Lesher committed
      /* Else will try to reuse look-ahead token after shifting the error
    
    /*---------------------------------------------------.
    | yyerrorlab -- error raised explicitly by YYERROR.  |
    `---------------------------------------------------*/
    yyerrorlab:
    
      /* Pacify compilers like GCC when the user code never invokes
         YYERROR and the label yyerrorlab therefore never appears in user
         code.  */
    
    Tilghman Lesher's avatar
     
    Tilghman Lesher committed
      yyerror_range[0] = yylsp[1-yylen];
      yylsp -= yylen;
    
      yyvsp -= yylen;
      yyssp -= yylen;
      yystate = *yyssp;
      goto yyerrlab1;
    
    /*-------------------------------------------------------------.
    | yyerrlab1 -- common code for both syntax error and YYERROR.  |
    `-------------------------------------------------------------*/
    yyerrlab1:
    
      yyerrstatus = 3;	/* Each real token shifted decrements this.  */
    
      for (;;)
        {
          yyn = yypact[yystate];
          if (yyn != YYPACT_NINF)
    	{
    	  yyn += YYTERROR;
    	  if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
    	    {
    	      yyn = yytable[yyn];
    	      if (0 < yyn)
    		break;
    	    }
    	}
    
          /* Pop the current state because it cannot handle the error token.  */
          if (yyssp == yyss)
    	YYABORT;
    
    
    Tilghman Lesher's avatar
     
    Tilghman Lesher committed
          yyerror_range[0] = *yylsp;
          yydestruct ("Error: popping", yystos[yystate], yyvsp, yylsp);
    
          YY_STACK_PRINT (yyss, yyssp);
        }
    
      if (yyn == YYFINAL)
        YYACCEPT;
    
      *++yyvsp = yylval;
    
    Tilghman Lesher's avatar
     
    Tilghman Lesher committed
    
      yyerror_range[1] = yylloc;
      /* Using YYLLOC is tempting, but would change the location of
         the look-ahead.  YYLOC is available though. */
      YYLLOC_DEFAULT (yyloc, yyerror_range - 1, 2);
    
    Tilghman Lesher's avatar
     
    Tilghman Lesher committed
      /* Shift the error token. */
      YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
    
    
      yystate = yyn;
      goto yynewstate;
    
    
    /*-------------------------------------.
    | yyacceptlab -- YYACCEPT comes here.  |
    `-------------------------------------*/
    yyacceptlab:
      yyresult = 0;
      goto yyreturn;
    
    /*-----------------------------------.
    | yyabortlab -- YYABORT comes here.  |
    `-----------------------------------*/
    yyabortlab:
      yyresult = 1;
      goto yyreturn;
    
    #ifndef yyoverflow
    
    /*-------------------------------------------------.
    | yyexhaustedlab -- memory exhaustion comes here.  |
    `-------------------------------------------------*/
    yyexhaustedlab:
      yyerror (YY_("memory exhausted"));
    
      if (yychar != YYEOF && yychar != YYEMPTY)
         yydestruct ("Cleanup: discarding lookahead",
    		 yytoken, &yylval, &yylloc);
      while (yyssp != yyss)
        {
          yydestruct ("Cleanup: popping",
    		  yystos[*yyssp], yyvsp, yylsp);
          YYPOPSTACK;
        }
    
    #ifndef yyoverflow
      if (yyss != yyssa)
        YYSTACK_FREE (yyss);
    #endif
      return yyresult;
    }
    
    
    
    Tilghman Lesher's avatar
     
    Tilghman Lesher committed
    #line 255 "ast_expr2.y"
    
    
    
    static struct val *
    make_integer (quad_t i)
    {
    	struct val *vp;
    
    	vp = (struct val *) malloc (sizeof (*vp));
    	if (vp == NULL) {
    		ast_log(LOG_WARNING, "malloc() failed\n");
    		return(NULL);
    	}
    
    	vp->type = AST_EXPR_integer;
    	vp->u.i  = i;
    	return vp; 
    }
    
    static struct val *
    make_str (const char *s)
    {
    	struct val *vp;
    	size_t i;
    	int isint;
    
    	vp = (struct val *) malloc (sizeof (*vp));
    	if (vp == NULL || ((vp->u.s = strdup (s)) == NULL)) {
    		ast_log(LOG_WARNING,"malloc() failed\n");
    		return(NULL);
    	}
    
    	for(i = 1, isint = isdigit(s[0]) || s[0] == '-';
    	    isint && i < strlen(s);
    	    i++)
    	{
    		if(!isdigit(s[i]))
    			 isint = 0;
    	}
    
    	if (isint)
    		vp->type = AST_EXPR_numeric_string;
    	else	
    		vp->type = AST_EXPR_string;
    
    	return vp;
    }
    
    
    static void
    free_value (struct val *vp)
    {	
    	if (vp==NULL) {
    		return;
    	}
    	if (vp->type == AST_EXPR_string || vp->type == AST_EXPR_numeric_string)
    		free (vp->u.s);	
    
    Tilghman Lesher's avatar
     
    Tilghman Lesher committed
    	free(vp);
    
    }
    
    
    static quad_t
    to_integer (struct val *vp)
    {
    	quad_t i;
    	
    	if (vp == NULL) {
    		ast_log(LOG_WARNING,"vp==NULL in to_integer()\n");
    		return(0);
    	}
    
    	if (vp->type == AST_EXPR_integer)
    		return 1;
    
    	if (vp->type == AST_EXPR_string)
    		return 0;
    
    	/* vp->type == AST_EXPR_numeric_string, make it numeric */
    	errno = 0;
    	i  = strtoll(vp->u.s, (char**)NULL, 10);
    	if (errno != 0) {
    		ast_log(LOG_WARNING,"Conversion of %s to integer under/overflowed!\n", vp->u.s);
    		free(vp->u.s);
    		vp->u.s = 0;
    		return(0);
    	}
    	free (vp->u.s);
    	vp->u.i = i;
    	vp->type = AST_EXPR_integer;
    	return 1;
    }
    
    static void
    strip_quotes(struct val *vp)
    {
    	if (vp->type != AST_EXPR_string && vp->type != AST_EXPR_numeric_string)
    		return;
    	
    	if( vp->u.s[0] == '"' && vp->u.s[strlen(vp->u.s)-1] == '"' )
    	{
    		char *f, *t;
    		f = vp->u.s;
    		t = vp->u.s;
    		
    		while( *f )
    		{
    			if( *f  && *f != '"' )
    				*t++ = *f++;
    			else
    				f++;
    		}
    		*t = *f;
    	}
    }
    
    static void
    to_string (struct val *vp)
    {
    	char *tmp;
    
    	if (vp->type == AST_EXPR_string || vp->type == AST_EXPR_numeric_string)
    		return;
    
    	tmp = malloc ((size_t)25);
    	if (tmp == NULL) {
    		ast_log(LOG_WARNING,"malloc() failed\n");
    		return;
    	}
    
    
    	sprintf(tmp, "%ld", (long int) vp->u.i);
    
    	vp->type = AST_EXPR_string;
    	vp->u.s  = tmp;
    }
    
    
    static int
    isstring (struct val *vp)
    {
    	/* only TRUE if this string is not a valid integer */
    	return (vp->type == AST_EXPR_string);
    }
    
    
    static int
    is_zero_or_null (struct val *vp)
    {
    	if (vp->type == AST_EXPR_integer) {
    		return (vp->u.i == 0);
    	} else {
    		return (*vp->u.s == 0 || (to_integer (vp) && vp->u.i == 0));
    	}
    	/* NOTREACHED */
    }
    
    #ifdef STANDALONE
    
    void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...)
    {
    	va_list vars;
    	va_start(vars,fmt);
    	
            printf("LOG: lev:%d file:%s  line:%d func: %s  ",
                       level, file, line, function);
    	vprintf(fmt, vars);
    	fflush(stdout);
    	va_end(vars);
    }
    
    
    int main(int argc,char **argv) {
    
    	char s[4096];
    	
    	if (ast_expr(argv[1], s, sizeof(s)))
    		printf("=====%s======\n",s);
    	else
    		printf("No result\n");
    
    }
    
    #endif
    
    #undef ast_yyerror
    #define ast_yyerror(x) ast_yyerror(x, YYLTYPE *yylloc, struct parse_io *parseio)
    
    /* I put the ast_yyerror func in the flex input file,
       because it refers to the buffer state. Best to
       let it access the BUFFER stuff there and not trying
       define all the structs, macros etc. in this file! */
    
    
    static struct val *
    op_or (struct val *a, struct val *b)
    {
    	if (is_zero_or_null (a)) {
    		free_value (a);
    		return (b);