Ejemplo n.º 1
0
  int
  Parser::parse ()
  {
    // State.
    int yyn;
    /// Length of the RHS of the rule being reduced.
    int yylen = 0;

    // Error handling.
    int yynerrs_ = 0;
    int yyerrstatus_ = 0;

    /// The lookahead symbol.
    symbol_type yyla;

    /// The return value of parse ().
    int yyresult;

    // FIXME: This shoud be completely indented.  It is not yet to
    // avoid gratuitous conflicts when merging into the master branch.
    try
      {
    YYCDEBUG << "Starting parse" << std::endl;


    /* Initialize the stack.  The initial state will be set in
       yynewstate, since the latter expects the semantical and the
       location values to have been already stored, initialize these
       stacks with a primary value.  */
    yystack_.clear ();
    yypush_ (YY_NULLPTR, 0, yyla);

    // A new symbol was pushed on the stack.
  yynewstate:
    YYCDEBUG << "Entering state " << yystack_[0].state << std::endl;

    // Accept?
    if (yystack_[0].state == yyfinal_)
      goto yyacceptlab;

    goto yybackup;

    // Backup.
  yybackup:

    // Try to take a decision without lookahead.
    yyn = yypact_[yystack_[0].state];
    if (yy_pact_value_is_default_ (yyn))
      goto yydefault;

    // Read a lookahead token.
    if (yyla.empty ())
      {
        YYCDEBUG << "Reading a token: ";
        try
          {
            yyla.type = yytranslate_ (yylex (&yyla.value));
          }
        catch (const syntax_error& yyexc)
          {
            error (yyexc);
            goto yyerrlab1;
          }
      }
    YY_SYMBOL_PRINT ("Next token is", yyla);

    /* If the proper action on seeing token YYLA.TYPE is to reduce or
       to detect an error, take that action.  */
    yyn += yyla.type_get ();
    if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yyla.type_get ())
      goto yydefault;

    // Reduce or error.
    yyn = yytable_[yyn];
    if (yyn <= 0)
      {
        if (yy_table_value_is_error_ (yyn))
          goto yyerrlab;
        yyn = -yyn;
        goto yyreduce;
      }

    // Count tokens shifted since error; after three, turn off error status.
    if (yyerrstatus_)
      --yyerrstatus_;

    // Shift the lookahead token.
    yypush_ ("Shifting", yyn, yyla);
    goto yynewstate;

  /*-----------------------------------------------------------.
  | yydefault -- do the default action for the current state.  |
  `-----------------------------------------------------------*/
  yydefault:
    yyn = yydefact_[yystack_[0].state];
    if (yyn == 0)
      goto yyerrlab;
    goto yyreduce;

  /*-----------------------------.
  | yyreduce -- Do a reduction.  |
  `-----------------------------*/
  yyreduce:
    yylen = yyr2_[yyn];
    {
      stack_symbol_type yylhs;
      yylhs.state = yy_lr_goto_state_(yystack_[yylen].state, yyr1_[yyn]);
      /* If YYLEN is nonzero, implement the default value of the
         action: '$$ = $1'.  Otherwise, use the top of the stack.

         Otherwise, the following line sets YYLHS.VALUE to garbage.
         This behavior is undocumented and Bison users should not rely
         upon it.  */
      if (yylen)
        yylhs.value = yystack_[yylen - 1].value;
      else
        yylhs.value = yystack_[0].value;


      // Perform the reduction.
      YY_REDUCE_PRINT (yyn);
      try
        {
          switch (yyn)
            {
  case 2:
#line 147 "src/grammar/parser.yy" // lalr1.cc:859
    {
                                              std::vector<Nodes::AbstractNode *> nodes;
                                              nodes.push_back((yystack_[0].value.abs_node));
                                              driver.push_stack(nodes);
                                              (yylhs.value.driver) = &driver;
                                            }
#line 692 "src/frontend/parser.tab.cpp" // lalr1.cc:859
    break;

  case 3:
#line 153 "src/grammar/parser.yy" // lalr1.cc:859
    {
                                              (yystack_[2].value.driver)->push_node((yystack_[0].value.abs_node));
                                              (yylhs.value.driver) = (yystack_[2].value.driver);
                                            }
#line 701 "src/frontend/parser.tab.cpp" // lalr1.cc:859
    break;

  case 4:
#line 157 "src/grammar/parser.yy" // lalr1.cc:859
    {
    
                                            }
#line 709 "src/frontend/parser.tab.cpp" // lalr1.cc:859
    break;

  case 5:
#line 160 "src/grammar/parser.yy" // lalr1.cc:859
    {
                                              (yylhs.value.driver) = (yystack_[1].value.driver);
                                            }
#line 717 "src/frontend/parser.tab.cpp" // lalr1.cc:859
    break;

  case 6:
#line 167 "src/grammar/parser.yy" // lalr1.cc:859
    {
                                            std::vector<Nodes::AbstractNode *> nodes;
                                            nodes.push_back((yystack_[0].value.abs_node));
                                            Nodes::Nodes *nodelist = new Nodes::Nodes(nodes);
                                            (yylhs.value.nodes) = nodelist;
                                          }
#line 728 "src/frontend/parser.tab.cpp" // lalr1.cc:859
    break;

  case 7:
#line 173 "src/grammar/parser.yy" // lalr1.cc:859
    {
                                            (yystack_[2].value.nodes)->add((yystack_[0].value.abs_node));
                                            (yylhs.value.nodes) = (yystack_[2].value.nodes);
                                          }
#line 737 "src/frontend/parser.tab.cpp" // lalr1.cc:859
    break;

  case 8:
#line 177 "src/grammar/parser.yy" // lalr1.cc:859
    { /* do nothing */ }
#line 743 "src/frontend/parser.tab.cpp" // lalr1.cc:859
    break;

  case 9:
#line 178 "src/grammar/parser.yy" // lalr1.cc:859
    {
                                            (yylhs.value.nodes) = (yystack_[1].value.nodes);
                                          }
#line 751 "src/frontend/parser.tab.cpp" // lalr1.cc:859
    break;

  case 20:
#line 194 "src/grammar/parser.yy" // lalr1.cc:859
    { (yylhs.value.abs_node) = (yystack_[1].value.abs_node); }
#line 757 "src/frontend/parser.tab.cpp" // lalr1.cc:859
    break;

  case 21:
#line 198 "src/grammar/parser.yy" // lalr1.cc:859
    {
                              (yylhs.value.abs_node) = new Nodes::LiteralNode((yystack_[0].value.ival));
                            }
#line 765 "src/frontend/parser.tab.cpp" // lalr1.cc:859
    break;

  case 22:
#line 201 "src/grammar/parser.yy" // lalr1.cc:859
    {
                              (yylhs.value.abs_node) = new Nodes::LiteralNode((yystack_[0].value.fval));
                            }
#line 773 "src/frontend/parser.tab.cpp" // lalr1.cc:859
    break;

  case 23:
#line 204 "src/grammar/parser.yy" // lalr1.cc:859
    {
                              (yylhs.value.abs_node) = new Nodes::LiteralNode(*(yystack_[0].value.sval));
                            }
#line 781 "src/frontend/parser.tab.cpp" // lalr1.cc:859
    break;

  case 24:
#line 207 "src/grammar/parser.yy" // lalr1.cc:859
    {
                              (yylhs.value.abs_node) = new Nodes::SelfNode();
                            }
#line 789 "src/frontend/parser.tab.cpp" // lalr1.cc:859
    break;

  case 33:
#line 212 "src/grammar/parser.yy" // lalr1.cc:859
    { (yylhs.value.sval) = (yystack_[0].value.sval); }
#line 795 "src/frontend/parser.tab.cpp" // lalr1.cc:859
    break;

  case 34:
#line 215 "src/grammar/parser.yy" // lalr1.cc:859
    {
                                                                    std::vector<Nodes::AbstractNode*> arguments;
                                                                    arguments.push_back((yystack_[0].value.abs_node));
                                                                    (yylhs.value.abs_node) = new Nodes::CallNode(*(yystack_[1].value.sval), (yystack_[2].value.abs_node), arguments);
                                                                  }
#line 805 "src/frontend/parser.tab.cpp" // lalr1.cc:859
    break;

  case 35:
#line 220 "src/grammar/parser.yy" // lalr1.cc:859
    { (yylhs.value.abs_node) = new Nodes::CallNode(*(yystack_[3].value.sval), NULL, *(yystack_[1].value.arguments)); }
#line 811 "src/frontend/parser.tab.cpp" // lalr1.cc:859
    break;

  case 36:
#line 221 "src/grammar/parser.yy" // lalr1.cc:859
    { (yylhs.value.abs_node) = new Nodes::CallNode(*(yystack_[3].value.sval), (yystack_[5].value.abs_node), *(yystack_[1].value.arguments));   }
#line 817 "src/frontend/parser.tab.cpp" // lalr1.cc:859
    break;

  case 37:
#line 227 "src/grammar/parser.yy" // lalr1.cc:859
    {
                                    (yylhs.value.abs_node) = new Nodes::MethodDefinitionNode(*(yystack_[6].value.sval), *(yystack_[4].value.parameters), (yystack_[1].value.nodes));
                                  }
#line 825 "src/frontend/parser.tab.cpp" // lalr1.cc:859
    break;

  case 38:
#line 233 "src/grammar/parser.yy" // lalr1.cc:859
    {
                                    (yylhs.value.abs_node) = new Nodes::MethodDefinitionNode(*(yystack_[6].value.sval), *(yystack_[4].value.parameters), (yystack_[1].value.nodes));
                                  }
#line 833 "src/frontend/parser.tab.cpp" // lalr1.cc:859
    break;

  case 39:
#line 242 "src/grammar/parser.yy" // lalr1.cc:859
    {
                                    (yylhs.value.abs_node) = new Nodes::LambdaNode(*(yystack_[4].value.parameters),(yystack_[1].value.nodes));
                                  }
#line 841 "src/frontend/parser.tab.cpp" // lalr1.cc:859
    break;

  case 40:
#line 248 "src/grammar/parser.yy" // lalr1.cc:859
    {
                                  std::vector<Nodes::AbstractNode*> *arguments = new std::vector<Nodes::AbstractNode*>();
                                  arguments->push_back((yystack_[0].value.abs_node));
                                  (yylhs.value.arguments) = arguments;
                                }
#line 851 "src/frontend/parser.tab.cpp" // lalr1.cc:859
    break;

  case 41:
#line 253 "src/grammar/parser.yy" // lalr1.cc:859
    {
                                  (yystack_[2].value.arguments)->push_back((yystack_[0].value.abs_node));
                                  (yylhs.value.arguments) = (yystack_[2].value.arguments);
                                }
#line 860 "src/frontend/parser.tab.cpp" // lalr1.cc:859
    break;

  case 42:
#line 257 "src/grammar/parser.yy" // lalr1.cc:859
    {
                                  std::vector<Nodes::AbstractNode*> *arguments = new std::vector<Nodes::AbstractNode*>();
                                  (yylhs.value.arguments) = arguments;
                                }
#line 869 "src/frontend/parser.tab.cpp" // lalr1.cc:859
    break;

  case 43:
#line 264 "src/grammar/parser.yy" // lalr1.cc:859
    {
                                    std::vector<std::string> *parameters = new std::vector<std::string>();
                                    parameters->push_back(*(yystack_[0].value.sval));
                                    (yylhs.value.parameters) = parameters;
                                  }
#line 879 "src/frontend/parser.tab.cpp" // lalr1.cc:859
    break;

  case 44:
#line 269 "src/grammar/parser.yy" // lalr1.cc:859
    { (yystack_[2].value.parameters)->push_back(*(yystack_[0].value.sval)); (yylhs.value.parameters) = (yystack_[2].value.parameters); }
#line 885 "src/frontend/parser.tab.cpp" // lalr1.cc:859
    break;

  case 45:
#line 270 "src/grammar/parser.yy" // lalr1.cc:859
    { 
                                    std::vector<std::string> *parameters = new std::vector<std::string>();
                                    (yylhs.value.parameters) = parameters;
                                  }
#line 894 "src/frontend/parser.tab.cpp" // lalr1.cc:859
    break;

  case 46:
#line 279 "src/grammar/parser.yy" // lalr1.cc:859
    {
                                    (yylhs.value.abs_node) = new Nodes::ClassDefinitionNode(*(yystack_[5].value.sval), *(yystack_[3].value.sval), (yystack_[1].value.nodes));
                                  }
#line 902 "src/frontend/parser.tab.cpp" // lalr1.cc:859
    break;

  case 47:
#line 284 "src/grammar/parser.yy" // lalr1.cc:859
    {
                                    (yylhs.value.abs_node) = new Nodes::ClassDefinitionNode(*(yystack_[3].value.sval), std::string(""), (yystack_[1].value.nodes));
                                  }
#line 910 "src/frontend/parser.tab.cpp" // lalr1.cc:859
    break;

  case 48:
#line 292 "src/grammar/parser.yy" // lalr1.cc:859
    { (yylhs.value.abs_node) = new Nodes::IfNode((yystack_[3].value.nodes), (yystack_[1].value.nodes)); }
#line 916 "src/frontend/parser.tab.cpp" // lalr1.cc:859
    break;

  case 49:
#line 296 "src/grammar/parser.yy" // lalr1.cc:859
    { (yylhs.value.abs_node) = new Nodes::ReturnNode((yystack_[0].value.nodes)); }
#line 922 "src/frontend/parser.tab.cpp" // lalr1.cc:859
    break;

  case 50:
#line 300 "src/grammar/parser.yy" // lalr1.cc:859
    { (yylhs.value.abs_node) = new Nodes::LocalAssignNode(*(yystack_[2].value.sval), (yystack_[0].value.abs_node)); }
#line 928 "src/frontend/parser.tab.cpp" // lalr1.cc:859
    break;

  case 51:
#line 304 "src/grammar/parser.yy" // lalr1.cc:859
    { (yylhs.value.abs_node) = new Nodes::LocalNode(*(yystack_[0].value.sval)); }
#line 934 "src/frontend/parser.tab.cpp" // lalr1.cc:859
    break;

  case 52:
#line 308 "src/grammar/parser.yy" // lalr1.cc:859
    { (yylhs.value.abs_node) = new Nodes::ConstantNode(*(yystack_[0].value.sval)); }
#line 940 "src/frontend/parser.tab.cpp" // lalr1.cc:859
    break;


#line 944 "src/frontend/parser.tab.cpp" // lalr1.cc:859
            default:
              break;
            }
        }
      catch (const syntax_error& yyexc)
        {
          error (yyexc);
          YYERROR;
        }
      YY_SYMBOL_PRINT ("-> $$ =", yylhs);
      yypop_ (yylen);
      yylen = 0;
      YY_STACK_PRINT ();

      // Shift the result of the reduction.
      yypush_ (YY_NULLPTR, yylhs);
    }
    goto yynewstate;

  /*--------------------------------------.
  | yyerrlab -- here on detecting error.  |
  `--------------------------------------*/
  yyerrlab:
    // If not already recovering from an error, report this error.
    if (!yyerrstatus_)
      {
        ++yynerrs_;
        error (yysyntax_error_ (yystack_[0].state, yyla));
      }


    if (yyerrstatus_ == 3)
      {
        /* If just tried and failed to reuse lookahead token after an
           error, discard it.  */

        // Return failure if at end of input.
        if (yyla.type_get () == yyeof_)
          YYABORT;
        else if (!yyla.empty ())
          {
            yy_destroy_ ("Error: discarding", yyla);
            yyla.clear ();
          }
      }

    // Else will try to reuse lookahead token after shifting the error token.
    goto yyerrlab1;


  /*---------------------------------------------------.
  | 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.  */
    if (false)
      goto yyerrorlab;
    /* Do not reclaim the symbols of the rule whose action triggered
       this YYERROR.  */
    yypop_ (yylen);
    yylen = 0;
    goto yyerrlab1;

  /*-------------------------------------------------------------.
  | yyerrlab1 -- common code for both syntax error and YYERROR.  |
  `-------------------------------------------------------------*/
  yyerrlab1:
    yyerrstatus_ = 3;   // Each real token shifted decrements this.
    {
      stack_symbol_type error_token;
      for (;;)
        {
          yyn = yypact_[yystack_[0].state];
          if (!yy_pact_value_is_default_ (yyn))
            {
              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 (yystack_.size () == 1)
            YYABORT;

          yy_destroy_ ("Error: popping", yystack_[0]);
          yypop_ ();
          YY_STACK_PRINT ();
        }


      // Shift the error token.
      error_token.state = yyn;
      yypush_ ("Shifting", error_token);
    }
    goto yynewstate;

    // Accept.
  yyacceptlab:
    yyresult = 0;
    goto yyreturn;

    // Abort.
  yyabortlab:
    yyresult = 1;
    goto yyreturn;

  yyreturn:
    if (!yyla.empty ())
      yy_destroy_ ("Cleanup: discarding lookahead", yyla);

    /* Do not reclaim the symbols of the rule whose action triggered
       this YYABORT or YYACCEPT.  */
    yypop_ (yylen);
    while (1 < yystack_.size ())
      {
        yy_destroy_ ("Cleanup: popping", yystack_[0]);
        yypop_ ();
      }

    return yyresult;
  }
    catch (...)
      {
        YYCDEBUG << "Exception caught: cleaning lookahead and stack"
                 << std::endl;
        // Do not try to display the values of the reclaimed symbols,
        // as their printer might throw an exception.
        if (!yyla.empty ())
          yy_destroy_ (YY_NULLPTR, yyla);

        while (1 < yystack_.size ())
          {
            yy_destroy_ (YY_NULLPTR, yystack_[0]);
            yypop_ ();
          }
        throw;
      }
  }
Ejemplo n.º 2
0
  int
  Parser::parse ()
  {
    /// Lookahead and lookahead in internal form.
    int yychar = yyempty_;
    int yytoken = 0;

    /* State.  */
    int yyn;
    int yylen = 0;
    int yystate = 0;

    /* Error handling.  */
    int yynerrs_ = 0;
    int yyerrstatus_ = 0;

    /// Semantic value of the lookahead.
    semantic_type yylval;
    /// Location of the lookahead.
    location_type yylloc;
    /// The locations where the error started and ended.
    location_type yyerror_range[2];

    /// $$.
    semantic_type yyval;
    /// @$.
    location_type yyloc;

    int yyresult;

    YYCDEBUG << "Starting parse" << std::endl;


    /* Initialize the stacks.  The initial state will be pushed in
       yynewstate, since the latter expects the semantical and the
       location values to have been already stored, initialize these
       stacks with a primary value.  */
    yystate_stack_ = state_stack_type (0);
    yysemantic_stack_ = semantic_stack_type (0);
    yylocation_stack_ = location_stack_type (0);
    yysemantic_stack_.push (yylval);
    yylocation_stack_.push (yylloc);

    /* New state.  */
  yynewstate:
    yystate_stack_.push (yystate);
    YYCDEBUG << "Entering state " << yystate << std::endl;

    /* Accept?  */
    if (yystate == yyfinal_)
      goto yyacceptlab;

    goto yybackup;

    /* Backup.  */
  yybackup:

    /* Try to take a decision without lookahead.  */
    yyn = yypact_[yystate];
    if (yyn == yypact_ninf_)
      goto yydefault;

    /* Read a lookahead token.  */
    if (yychar == yyempty_)
      {
	YYCDEBUG << "Reading a token: ";
	yychar = yylex (&yylval, &yylloc, scanner);
      }


    /* Convert token to internal form.  */
    if (yychar <= yyeof_)
      {
	yychar = yytoken = yyeof_;
	YYCDEBUG << "Now at end of input." << std::endl;
      }
    else
      {
	yytoken = yytranslate_ (yychar);
	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;

    /* Reduce or error.  */
    yyn = yytable_[yyn];
    if (yyn <= 0)
      {
	if (yyn == 0 || yyn == yytable_ninf_)
	goto yyerrlab;
	yyn = -yyn;
	goto yyreduce;
      }

    /* Shift the lookahead token.  */
    YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);

    /* Discard the token being shifted.  */
    yychar = yyempty_;

    yysemantic_stack_.push (yylval);
    yylocation_stack_.push (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:
    yylen = yyr2_[yyn];
    /* If YYLEN is nonzero, implement the default value of the action:
       `$$ = $1'.  Otherwise, use the top of the stack.

       Otherwise, the following line sets YYVAL to garbage.
       This behavior is undocumented and Bison
       users should not rely upon it.  */
    if (yylen)
      yyval = yysemantic_stack_[yylen - 1];
    else
      yyval = yysemantic_stack_[0];

    {
      slice<location_type, location_stack_type> slice (yylocation_stack_, yylen);
      YYLLOC_DEFAULT (yyloc, slice, yylen);
    }
    YY_REDUCE_PRINT (yyn);
    switch (yyn)
      {
	  case 21:

/* Line 678 of lalr1.cc  */
#line 79 "parser.ypp"
    { std::vector<std::string>  line ;
						     line.push_back ( (yysemantic_stack_[(3) - (2)]) ) ;
						     configlines.push_back ( line ) ; }
    break;

  case 22:

/* Line 678 of lalr1.cc  */
#line 85 "parser.ypp"
    { std::vector<std::string>  line ;
						     line.push_back ( (yysemantic_stack_[(4) - (2)]) ) ;
						     line.push_back ( (yysemantic_stack_[(4) - (4)]) ) ; 
						     configlines.push_back ( line ) ; }
    break;

  case 23:

/* Line 678 of lalr1.cc  */
#line 93 "parser.ypp"
    { std::vector<std::string>  line ;
						     	    line.push_back ( (yysemantic_stack_[(5) - (2)]) ) ;
						            line.push_back ( (yysemantic_stack_[(5) - (4)]) ) ; 
						            line.push_back ( (yysemantic_stack_[(5) - (5)]) ) ; 
						     	    configlines.push_back ( line ) ; }
    break;

  case 24:

/* Line 678 of lalr1.cc  */
#line 101 "parser.ypp"
    { std::vector<std::string>  line ;
						     	    line.push_back ( (yysemantic_stack_[(6) - (2)]) ) ;
						            line.push_back ( (yysemantic_stack_[(6) - (4)]) ) ; 
						            line.push_back ( (yysemantic_stack_[(6) - (5)]) ) ;
						            line.push_back ( (yysemantic_stack_[(6) - (6)]) ) ;
						     	    configlines.push_back ( line ) ; }
    break;

  case 25:

/* Line 678 of lalr1.cc  */
#line 110 "parser.ypp"
    { std::vector<std::string>  line ;
								     	    line.push_back ( (yysemantic_stack_[(7) - (2)]) ) ;
								            line.push_back ( (yysemantic_stack_[(7) - (4)]) ) ; 
								            line.push_back ( (yysemantic_stack_[(7) - (5)]) ) ; 
								            line.push_back ( (yysemantic_stack_[(7) - (6)]) ) ; 
								            line.push_back ( (yysemantic_stack_[(7) - (7)]) ) ; 
								     	    configlines.push_back ( line ) ; }
    break;

  case 26:

/* Line 678 of lalr1.cc  */
#line 120 "parser.ypp"
    { std::vector<std::string>  line ;
									     	    line.push_back ( (yysemantic_stack_[(8) - (2)]) ) ;
									            line.push_back ( (yysemantic_stack_[(8) - (4)]) ) ; 
									            line.push_back ( (yysemantic_stack_[(8) - (5)]) ) ; 
									            line.push_back ( (yysemantic_stack_[(8) - (6)]) ) ; 
									            line.push_back ( (yysemantic_stack_[(8) - (7)]) ) ; 
									            line.push_back ( (yysemantic_stack_[(8) - (8)]) ) ; 
						     	    			    configlines.push_back ( line ) ; }
    break;

  case 27:

/* Line 678 of lalr1.cc  */
#line 131 "parser.ypp"
    { std::vector<std::string>  line ;
									     	    	line.push_back ( (yysemantic_stack_[(9) - (2)]) ) ;
									            	line.push_back ( (yysemantic_stack_[(9) - (4)]) ) ; 
									            	line.push_back ( (yysemantic_stack_[(9) - (5)]) ) ; 
									            	line.push_back ( (yysemantic_stack_[(9) - (6)]) ) ; 
									            	line.push_back ( (yysemantic_stack_[(9) - (7)]) ) ; 
									            	line.push_back ( (yysemantic_stack_[(9) - (8)]) ) ; 
									            	line.push_back ( (yysemantic_stack_[(9) - (9)]) ) ; 
						     	    			    	configlines.push_back ( line ) ; }
    break;

  case 28:

/* Line 678 of lalr1.cc  */
#line 143 "parser.ypp"
    { std::vector<std::string>  line ;
									     	    		line.push_back ( (yysemantic_stack_[(10) - (2)]) ) ;
									            		line.push_back ( (yysemantic_stack_[(10) - (4)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(10) - (5)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(10) - (6)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(10) - (7)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(10) - (8)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(10) - (9)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(10) - (10)]) ) ; 
												configlines.push_back ( line ) ; }
    break;

  case 29:

/* Line 678 of lalr1.cc  */
#line 157 "parser.ypp"
    { std::vector<std::string>  line ;
									     	    		line.push_back ( (yysemantic_stack_[(11) - (2)]) ) ;
									            		line.push_back ( (yysemantic_stack_[(11) - (4)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(11) - (5)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(11) - (6)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(11) - (7)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(11) - (8)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(11) - (9)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(11) - (10)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(11) - (11)]) ) ; 
												configlines.push_back ( line ) ; }
    break;

  case 30:

/* Line 678 of lalr1.cc  */
#line 172 "parser.ypp"
    { std::vector<std::string>  line ;
									     	    		line.push_back ( (yysemantic_stack_[(12) - (2)]) ) ;
									            		line.push_back ( (yysemantic_stack_[(12) - (4)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(12) - (5)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(12) - (6)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(12) - (7)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(12) - (8)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(12) - (9)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(12) - (10)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(12) - (11)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(12) - (12)]) ) ; 
												configlines.push_back ( line ) ; }
    break;

  case 31:

/* Line 678 of lalr1.cc  */
#line 189 "parser.ypp"
    { std::vector<std::string>  line ;
									     	    		line.push_back ( (yysemantic_stack_[(13) - (2)]) ) ;
									            		line.push_back ( (yysemantic_stack_[(13) - (4)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(13) - (5)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(13) - (6)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(13) - (7)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(13) - (8)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(13) - (9)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(13) - (10)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(13) - (11)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(13) - (12)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(13) - (13)]) ) ; 
												configlines.push_back ( line ) ; }
    break;

  case 32:

/* Line 678 of lalr1.cc  */
#line 207 "parser.ypp"
    { std::vector<std::string>  line ;
									     	    		line.push_back ( (yysemantic_stack_[(14) - (2)]) ) ;
									            		line.push_back ( (yysemantic_stack_[(14) - (4)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(14) - (5)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(14) - (6)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(14) - (7)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(14) - (8)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(14) - (9)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(14) - (10)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(14) - (11)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(14) - (12)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(14) - (13)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(14) - (14)]) ) ; 
												configlines.push_back ( line ) ; }
    break;

  case 33:

/* Line 678 of lalr1.cc  */
#line 227 "parser.ypp"
    { std::vector<std::string>  line ;
									     	    		line.push_back ( (yysemantic_stack_[(15) - (2)]) ) ;
									            		line.push_back ( (yysemantic_stack_[(15) - (4)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(15) - (5)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(15) - (6)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(15) - (7)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(15) - (8)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(15) - (9)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(15) - (10)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(15) - (11)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(15) - (12)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(15) - (13)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(15) - (14)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(15) - (15)]) ) ; 
												configlines.push_back ( line ) ; }
    break;

  case 34:

/* Line 678 of lalr1.cc  */
#line 248 "parser.ypp"
    { std::vector<std::string>  line ;
									     	    		line.push_back ( (yysemantic_stack_[(16) - (2)]) ) ;
									            		line.push_back ( (yysemantic_stack_[(16) - (4)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(16) - (5)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(16) - (6)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(16) - (7)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(16) - (8)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(16) - (9)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(16) - (10)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(16) - (11)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(16) - (12)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(16) - (13)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(16) - (14)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(16) - (15)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(16) - (16)]) ) ; 
												configlines.push_back ( line ) ; }
    break;

  case 35:

/* Line 678 of lalr1.cc  */
#line 270 "parser.ypp"
    { std::vector<std::string>  line ;
									     	    		line.push_back ( (yysemantic_stack_[(17) - (2)]) ) ;
									            		line.push_back ( (yysemantic_stack_[(17) - (4)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(17) - (5)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(17) - (6)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(17) - (7)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(17) - (8)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(17) - (9)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(17) - (10)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(17) - (11)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(17) - (12)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(17) - (13)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(17) - (14)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(17) - (15)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(17) - (16)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(17) - (17)]) ) ; 
												configlines.push_back ( line ) ; }
    break;

  case 36:

/* Line 678 of lalr1.cc  */
#line 293 "parser.ypp"
    { std::vector<std::string>  line ;
									     	    		line.push_back ( (yysemantic_stack_[(18) - (2)]) ) ;
									            		line.push_back ( (yysemantic_stack_[(18) - (4)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(18) - (5)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(18) - (6)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(18) - (7)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(18) - (8)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(18) - (9)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(18) - (10)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(18) - (11)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(18) - (12)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(18) - (13)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(18) - (14)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(18) - (15)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(18) - (16)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(18) - (17)]) ) ; 
									            		line.push_back ( (yysemantic_stack_[(18) - (18)]) ) ; 
												configlines.push_back ( line ) ; }
    break;

  case 37:

/* Line 678 of lalr1.cc  */
#line 317 "parser.ypp"
    { }
    break;



/* Line 678 of lalr1.cc  */
#line 695 "parser.tab.cpp"
	default:
          break;
      }
    YY_SYMBOL_PRINT ("-> $$ =", yyr1_[yyn], &yyval, &yyloc);

    yypop_ (yylen);
    yylen = 0;
    YY_STACK_PRINT ();

    yysemantic_stack_.push (yyval);
    yylocation_stack_.push (yyloc);

    /* Shift the result of the reduction.  */
    yyn = yyr1_[yyn];
    yystate = yypgoto_[yyn - yyntokens_] + yystate_stack_[0];
    if (0 <= yystate && yystate <= yylast_
	&& yycheck_[yystate] == yystate_stack_[0])
      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_;
	error (yylloc, yysyntax_error_ (yystate));
      }

    yyerror_range[0] = yylloc;
    if (yyerrstatus_ == 3)
      {
	/* If just tried and failed to reuse lookahead token after an
	 error, discard it.  */

	if (yychar <= yyeof_)
	  {
	  /* Return failure if at end of input.  */
	  if (yychar == yyeof_)
	    YYABORT;
	  }
	else
	  {
	    yydestruct_ ("Error: discarding", yytoken, &yylval, &yylloc);
	    yychar = yyempty_;
	  }
      }

    /* Else will try to reuse lookahead token after shifting the error
       token.  */
    goto yyerrlab1;


  /*---------------------------------------------------.
  | 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.  */
    if (false)
      goto yyerrorlab;

    yyerror_range[0] = yylocation_stack_[yylen - 1];
    /* Do not reclaim the symbols of the rule which action triggered
       this YYERROR.  */
    yypop_ (yylen);
    yylen = 0;
    yystate = yystate_stack_[0];
    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 (yystate_stack_.height () == 1)
	YYABORT;

	yyerror_range[0] = yylocation_stack_[0];
	yydestruct_ ("Error: popping",
		     yystos_[yystate],
		     &yysemantic_stack_[0], &yylocation_stack_[0]);
	yypop_ ();
	yystate = yystate_stack_[0];
	YY_STACK_PRINT ();
      }

    yyerror_range[1] = yylloc;
    // Using YYLLOC is tempting, but would change the location of
    // the lookahead.  YYLOC is available though.
    YYLLOC_DEFAULT (yyloc, (yyerror_range - 1), 2);
    yysemantic_stack_.push (yylval);
    yylocation_stack_.push (yyloc);

    /* Shift the error token.  */
    YY_SYMBOL_PRINT ("Shifting", yystos_[yyn],
		     &yysemantic_stack_[0], &yylocation_stack_[0]);

    yystate = yyn;
    goto yynewstate;

    /* Accept.  */
  yyacceptlab:
    yyresult = 0;
    goto yyreturn;

    /* Abort.  */
  yyabortlab:
    yyresult = 1;
    goto yyreturn;

  yyreturn:
    if (yychar != yyempty_)
      yydestruct_ ("Cleanup: discarding lookahead", yytoken, &yylval, &yylloc);

    /* Do not reclaim the symbols of the rule which action triggered
       this YYABORT or YYACCEPT.  */
    yypop_ (yylen);
    while (yystate_stack_.height () != 1)
      {
	yydestruct_ ("Cleanup: popping",
		   yystos_[yystate_stack_[0]],
		   &yysemantic_stack_[0],
		   &yylocation_stack_[0]);
	yypop_ ();
      }

    return yyresult;
  }
Ejemplo n.º 3
0
 inline
 Parser::by_type::by_type (token_type t)
   : type (yytranslate_ (t))
 {}
Ejemplo n.º 4
0
  int
  config_parser::parse ()
  {
    /// Lookahead and lookahead in internal form.
    int yychar = yyempty_;
    int yytoken = 0;

    /* State.  */
    int yyn;
    int yylen = 0;
    int yystate = 0;

    /* Error handling.  */
    int yynerrs_ = 0;
    int yyerrstatus_ = 0;

    /// Semantic value of the lookahead.
    semantic_type yylval;
    /// Location of the lookahead.
    location_type yylloc;
    /// The locations where the error started and ended.
    location_type yyerror_range[2];

    /// $$.
    semantic_type yyval;
    /// @$.
    location_type yyloc;

    int yyresult;

    YYCDEBUG << "Starting parse" << std::endl;


    /* User initialization code.  */
    
{
// start
	// void
 yylloc.begin.filename = yylloc.end.filename = driver.getFileNamePtr(); //new string(driver.getFileName());
/* @$.begin.line = @$.end.line = 0;
 @$.begin.column = @$.end.column = 0;
*/
}


    /* Initialize the stacks.  The initial state will be pushed in
       yynewstate, since the latter expects the semantical and the
       location values to have been already stored, initialize these
       stacks with a primary value.  */
    yystate_stack_ = state_stack_type (0);
    yysemantic_stack_ = semantic_stack_type (0);
    yylocation_stack_ = location_stack_type (0);
    yysemantic_stack_.push (yylval);
    yylocation_stack_.push (yylloc);

    /* New state.  */
  yynewstate:
    yystate_stack_.push (yystate);
    YYCDEBUG << "Entering state " << yystate << std::endl;

    /* Accept?  */
    if (yystate == yyfinal_)
      goto yyacceptlab;

    goto yybackup;

    /* Backup.  */
  yybackup:

    /* Try to take a decision without lookahead.  */
    yyn = yypact_[yystate];
    if (yyn == yypact_ninf_)
      goto yydefault;

    /* Read a lookahead token.  */
    if (yychar == yyempty_)
      {
	YYCDEBUG << "Reading a token: ";
	yychar = yylex (&yylval, &yylloc);
      }


    /* Convert token to internal form.  */
    if (yychar <= yyeof_)
      {
	yychar = yytoken = yyeof_;
	YYCDEBUG << "Now at end of input." << std::endl;
      }
    else
      {
	yytoken = yytranslate_ (yychar);
	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;

    /* Reduce or error.  */
    yyn = yytable_[yyn];
    if (yyn <= 0)
      {
	if (yyn == 0 || yyn == yytable_ninf_)
	goto yyerrlab;
	yyn = -yyn;
	goto yyreduce;
      }

    /* Shift the lookahead token.  */
    YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);

    /* Discard the token being shifted.  */
    yychar = yyempty_;

    yysemantic_stack_.push (yylval);
    yylocation_stack_.push (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:
    yylen = yyr2_[yyn];
    /* If YYLEN is nonzero, implement the default value of the action:
       `$$ = $1'.  Otherwise, use the top of the stack.

       Otherwise, the following line sets YYVAL to garbage.
       This behavior is undocumented and Bison
       users should not rely upon it.  */
    if (yylen)
      yyval = yysemantic_stack_[yylen - 1];
    else
      yyval = yysemantic_stack_[0];

    {
      slice<location_type, location_stack_type> slice (yylocation_stack_, yylen);
      YYLLOC_DEFAULT (yyloc, slice, yylen);
    }
    YY_REDUCE_PRINT (yyn);
    switch (yyn)
      {
	  case 2:

    { driver.addBlockList((yysemantic_stack_[(1) - (1)].gc_block_list)); }
    break;

  case 4:

    { (yyval.gc_block_list) = new GConfigBlockList((yysemantic_stack_[(1) - (1)].gc_block)); }
    break;

  case 5:

    { (yysemantic_stack_[(2) - (1)].gc_block_list)->appendBlock((yysemantic_stack_[(2) - (2)].gc_block)); (yyval.gc_block_list) = (yysemantic_stack_[(2) - (1)].gc_block_list); }
    break;

  case 6:

    { (yyval.gc_block_header) = new GConfigBlockHeader((yysemantic_stack_[(5) - (1)].str_val), (yysemantic_stack_[(5) - (3)].gc_identifier), (yylocation_stack_[(5) - (1)])); free((yysemantic_stack_[(5) - (1)].str_val)); }
    break;

  case 7:

    { (yyval.gc_block_header) = new GConfigBlockHeader((yysemantic_stack_[(2) - (1)].str_val), (yylocation_stack_[(2) - (1)])); free((yysemantic_stack_[(2) - (1)].str_val)); }
    break;

  case 8:

    { (yyval.gc_block) = new GConfigBlock((yysemantic_stack_[(3) - (1)].gc_block_header), (yysemantic_stack_[(3) - (2)].gc_statement_list)); }
    break;

  case 9:

    { (yyval.gc_identifier) = new GConfigIdentifier((yysemantic_stack_[(1) - (1)].str_val), (yylocation_stack_[(1) - (1)])); free((yysemantic_stack_[(1) - (1)].str_val)); }
    break;

  case 10:

    { (yysemantic_stack_[(3) - (1)].gc_identifier)->appendString((yysemantic_stack_[(3) - (3)].str_val), (yylocation_stack_[(3) - (3)])); free((yysemantic_stack_[(3) - (3)].str_val)); (yyval.gc_identifier) = (yysemantic_stack_[(3) - (1)].gc_identifier); }
    break;

  case 11:

    { (yyval.gc_statement_list) = new GConfigStatementList((yysemantic_stack_[(1) - (1)].gc_statement)); }
    break;

  case 12:

    { (yysemantic_stack_[(2) - (1)].gc_statement_list)->appendStatement((yysemantic_stack_[(2) - (2)].gc_statement)); (yyval.gc_statement_list) = (yysemantic_stack_[(2) - (1)].gc_statement_list); }
    break;

  case 13:

    { (yyval.gc_statement) = (yysemantic_stack_[(1) - (1)].gc_block); }
    break;

  case 14:

    { (yyval.gc_statement) = (yysemantic_stack_[(1) - (1)].gc_function); }
    break;

  case 15:

    { (yyval.gc_statement) = (yysemantic_stack_[(1) - (1)].gc_variable); }
    break;

  case 16:

    { (yyval.gc_statement) = (yysemantic_stack_[(1) - (1)].gc_define); }
    break;

  case 17:

    { (yyval.gc_variable) = new GConfigVariableStatement((yysemantic_stack_[(4) - (1)].gc_identifier), (yysemantic_stack_[(4) - (3)].gc_argument)); }
    break;

  case 18:

    { (yyval.gc_define) = new GConfigDefineStatement((yysemantic_stack_[(2) - (1)].gc_identifier)); }
    break;

  case 19:

    { (yyval.gc_function) = new GConfigFunctionStatement((yysemantic_stack_[(5) - (1)].gc_identifier), (yysemantic_stack_[(5) - (3)].gc_argument_list)); }
    break;

  case 20:

    { (yyval.gc_argument) = new GConfigArgument((yysemantic_stack_[(1) - (1)].gc_scalar_val)); }
    break;

  case 21:

    { (yyval.gc_argument) = new GConfigArgument((yysemantic_stack_[(3) - (2)].gc_argument_list)); }
    break;

  case 22:

    { (yyval.gc_argument_list) = new GConfigArgumentList((yysemantic_stack_[(1) - (1)].gc_scalar_val)); }
    break;

  case 23:

    { (yysemantic_stack_[(3) - (1)].gc_argument_list)->appendArgument((yysemantic_stack_[(3) - (3)].gc_scalar_val)); (yyval.gc_argument_list) = (yysemantic_stack_[(3) - (1)].gc_argument_list); }
    break;

  case 24:

    { (yyval.gc_scalar_val) = new GConfigScalarVal((yysemantic_stack_[(1) - (1)].long_val), (yylocation_stack_[(1) - (1)])); }
    break;

  case 25:

    { (yyval.gc_scalar_val) = new GConfigScalarVal((yysemantic_stack_[(1) - (1)].double_val), (yylocation_stack_[(1) - (1)])); }
    break;

  case 26:

    { (yyval.gc_scalar_val) = new GConfigScalarVal((yysemantic_stack_[(1) - (1)].str_val), (yylocation_stack_[(1) - (1)])); free((yysemantic_stack_[(1) - (1)].str_val)); }
    break;

  case 27:

    { (yyval.gc_scalar_val) = new GConfigScalarVal((yysemantic_stack_[(1) - (1)].gc_identifier)); }
    break;



	default:
          break;
      }
    YY_SYMBOL_PRINT ("-> $$ =", yyr1_[yyn], &yyval, &yyloc);

    yypop_ (yylen);
    yylen = 0;
    YY_STACK_PRINT ();

    yysemantic_stack_.push (yyval);
    yylocation_stack_.push (yyloc);

    /* Shift the result of the reduction.  */
    yyn = yyr1_[yyn];
    yystate = yypgoto_[yyn - yyntokens_] + yystate_stack_[0];
    if (0 <= yystate && yystate <= yylast_
	&& yycheck_[yystate] == yystate_stack_[0])
      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_;
	error (yylloc, yysyntax_error_ (yystate, yytoken));
      }

    yyerror_range[0] = yylloc;
    if (yyerrstatus_ == 3)
      {
	/* If just tried and failed to reuse lookahead token after an
	 error, discard it.  */

	if (yychar <= yyeof_)
	  {
	  /* Return failure if at end of input.  */
	  if (yychar == yyeof_)
	    YYABORT;
	  }
	else
	  {
	    yydestruct_ ("Error: discarding", yytoken, &yylval, &yylloc);
	    yychar = yyempty_;
	  }
      }

    /* Else will try to reuse lookahead token after shifting the error
       token.  */
    goto yyerrlab1;


  /*---------------------------------------------------.
  | 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.  */
    if (false)
      goto yyerrorlab;

    yyerror_range[0] = yylocation_stack_[yylen - 1];
    /* Do not reclaim the symbols of the rule which action triggered
       this YYERROR.  */
    yypop_ (yylen);
    yylen = 0;
    yystate = yystate_stack_[0];
    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 (yystate_stack_.height () == 1)
	YYABORT;

	yyerror_range[0] = yylocation_stack_[0];
	yydestruct_ ("Error: popping",
		     yystos_[yystate],
		     &yysemantic_stack_[0], &yylocation_stack_[0]);
	yypop_ ();
	yystate = yystate_stack_[0];
	YY_STACK_PRINT ();
      }

    yyerror_range[1] = yylloc;
    // Using YYLLOC is tempting, but would change the location of
    // the lookahead.  YYLOC is available though.
    YYLLOC_DEFAULT (yyloc, (yyerror_range - 1), 2);
    yysemantic_stack_.push (yylval);
    yylocation_stack_.push (yyloc);

    /* Shift the error token.  */
    YY_SYMBOL_PRINT ("Shifting", yystos_[yyn],
		     &yysemantic_stack_[0], &yylocation_stack_[0]);

    yystate = yyn;
    goto yynewstate;

    /* Accept.  */
  yyacceptlab:
    yyresult = 0;
    goto yyreturn;

    /* Abort.  */
  yyabortlab:
    yyresult = 1;
    goto yyreturn;

  yyreturn:
    if (yychar != yyempty_)
      yydestruct_ ("Cleanup: discarding lookahead", yytoken, &yylval, &yylloc);

    /* Do not reclaim the symbols of the rule which action triggered
       this YYABORT or YYACCEPT.  */
    yypop_ (yylen);
    while (yystate_stack_.height () != 1)
      {
	yydestruct_ ("Cleanup: popping",
		   yystos_[yystate_stack_[0]],
		   &yysemantic_stack_[0],
		   &yylocation_stack_[0]);
	yypop_ ();
      }

    return yyresult;
  }
Ejemplo n.º 5
0
  int
  obj_parser::parse ()
  {
    /// Lookahead and lookahead in internal form.
    int yychar = yyempty_;
    int yytoken = 0;

    // State.
    int yyn;
    int yylen = 0;
    int yystate = 0;

    // Error handling.
    int yynerrs_ = 0;
    int yyerrstatus_ = 0;

    /// Semantic value of the lookahead.
    static semantic_type yyval_default;
    semantic_type yylval = yyval_default;
    /// Location of the lookahead.
    location_type yylloc;
    /// The locations where the error started and ended.
    location_type yyerror_range[3];

    /// $$.
    semantic_type yyval;
    /// @$.
    location_type yyloc;

    int yyresult;

    // FIXME: This shoud be completely indented.  It is not yet to
    // avoid gratuitous conflicts when merging into the master branch.
    try
      {
    YYCDEBUG << "Starting parse" << std::endl;


    /* Initialize the stacks.  The initial state will be pushed in
       yynewstate, since the latter expects the semantical and the
       location values to have been already stored, initialize these
       stacks with a primary value.  */
    yystate_stack_.clear ();
    yysemantic_stack_.clear ();
    yylocation_stack_.clear ();
    yysemantic_stack_.push (yylval);
    yylocation_stack_.push (yylloc);

    /* New state.  */
  yynewstate:
    yystate_stack_.push (yystate);
    YYCDEBUG << "Entering state " << yystate << std::endl;

    /* Accept?  */
    if (yystate == yyfinal_)
      goto yyacceptlab;

    goto yybackup;

    /* Backup.  */
  yybackup:

    /* Try to take a decision without lookahead.  */
    yyn = yypact_[yystate];
    if (yy_pact_value_is_default_ (yyn))
      goto yydefault;

    /* Read a lookahead token.  */
    if (yychar == yyempty_)
      {
        YYCDEBUG << "Reading a token: ";
        yychar = yylex (&yylval, &yylloc, reader);
      }

    /* Convert token to internal form.  */
    if (yychar <= yyeof_)
      {
	yychar = yytoken = yyeof_;
	YYCDEBUG << "Now at end of input." << std::endl;
      }
    else
      {
	yytoken = yytranslate_ (yychar);
	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;

    /* Reduce or error.  */
    yyn = yytable_[yyn];
    if (yyn <= 0)
      {
	if (yy_table_value_is_error_ (yyn))
	  goto yyerrlab;
	yyn = -yyn;
	goto yyreduce;
      }

    /* Shift the lookahead token.  */
    YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);

    /* Discard the token being shifted.  */
    yychar = yyempty_;

    yysemantic_stack_.push (yylval);
    yylocation_stack_.push (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:
    yylen = yyr2_[yyn];
    /* If YYLEN is nonzero, implement the default value of the action:
       `$$ = $1'.  Otherwise, use the top of the stack.

       Otherwise, the following line sets YYVAL to garbage.
       This behavior is undocumented and Bison
       users should not rely upon it.  */
    if (yylen)
      yyval = yysemantic_stack_[yylen - 1];
    else
      yyval = yysemantic_stack_[0];

    // Compute the default @$.
    {
      slice<location_type, location_stack_type> slice (yylocation_stack_, yylen);
      YYLLOC_DEFAULT (yyloc, slice, yylen);
    }

    // Perform the reduction.
    YY_REDUCE_PRINT (yyn);
    switch (yyn)
      {
          case 6:
/* Line 664 of lalr1.cc  */
#line 174 "obj_parser.y"
    { reader.parse_mtl(*(yysemantic_stack_[(2) - (2)].sval)); }
    break;

  case 7:
/* Line 664 of lalr1.cc  */
#line 175 "obj_parser.y"
    { reader.set_mtl_name((yysemantic_stack_[(1) - (1)].sval)); }
    break;

  case 8:
/* Line 664 of lalr1.cc  */
#line 176 "obj_parser.y"
    { reader.add((yysemantic_stack_[(1) - (1)].v)); }
    break;

  case 9:
/* Line 664 of lalr1.cc  */
#line 177 "obj_parser.y"
    { reader.add((yysemantic_stack_[(1) - (1)].vn)); }
    break;

  case 10:
/* Line 664 of lalr1.cc  */
#line 178 "obj_parser.y"
    { reader.add((yysemantic_stack_[(1) - (1)].vt)); }
    break;

  case 11:
/* Line 664 of lalr1.cc  */
#line 179 "obj_parser.y"
    { reader.add((yysemantic_stack_[(1) - (1)].f)); }
    break;

  case 12:
/* Line 664 of lalr1.cc  */
#line 180 "obj_parser.y"
    { reader.add((yysemantic_stack_[(1) - (1)].obj)); }
    break;

  case 14:
/* Line 664 of lalr1.cc  */
#line 182 "obj_parser.y"
    { reader.add((yysemantic_stack_[(1) - (1)].obj)); }
    break;

  case 15:
/* Line 664 of lalr1.cc  */
#line 185 "obj_parser.y"
    { reader.add((yysemantic_stack_[(1) - (1)].mtl)); }
    break;

  case 16:
/* Line 664 of lalr1.cc  */
#line 186 "obj_parser.y"
    { reader.set_mtl_Ka((yysemantic_stack_[(1) - (1)].color)); }
    break;

  case 17:
/* Line 664 of lalr1.cc  */
#line 187 "obj_parser.y"
    { reader.set_mtl_Kd((yysemantic_stack_[(1) - (1)].color)); }
    break;

  case 18:
/* Line 664 of lalr1.cc  */
#line 188 "obj_parser.y"
    { reader.set_mtl_Ks((yysemantic_stack_[(1) - (1)].color)); }
    break;

  case 19:
/* Line 664 of lalr1.cc  */
#line 189 "obj_parser.y"
    { reader.set_mtl_Ns((yysemantic_stack_[(1) - (1)].fval)); }
    break;

  case 20:
/* Line 664 of lalr1.cc  */
#line 190 "obj_parser.y"
    { reader.set_mtl_Ke((yysemantic_stack_[(1) - (1)].color)); }
    break;

  case 21:
/* Line 664 of lalr1.cc  */
#line 191 "obj_parser.y"
    { reader.set_mtl_d((yysemantic_stack_[(1) - (1)].fval)); }
    break;

  case 22:
/* Line 664 of lalr1.cc  */
#line 192 "obj_parser.y"
    { reader.set_mtl_illum((yysemantic_stack_[(1) - (1)].ival)); }
    break;

  case 23:
/* Line 664 of lalr1.cc  */
#line 193 "obj_parser.y"
    { reader.set_mtl_map_Ka((yysemantic_stack_[(1) - (1)].tex)); }
    break;

  case 24:
/* Line 664 of lalr1.cc  */
#line 194 "obj_parser.y"
    { reader.set_mtl_map_Kd((yysemantic_stack_[(1) - (1)].tex)); }
    break;

  case 25:
/* Line 664 of lalr1.cc  */
#line 195 "obj_parser.y"
    { reader.set_mtl_map_Ks((yysemantic_stack_[(1) - (1)].tex)); }
    break;

  case 26:
/* Line 664 of lalr1.cc  */
#line 196 "obj_parser.y"
    { reader.set_mtl_map_Ns((yysemantic_stack_[(1) - (1)].tex)); }
    break;

  case 27:
/* Line 664 of lalr1.cc  */
#line 197 "obj_parser.y"
    { reader.set_mtl_map_bump((yysemantic_stack_[(1) - (1)].tex)); }
    break;

  case 28:
/* Line 664 of lalr1.cc  */
#line 198 "obj_parser.y"
    { reader.set_mtl_map_d((yysemantic_stack_[(1) - (1)].tex)); }
    break;

  case 29:
/* Line 664 of lalr1.cc  */
#line 199 "obj_parser.y"
    { reader.set_mtl_disp((yysemantic_stack_[(1) - (1)].tex)); }
    break;

  case 30:
/* Line 664 of lalr1.cc  */
#line 200 "obj_parser.y"
    { reader.set_mtl_decal((yysemantic_stack_[(1) - (1)].tex)); }
    break;

  case 31:
/* Line 664 of lalr1.cc  */
#line 201 "obj_parser.y"
    { reader.set_mtl_refl((yysemantic_stack_[(1) - (1)].tex)); }
    break;

  case 32:
/* Line 664 of lalr1.cc  */
#line 202 "obj_parser.y"
    { reader.set_mtl_Tf((yysemantic_stack_[(1) - (1)].color)); }
    break;

  case 33:
/* Line 664 of lalr1.cc  */
#line 203 "obj_parser.y"
    { reader.set_mtl_Ni((yysemantic_stack_[(1) - (1)].fval)); }
    break;

  case 35:
/* Line 664 of lalr1.cc  */
#line 208 "obj_parser.y"
    { (yyval.sval) = (yysemantic_stack_[(2) - (2)].sval); }
    break;

  case 36:
/* Line 664 of lalr1.cc  */
#line 212 "obj_parser.y"
    { (yyval.v) = new obj::vertex((yysemantic_stack_[(5) - (2)].fval), (yysemantic_stack_[(5) - (3)].fval), (yysemantic_stack_[(5) - (4)].fval), (yysemantic_stack_[(5) - (5)].fval)); }
    break;

  case 37:
/* Line 664 of lalr1.cc  */
#line 213 "obj_parser.y"
    { (yyval.v) = new obj::vertex((yysemantic_stack_[(4) - (2)].fval), (yysemantic_stack_[(4) - (3)].fval), (yysemantic_stack_[(4) - (4)].fval)); }
    break;

  case 38:
/* Line 664 of lalr1.cc  */
#line 217 "obj_parser.y"
    { (yyval.vn) = new obj::normal((yysemantic_stack_[(4) - (2)].fval), (yysemantic_stack_[(4) - (3)].fval), (yysemantic_stack_[(4) - (4)].fval)); }
    break;

  case 39:
/* Line 664 of lalr1.cc  */
#line 221 "obj_parser.y"
    { (yyval.vt) = new obj::texture((yysemantic_stack_[(4) - (2)].fval), (yysemantic_stack_[(4) - (3)].fval), (yysemantic_stack_[(4) - (4)].fval)); }
    break;

  case 40:
/* Line 664 of lalr1.cc  */
#line 222 "obj_parser.y"
    { (yyval.vt) = new obj::texture((yysemantic_stack_[(3) - (2)].fval), (yysemantic_stack_[(3) - (3)].fval)); }
    break;

  case 41:
/* Line 664 of lalr1.cc  */
#line 223 "obj_parser.y"
    { (yyval.vt) = new obj::texture((yysemantic_stack_[(2) - (2)].fval)); }
    break;

  case 42:
/* Line 664 of lalr1.cc  */
#line 227 "obj_parser.y"
    { (yyval.obj) = new obj::object((yysemantic_stack_[(2) - (2)].sval)); }
    break;

  case 43:
/* Line 664 of lalr1.cc  */
#line 231 "obj_parser.y"
    { /*std::cout << "smoothing group: " << $2 << std::endl;*/ }
    break;

  case 44:
/* Line 664 of lalr1.cc  */
#line 232 "obj_parser.y"
    { /*std::cout << "smoothing group: " << $2 << std::endl;*/ }
    break;

  case 45:
/* Line 664 of lalr1.cc  */
#line 236 "obj_parser.y"
    { (yyval.iv) = new obj::ivertex((yysemantic_stack_[(5) - (1)].ival), (yysemantic_stack_[(5) - (3)].ival), (yysemantic_stack_[(5) - (5)].ival)); }
    break;

  case 46:
/* Line 664 of lalr1.cc  */
#line 237 "obj_parser.y"
    { (yyval.iv) = new obj::ivertex((yysemantic_stack_[(4) - (1)].ival), (yysemantic_stack_[(4) - (4)].ival)); }
    break;

  case 47:
/* Line 664 of lalr1.cc  */
#line 241 "obj_parser.y"
    { (yyval.f) = new obj::face((yysemantic_stack_[(5) - (2)].iv), (yysemantic_stack_[(5) - (3)].iv), (yysemantic_stack_[(5) - (4)].iv), (yysemantic_stack_[(5) - (5)].iv)); }
    break;

  case 48:
/* Line 664 of lalr1.cc  */
#line 242 "obj_parser.y"
    { (yyval.f) = new obj::face((yysemantic_stack_[(4) - (2)].iv), (yysemantic_stack_[(4) - (3)].iv), (yysemantic_stack_[(4) - (4)].iv)); }
    break;

  case 49:
/* Line 664 of lalr1.cc  */
#line 245 "obj_parser.y"
    { (yyval.obj) = new obj::object((yysemantic_stack_[(2) - (2)].sval)); }
    break;

  case 50:
/* Line 664 of lalr1.cc  */
#line 249 "obj_parser.y"
    { (yyval.fval) = (yysemantic_stack_[(1) - (1)].ival); }
    break;

  case 51:
/* Line 664 of lalr1.cc  */
#line 250 "obj_parser.y"
    { (yyval.fval) = (yysemantic_stack_[(1) - (1)].fval); }
    break;

  case 52:
/* Line 664 of lalr1.cc  */
#line 253 "obj_parser.y"
    { (yyval.sval) = (yysemantic_stack_[(1) - (1)].sval); }
    break;

  case 53:
/* Line 664 of lalr1.cc  */
#line 254 "obj_parser.y"
    { (yyval.sval) = (yysemantic_stack_[(1) - (1)].sval); }
    break;

  case 54:
/* Line 664 of lalr1.cc  */
#line 257 "obj_parser.y"
    { (yyval.mtl) = new obj::material((yysemantic_stack_[(2) - (2)].sval)); }
    break;

  case 56:
/* Line 664 of lalr1.cc  */
#line 261 "obj_parser.y"
    { (yyval.color) = new obj::vec3((yysemantic_stack_[(4) - (2)].fval), (yysemantic_stack_[(4) - (3)].fval), (yysemantic_stack_[(4) - (4)].fval)); }
    break;

  case 58:
/* Line 664 of lalr1.cc  */
#line 265 "obj_parser.y"
    { (yyval.color) = new obj::vec3((yysemantic_stack_[(4) - (2)].fval), (yysemantic_stack_[(4) - (3)].fval), (yysemantic_stack_[(4) - (4)].fval)); }
    break;

  case 60:
/* Line 664 of lalr1.cc  */
#line 269 "obj_parser.y"
    { (yyval.color) = new obj::vec3((yysemantic_stack_[(4) - (2)].fval), (yysemantic_stack_[(4) - (3)].fval), (yysemantic_stack_[(4) - (4)].fval)); }
    break;

  case 62:
/* Line 664 of lalr1.cc  */
#line 273 "obj_parser.y"
    { (yyval.color) = new obj::vec3((yysemantic_stack_[(4) - (2)].fval), (yysemantic_stack_[(4) - (3)].fval), (yysemantic_stack_[(4) - (4)].fval)); }
    break;

  case 63:
/* Line 664 of lalr1.cc  */
#line 276 "obj_parser.y"
    { (yyval.fval) = (yysemantic_stack_[(2) - (2)].fval); }
    break;

  case 64:
/* Line 664 of lalr1.cc  */
#line 277 "obj_parser.y"
    { (yyval.fval) = (yysemantic_stack_[(2) - (2)].fval); }
    break;

  case 66:
/* Line 664 of lalr1.cc  */
#line 281 "obj_parser.y"
    { (yyval.fval) = (yysemantic_stack_[(2) - (2)].fval); }
    break;

  case 68:
/* Line 664 of lalr1.cc  */
#line 285 "obj_parser.y"
    { (yyval.ival) = (yysemantic_stack_[(2) - (2)].ival); }
    break;

  case 70:
/* Line 664 of lalr1.cc  */
#line 289 "obj_parser.y"
    { (yyval.tex) = new obj::tex_map((yysemantic_stack_[(2) - (2)].sval)); }
    break;

  case 72:
/* Line 664 of lalr1.cc  */
#line 293 "obj_parser.y"
    { (yyval.tex) = new obj::tex_map((yysemantic_stack_[(2) - (2)].sval)); }
    break;

  case 74:
/* Line 664 of lalr1.cc  */
#line 297 "obj_parser.y"
    { (yyval.tex) = new obj::tex_map((yysemantic_stack_[(2) - (2)].sval)); }
    break;

  case 76:
/* Line 664 of lalr1.cc  */
#line 301 "obj_parser.y"
    { (yyval.tex) = new obj::tex_map((yysemantic_stack_[(2) - (2)].sval)); }
    break;

  case 79:
/* Line 664 of lalr1.cc  */
#line 306 "obj_parser.y"
    { (yyval.tex) = new obj::tex_map((yysemantic_stack_[(2) - (2)].sval)); }
    break;

  case 80:
/* Line 664 of lalr1.cc  */
#line 307 "obj_parser.y"
    { (yyval.tex) = new obj::tex_map((yysemantic_stack_[(2) - (2)].sval)); }
    break;

  case 83:
/* Line 664 of lalr1.cc  */
#line 312 "obj_parser.y"
    { (yyval.tex) = new obj::tex_map((yysemantic_stack_[(2) - (2)].sval)); }
    break;

  case 84:
/* Line 664 of lalr1.cc  */
#line 313 "obj_parser.y"
    { (yyval.tex) = new obj::tex_map((yysemantic_stack_[(2) - (2)].sval)); }
    break;

  case 86:
/* Line 664 of lalr1.cc  */
#line 317 "obj_parser.y"
    { (yyval.tex) = new obj::tex_map((yysemantic_stack_[(2) - (2)].sval)); }
    break;

  case 88:
/* Line 664 of lalr1.cc  */
#line 321 "obj_parser.y"
    { (yyval.tex) = new obj::tex_map((yysemantic_stack_[(2) - (2)].sval)); }
    break;

  case 90:
/* Line 664 of lalr1.cc  */
#line 325 "obj_parser.y"
    { (yyval.tex) = new obj::tex_map((yysemantic_stack_[(2) - (2)].sval)); }
    break;

  case 91:
/* Line 664 of lalr1.cc  */
#line 327 "obj_parser.y"
    { (yyval.color) = new obj::vec3((yysemantic_stack_[(4) - (2)].fval), (yysemantic_stack_[(4) - (3)].fval), (yysemantic_stack_[(4) - (4)].fval)); }
    break;

  case 93:
/* Line 664 of lalr1.cc  */
#line 331 "obj_parser.y"
    { (yyval.fval) = (yysemantic_stack_[(2) - (2)].fval); }
    break;


/* Line 664 of lalr1.cc  */
#line 824 "obj_parser.cpp"
      default:
        break;
      }

    /* User semantic actions sometimes alter yychar, and that requires
       that yytoken be updated with the new translation.  We take the
       approach of translating immediately before every use of yytoken.
       One alternative is translating here after every semantic action,
       but that translation would be missed if the semantic action
       invokes YYABORT, YYACCEPT, or YYERROR immediately after altering
       yychar.  In the case of YYABORT or YYACCEPT, an incorrect
       destructor might then be invoked immediately.  In the case of
       YYERROR, subsequent parser actions might lead to an incorrect
       destructor call or verbose syntax error message before the
       lookahead is translated.  */
    YY_SYMBOL_PRINT ("-> $$ =", yyr1_[yyn], &yyval, &yyloc);

    yypop_ (yylen);
    yylen = 0;
    YY_STACK_PRINT ();

    yysemantic_stack_.push (yyval);
    yylocation_stack_.push (yyloc);

    /* Shift the result of the reduction.  */
    yyn = yyr1_[yyn];
    yystate = yypgoto_[yyn - yyntokens_] + yystate_stack_[0];
    if (0 <= yystate && yystate <= yylast_
	&& yycheck_[yystate] == yystate_stack_[0])
      yystate = yytable_[yystate];
    else
      yystate = yydefgoto_[yyn - yyntokens_];
    goto yynewstate;

  /*------------------------------------.
  | yyerrlab -- here on detecting error |
  `------------------------------------*/
  yyerrlab:
    /* Make sure we have latest lookahead translation.  See comments at
       user semantic actions for why this is necessary.  */
    yytoken = yytranslate_ (yychar);

    /* If not already recovering from an error, report this error.  */
    if (!yyerrstatus_)
      {
	++yynerrs_;
	if (yychar == yyempty_)
	  yytoken = yyempty_;
	error (yylloc, yysyntax_error_ (yystate, yytoken));
      }

    yyerror_range[1] = yylloc;
    if (yyerrstatus_ == 3)
      {
        /* If just tried and failed to reuse lookahead token after an
           error, discard it.  */
        if (yychar <= yyeof_)
          {
            /* Return failure if at end of input.  */
            if (yychar == yyeof_)
              YYABORT;
          }
        else
          {
            yydestruct_ ("Error: discarding", yytoken, &yylval, &yylloc);
            yychar = yyempty_;
          }
      }

    /* Else will try to reuse lookahead token after shifting the error
       token.  */
    goto yyerrlab1;


  /*---------------------------------------------------.
  | 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.  */
    if (false)
      goto yyerrorlab;

    yyerror_range[1] = yylocation_stack_[yylen - 1];
    /* Do not reclaim the symbols of the rule which action triggered
       this YYERROR.  */
    yypop_ (yylen);
    yylen = 0;
    yystate = yystate_stack_[0];
    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 (!yy_pact_value_is_default_ (yyn))
	{
	  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 (yystate_stack_.height () == 1)
	  YYABORT;

	yyerror_range[1] = yylocation_stack_[0];
	yydestruct_ ("Error: popping",
		     yystos_[yystate],
		     &yysemantic_stack_[0], &yylocation_stack_[0]);
	yypop_ ();
	yystate = yystate_stack_[0];
	YY_STACK_PRINT ();
      }

    yyerror_range[2] = yylloc;
    // Using YYLLOC is tempting, but would change the location of
    // the lookahead.  YYLOC is available though.
    YYLLOC_DEFAULT (yyloc, yyerror_range, 2);
    yysemantic_stack_.push (yylval);
    yylocation_stack_.push (yyloc);

    /* Shift the error token.  */
    YY_SYMBOL_PRINT ("Shifting", yystos_[yyn],
		     &yysemantic_stack_[0], &yylocation_stack_[0]);

    yystate = yyn;
    goto yynewstate;

    /* Accept.  */
  yyacceptlab:
    yyresult = 0;
    goto yyreturn;

    /* Abort.  */
  yyabortlab:
    yyresult = 1;
    goto yyreturn;

  yyreturn:
    if (yychar != yyempty_)
      {
        /* Make sure we have latest lookahead translation.  See comments
           at user semantic actions for why this is necessary.  */
        yytoken = yytranslate_ (yychar);
        yydestruct_ ("Cleanup: discarding lookahead", yytoken, &yylval,
                     &yylloc);
      }

    /* Do not reclaim the symbols of the rule which action triggered
       this YYABORT or YYACCEPT.  */
    yypop_ (yylen);
    while (1 < yystate_stack_.height ())
      {
        yydestruct_ ("Cleanup: popping",
                     yystos_[yystate_stack_[0]],
                     &yysemantic_stack_[0],
                     &yylocation_stack_[0]);
        yypop_ ();
      }

    return yyresult;
    }
    catch (...)
      {
        YYCDEBUG << "Exception caught: cleaning lookahead and stack"
                 << std::endl;
        // Do not try to display the values of the reclaimed symbols,
        // as their printer might throw an exception.
        if (yychar != yyempty_)
          {
            /* Make sure we have latest lookahead translation.  See
               comments at user semantic actions for why this is
               necessary.  */
            yytoken = yytranslate_ (yychar);
            yydestruct_ (YY_NULL, yytoken, &yylval, &yylloc);
          }

        while (1 < yystate_stack_.height ())
          {
            yydestruct_ (YY_NULL,
                         yystos_[yystate_stack_[0]],
                         &yysemantic_stack_[0],
                         &yylocation_stack_[0]);
            yypop_ ();
          }
        throw;
      }
  }
Ejemplo n.º 6
0
  int
  Parser::parse ()
  {
    // State.
    int yyn;
    /// Length of the RHS of the rule being reduced.
    int yylen = 0;

    // Error handling.
    int yynerrs_ = 0;
    int yyerrstatus_ = 0;

    /// The lookahead symbol.
    symbol_type yyla;

    /// The return value of parse ().
    int yyresult;

    // FIXME: This shoud be completely indented.  It is not yet to
    // avoid gratuitous conflicts when merging into the master branch.
    try
      {
    YYCDEBUG << "Starting parse" << std::endl;


    /* Initialize the stack.  The initial state will be set in
       yynewstate, since the latter expects the semantical and the
       location values to have been already stored, initialize these
       stacks with a primary value.  */
    yystack_.clear ();
    yypush_ (YY_NULLPTR, 0, yyla);

    // A new symbol was pushed on the stack.
  yynewstate:
    YYCDEBUG << "Entering state " << yystack_[0].state << std::endl;

    // Accept?
    if (yystack_[0].state == yyfinal_)
      goto yyacceptlab;

    goto yybackup;

    // Backup.
  yybackup:

    // Try to take a decision without lookahead.
    yyn = yypact_[yystack_[0].state];
    if (yy_pact_value_is_default_ (yyn))
      goto yydefault;

    // Read a lookahead token.
    if (yyla.empty ())
      {
        YYCDEBUG << "Reading a token: ";
        try
          {
            yyla.type = yytranslate_ (yylex (&yyla.value));
          }
        catch (const syntax_error& yyexc)
          {
            error (yyexc);
            goto yyerrlab1;
          }
      }
    YY_SYMBOL_PRINT ("Next token is", yyla);

    /* If the proper action on seeing token YYLA.TYPE is to reduce or
       to detect an error, take that action.  */
    yyn += yyla.type_get ();
    if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yyla.type_get ())
      goto yydefault;

    // Reduce or error.
    yyn = yytable_[yyn];
    if (yyn <= 0)
      {
        if (yy_table_value_is_error_ (yyn))
          goto yyerrlab;
        yyn = -yyn;
        goto yyreduce;
      }

    // Count tokens shifted since error; after three, turn off error status.
    if (yyerrstatus_)
      --yyerrstatus_;

    // Shift the lookahead token.
    yypush_ ("Shifting", yyn, yyla);
    goto yynewstate;

  /*-----------------------------------------------------------.
  | yydefault -- do the default action for the current state.  |
  `-----------------------------------------------------------*/
  yydefault:
    yyn = yydefact_[yystack_[0].state];
    if (yyn == 0)
      goto yyerrlab;
    goto yyreduce;

  /*-----------------------------.
  | yyreduce -- Do a reduction.  |
  `-----------------------------*/
  yyreduce:
    yylen = yyr2_[yyn];
    {
      stack_symbol_type yylhs;
      yylhs.state = yy_lr_goto_state_(yystack_[yylen].state, yyr1_[yyn]);
      /* If YYLEN is nonzero, implement the default value of the
         action: '$$ = $1'.  Otherwise, use the top of the stack.

         Otherwise, the following line sets YYLHS.VALUE to garbage.
         This behavior is undocumented and Bison users should not rely
         upon it.  */
      if (yylen)
        yylhs.value = yystack_[yylen - 1].value;
      else
        yylhs.value = yystack_[0].value;


      // Perform the reduction.
      YY_REDUCE_PRINT (yyn);
      try
        {
          switch (yyn)
            {
  case 4:
#line 55 "src/grammar/parser.yy" // lalr1.cc:859
    { driver.add_upper(); }
#line 572 "src/frontend/parser.tab.cpp" // lalr1.cc:859
    break;

  case 5:
#line 56 "src/grammar/parser.yy" // lalr1.cc:859
    { driver.add_lower(); }
#line 578 "src/frontend/parser.tab.cpp" // lalr1.cc:859
    break;

  case 6:
#line 57 "src/grammar/parser.yy" // lalr1.cc:859
    { driver.add_word( *(yystack_[0].value.sval) ); }
#line 584 "src/frontend/parser.tab.cpp" // lalr1.cc:859
    break;

  case 7:
#line 58 "src/grammar/parser.yy" // lalr1.cc:859
    { driver.add_newline(); }
#line 590 "src/frontend/parser.tab.cpp" // lalr1.cc:859
    break;

  case 8:
#line 59 "src/grammar/parser.yy" // lalr1.cc:859
    { driver.add_char(); }
#line 596 "src/frontend/parser.tab.cpp" // lalr1.cc:859
    break;


#line 600 "src/frontend/parser.tab.cpp" // lalr1.cc:859
            default:
              break;
            }
        }
      catch (const syntax_error& yyexc)
        {
          error (yyexc);
          YYERROR;
        }
      YY_SYMBOL_PRINT ("-> $$ =", yylhs);
      yypop_ (yylen);
      yylen = 0;
      YY_STACK_PRINT ();

      // Shift the result of the reduction.
      yypush_ (YY_NULLPTR, yylhs);
    }
    goto yynewstate;

  /*--------------------------------------.
  | yyerrlab -- here on detecting error.  |
  `--------------------------------------*/
  yyerrlab:
    // If not already recovering from an error, report this error.
    if (!yyerrstatus_)
      {
        ++yynerrs_;
        error (yysyntax_error_ (yystack_[0].state, yyla));
      }


    if (yyerrstatus_ == 3)
      {
        /* If just tried and failed to reuse lookahead token after an
           error, discard it.  */

        // Return failure if at end of input.
        if (yyla.type_get () == yyeof_)
          YYABORT;
        else if (!yyla.empty ())
          {
            yy_destroy_ ("Error: discarding", yyla);
            yyla.clear ();
          }
      }

    // Else will try to reuse lookahead token after shifting the error token.
    goto yyerrlab1;


  /*---------------------------------------------------.
  | 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.  */
    if (false)
      goto yyerrorlab;
    /* Do not reclaim the symbols of the rule whose action triggered
       this YYERROR.  */
    yypop_ (yylen);
    yylen = 0;
    goto yyerrlab1;

  /*-------------------------------------------------------------.
  | yyerrlab1 -- common code for both syntax error and YYERROR.  |
  `-------------------------------------------------------------*/
  yyerrlab1:
    yyerrstatus_ = 3;   // Each real token shifted decrements this.
    {
      stack_symbol_type error_token;
      for (;;)
        {
          yyn = yypact_[yystack_[0].state];
          if (!yy_pact_value_is_default_ (yyn))
            {
              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 (yystack_.size () == 1)
            YYABORT;

          yy_destroy_ ("Error: popping", yystack_[0]);
          yypop_ ();
          YY_STACK_PRINT ();
        }


      // Shift the error token.
      error_token.state = yyn;
      yypush_ ("Shifting", error_token);
    }
    goto yynewstate;

    // Accept.
  yyacceptlab:
    yyresult = 0;
    goto yyreturn;

    // Abort.
  yyabortlab:
    yyresult = 1;
    goto yyreturn;

  yyreturn:
    if (!yyla.empty ())
      yy_destroy_ ("Cleanup: discarding lookahead", yyla);

    /* Do not reclaim the symbols of the rule whose action triggered
       this YYABORT or YYACCEPT.  */
    yypop_ (yylen);
    while (1 < yystack_.size ())
      {
        yy_destroy_ ("Cleanup: popping", yystack_[0]);
        yypop_ ();
      }

    return yyresult;
  }
    catch (...)
      {
        YYCDEBUG << "Exception caught: cleaning lookahead and stack"
                 << std::endl;
        // Do not try to display the values of the reclaimed symbols,
        // as their printer might throw an exception.
        if (!yyla.empty ())
          yy_destroy_ (YY_NULLPTR, yyla);

        while (1 < yystack_.size ())
          {
            yy_destroy_ (YY_NULLPTR, yystack_[0]);
            yypop_ ();
          }
        throw;
      }
  }
Ejemplo n.º 7
0
  int
  Parser::parse ()
  {
    /// Whether yyla contains a lookahead.
    bool yyempty = true;

    // State.
    int yyn;
    /// Length of the RHS of the rule being reduced.
    int yylen = 0;

    // Error handling.
    int yynerrs_ = 0;
    int yyerrstatus_ = 0;

    /// The lookahead symbol.
    symbol_type yyla;

    /// The locations where the error started and ended.
    stack_symbol_type yyerror_range[3];

    /// The return value of parse ().
    int yyresult;

    // FIXME: This shoud be completely indented.  It is not yet to
    // avoid gratuitous conflicts when merging into the master branch.
    try
      {
    YYCDEBUG << "Starting parse" << std::endl;


    // User initialization code.
    #line 36 "parser.yy" // lalr1.cc:725
{
    // initialize the initial location object
    yyla.location.begin.filename = yyla.location.end.filename = &driver.streamname;
}

#line 501 "parser.cpp" // lalr1.cc:725

    /* Initialize the stack.  The initial state will be set in
       yynewstate, since the latter expects the semantical and the
       location values to have been already stored, initialize these
       stacks with a primary value.  */
    yystack_.clear ();
    yypush_ (YY_NULLPTR, 0, yyla);

    // A new symbol was pushed on the stack.
  yynewstate:
    YYCDEBUG << "Entering state " << yystack_[0].state << std::endl;

    // Accept?
    if (yystack_[0].state == yyfinal_)
      goto yyacceptlab;

    goto yybackup;

    // Backup.
  yybackup:

    // Try to take a decision without lookahead.
    yyn = yypact_[yystack_[0].state];
    if (yy_pact_value_is_default_ (yyn))
      goto yydefault;

    // Read a lookahead token.
    if (yyempty)
      {
        YYCDEBUG << "Reading a token: ";
        try
          {
            yyla.type = yytranslate_ (yylex (&yyla.value, &yyla.location));
          }
        catch (const syntax_error& yyexc)
          {
            error (yyexc);
            goto yyerrlab1;
          }
        yyempty = false;
      }
    YY_SYMBOL_PRINT ("Next token is", yyla);

    /* If the proper action on seeing token YYLA.TYPE is to reduce or
       to detect an error, take that action.  */
    yyn += yyla.type_get ();
    if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yyla.type_get ())
      goto yydefault;

    // Reduce or error.
    yyn = yytable_[yyn];
    if (yyn <= 0)
      {
        if (yy_table_value_is_error_ (yyn))
          goto yyerrlab;
        yyn = -yyn;
        goto yyreduce;
      }

    // Discard the token being shifted.
    yyempty = true;

    // Count tokens shifted since error; after three, turn off error status.
    if (yyerrstatus_)
      --yyerrstatus_;

    // Shift the lookahead token.
    yypush_ ("Shifting", yyn, yyla);
    goto yynewstate;

  /*-----------------------------------------------------------.
  | yydefault -- do the default action for the current state.  |
  `-----------------------------------------------------------*/
  yydefault:
    yyn = yydefact_[yystack_[0].state];
    if (yyn == 0)
      goto yyerrlab;
    goto yyreduce;

  /*-----------------------------.
  | yyreduce -- Do a reduction.  |
  `-----------------------------*/
  yyreduce:
    yylen = yyr2_[yyn];
    {
      stack_symbol_type yylhs;
      yylhs.state = yy_lr_goto_state_(yystack_[yylen].state, yyr1_[yyn]);
      /* If YYLEN is nonzero, implement the default value of the
         action: '$$ = $1'.  Otherwise, use the top of the stack.

         Otherwise, the following line sets YYLHS.VALUE to garbage.
         This behavior is undocumented and Bison users should not rely
         upon it.  */
      if (yylen)
        yylhs.value = yystack_[yylen - 1].value;
      else
        yylhs.value = yystack_[0].value;

      // Compute the default @$.
      {
        slice<stack_symbol_type, stack_type> slice (yystack_, yylen);
        YYLLOC_DEFAULT (yylhs.location, slice, yylen);
      }

      // Perform the reduction.
      YY_REDUCE_PRINT (yyn);
      try
        {
          switch (yyn)
            {
  case 2:
#line 88 "parser.yy" // lalr1.cc:847
    {
          (yylhs.value.querynode) = new query_true();
        }
#line 617 "parser.cpp" // lalr1.cc:847
    break;

  case 3:
#line 92 "parser.yy" // lalr1.cc:847
    {
          (yylhs.value.querynode) = new query_true();
        }
#line 625 "parser.cpp" // lalr1.cc:847
    break;

  case 4:
#line 97 "parser.yy" // lalr1.cc:847
    {
              (yylhs.value.stringVal) = (yystack_[0].value.stringVal);
            }
#line 633 "parser.cpp" // lalr1.cc:847
    break;

  case 5:
#line 102 "parser.yy" // lalr1.cc:847
    {
              (yylhs.value.stringVal) = (yystack_[0].value.stringVal);
            }
#line 641 "parser.cpp" // lalr1.cc:847
    break;

  case 6:
#line 106 "parser.yy" // lalr1.cc:847
    {
              (yylhs.value.stringVal) = (yystack_[0].value.stringVal);
            }
#line 649 "parser.cpp" // lalr1.cc:847
    break;

  case 7:
#line 110 "parser.yy" // lalr1.cc:847
    {
              (yylhs.value.stringVal) = (yystack_[0].value.stringVal);
            }
#line 657 "parser.cpp" // lalr1.cc:847
    break;

  case 8:
#line 114 "parser.yy" // lalr1.cc:847
    {
              (yylhs.value.stringVal) = (yystack_[0].value.stringVal);
            }
#line 665 "parser.cpp" // lalr1.cc:847
    break;

  case 9:
#line 118 "parser.yy" // lalr1.cc:847
    {
              (yylhs.value.stringVal) = (yystack_[0].value.stringVal);
            }
#line 673 "parser.cpp" // lalr1.cc:847
    break;

  case 10:
#line 123 "parser.yy" // lalr1.cc:847
    {
            delete (yystack_[1].value.stringVal);
            (yylhs.value.querynode) = new query_tagged((yystack_[0].value.stringVal));
          }
#line 682 "parser.cpp" // lalr1.cc:847
    break;

  case 11:
#line 128 "parser.yy" // lalr1.cc:847
    {
            (yylhs.value.querynode) = new query_tagged((yystack_[0].value.stringVal));
          }
#line 690 "parser.cpp" // lalr1.cc:847
    break;

  case 12:
#line 132 "parser.yy" // lalr1.cc:847
    {
            delete (yystack_[1].value.stringVal);
            (yylhs.value.querynode) = new query_field((yystack_[2].value.unquotedstringVal));
          }
#line 699 "parser.cpp" // lalr1.cc:847
    break;

  case 13:
#line 138 "parser.yy" // lalr1.cc:847
    {
            (yylhs.value.querynode) = new query_field((yystack_[2].value.unquotedstringVal), (yystack_[0].value.stringVal), (yystack_[1].value.stringVal));
          }
#line 707 "parser.cpp" // lalr1.cc:847
    break;

  case 14:
#line 142 "parser.yy" // lalr1.cc:847
    {
            (yylhs.value.querynode) = new query_field((yystack_[2].value.unquotedstringVal), (yystack_[0].value.integerVal), (yystack_[1].value.stringVal));
          }
#line 715 "parser.cpp" // lalr1.cc:847
    break;

  case 15:
#line 146 "parser.yy" // lalr1.cc:847
    {
            (yylhs.value.querynode) = new query_field((yystack_[2].value.unquotedstringVal), (yystack_[0].value.doubleVal), (yystack_[1].value.stringVal));
          }
#line 723 "parser.cpp" // lalr1.cc:847
    break;

  case 16:
#line 151 "parser.yy" // lalr1.cc:847
    {
          (yylhs.value.querynode) = (yystack_[1].value.querynode);
        }
#line 731 "parser.cpp" // lalr1.cc:847
    break;

  case 17:
#line 155 "parser.yy" // lalr1.cc:847
    {
          (yylhs.value.querynode) = new query_and((yystack_[2].value.querynode), (yystack_[0].value.querynode));
        }
#line 739 "parser.cpp" // lalr1.cc:847
    break;

  case 18:
#line 159 "parser.yy" // lalr1.cc:847
    {
          (yylhs.value.querynode) = new query_or((yystack_[2].value.querynode), (yystack_[0].value.querynode));
        }
#line 747 "parser.cpp" // lalr1.cc:847
    break;

  case 19:
#line 163 "parser.yy" // lalr1.cc:847
    {
          (yylhs.value.querynode) = new query_not((yystack_[0].value.querynode));
        }
#line 755 "parser.cpp" // lalr1.cc:847
    break;

  case 20:
#line 167 "parser.yy" // lalr1.cc:847
    {
          (yylhs.value.querynode) = (yystack_[0].value.querynode);
        }
#line 763 "parser.cpp" // lalr1.cc:847
    break;

  case 21:
#line 172 "parser.yy" // lalr1.cc:847
    {
            driver.query.set_expression((yystack_[0].value.querynode));
          }
#line 771 "parser.cpp" // lalr1.cc:847
    break;

  case 22:
#line 176 "parser.yy" // lalr1.cc:847
    {
            driver.query.set_expression((yystack_[0].value.querynode));
          }
#line 779 "parser.cpp" // lalr1.cc:847
    break;


#line 783 "parser.cpp" // lalr1.cc:847
            default:
              break;
            }
        }
      catch (const syntax_error& yyexc)
        {
          error (yyexc);
          YYERROR;
        }
      YY_SYMBOL_PRINT ("-> $$ =", yylhs);
      yypop_ (yylen);
      yylen = 0;
      YY_STACK_PRINT ();

      // Shift the result of the reduction.
      yypush_ (YY_NULLPTR, yylhs);
    }
    goto yynewstate;

  /*--------------------------------------.
  | yyerrlab -- here on detecting error.  |
  `--------------------------------------*/
  yyerrlab:
    // If not already recovering from an error, report this error.
    if (!yyerrstatus_)
      {
        ++yynerrs_;
        error (yyla.location, yysyntax_error_ (yystack_[0].state,
                                           yyempty ? yyempty_ : yyla.type_get ()));
      }


    yyerror_range[1].location = yyla.location;
    if (yyerrstatus_ == 3)
      {
        /* If just tried and failed to reuse lookahead token after an
           error, discard it.  */

        // Return failure if at end of input.
        if (yyla.type_get () == yyeof_)
          YYABORT;
        else if (!yyempty)
          {
            yy_destroy_ ("Error: discarding", yyla);
            yyempty = true;
          }
      }

    // Else will try to reuse lookahead token after shifting the error token.
    goto yyerrlab1;


  /*---------------------------------------------------.
  | 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.  */
    if (false)
      goto yyerrorlab;
    yyerror_range[1].location = yystack_[yylen - 1].location;
    /* Do not reclaim the symbols of the rule whose action triggered
       this YYERROR.  */
    yypop_ (yylen);
    yylen = 0;
    goto yyerrlab1;

  /*-------------------------------------------------------------.
  | yyerrlab1 -- common code for both syntax error and YYERROR.  |
  `-------------------------------------------------------------*/
  yyerrlab1:
    yyerrstatus_ = 3;   // Each real token shifted decrements this.
    {
      stack_symbol_type error_token;
      for (;;)
        {
          yyn = yypact_[yystack_[0].state];
          if (!yy_pact_value_is_default_ (yyn))
            {
              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 (yystack_.size () == 1)
            YYABORT;

          yyerror_range[1].location = yystack_[0].location;
          yy_destroy_ ("Error: popping", yystack_[0]);
          yypop_ ();
          YY_STACK_PRINT ();
        }

      yyerror_range[2].location = yyla.location;
      YYLLOC_DEFAULT (error_token.location, yyerror_range, 2);

      // Shift the error token.
      error_token.state = yyn;
      yypush_ ("Shifting", error_token);
    }
    goto yynewstate;

    // Accept.
  yyacceptlab:
    yyresult = 0;
    goto yyreturn;

    // Abort.
  yyabortlab:
    yyresult = 1;
    goto yyreturn;

  yyreturn:
    if (!yyempty)
      yy_destroy_ ("Cleanup: discarding lookahead", yyla);

    /* Do not reclaim the symbols of the rule whose action triggered
       this YYABORT or YYACCEPT.  */
    yypop_ (yylen);
    while (1 < yystack_.size ())
      {
        yy_destroy_ ("Cleanup: popping", yystack_[0]);
        yypop_ ();
      }

    return yyresult;
  }
    catch (...)
      {
        YYCDEBUG << "Exception caught: cleaning lookahead and stack"
                 << std::endl;
        // Do not try to display the values of the reclaimed symbols,
        // as their printer might throw an exception.
        if (!yyempty)
          yy_destroy_ (YY_NULLPTR, yyla);

        while (1 < yystack_.size ())
          {
            yy_destroy_ (YY_NULLPTR, yystack_[0]);
            yypop_ ();
          }
        throw;
      }
  }
Ejemplo n.º 8
0
  int
  Parser::parse ()
  {
    /// Lookahead and lookahead in internal form.
    int yychar = yyempty_;
    int yytoken = 0;

    /* State.  */
    int yyn;
    int yylen = 0;
    int yystate = 0;

    /* Error handling.  */
    int yynerrs_ = 0;
    int yyerrstatus_ = 0;

    /// Semantic value of the lookahead.
    semantic_type yylval;
    /// Location of the lookahead.
    location_type yylloc;
    /// The locations where the error started and ended.
    location_type yyerror_range[3];

    /// $$.
    semantic_type yyval;
    /// @$.
    location_type yyloc;

    int yyresult;

    YYCDEBUG << "Starting parse" << std::endl;


    /* User initialization code.  */
    
/* Line 565 of lalr1.cc  */
#line 36 "parser.yy"
{
    // initialize the initial location object
    yylloc.begin.filename = yylloc.end.filename = &driver.streamname;
}

/* Line 565 of lalr1.cc  */
#line 352 "parser.cpp"

    /* Initialize the stacks.  The initial state will be pushed in
       yynewstate, since the latter expects the semantical and the
       location values to have been already stored, initialize these
       stacks with a primary value.  */
    yystate_stack_ = state_stack_type (0);
    yysemantic_stack_ = semantic_stack_type (0);
    yylocation_stack_ = location_stack_type (0);
    yysemantic_stack_.push (yylval);
    yylocation_stack_.push (yylloc);

    /* New state.  */
  yynewstate:
    yystate_stack_.push (yystate);
    YYCDEBUG << "Entering state " << yystate << std::endl;

    /* Accept?  */
    if (yystate == yyfinal_)
      goto yyacceptlab;

    goto yybackup;

    /* Backup.  */
  yybackup:

    /* Try to take a decision without lookahead.  */
    yyn = yypact_[yystate];
    if (yy_pact_value_is_default_ (yyn))
      goto yydefault;

    /* Read a lookahead token.  */
    if (yychar == yyempty_)
      {
	YYCDEBUG << "Reading a token: ";
	yychar = yylex (&yylval, &yylloc);
      }


    /* Convert token to internal form.  */
    if (yychar <= yyeof_)
      {
	yychar = yytoken = yyeof_;
	YYCDEBUG << "Now at end of input." << std::endl;
      }
    else
      {
	yytoken = yytranslate_ (yychar);
	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;

    /* Reduce or error.  */
    yyn = yytable_[yyn];
    if (yyn <= 0)
      {
	if (yy_table_value_is_error_ (yyn))
	  goto yyerrlab;
	yyn = -yyn;
	goto yyreduce;
      }

    /* Shift the lookahead token.  */
    YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);

    /* Discard the token being shifted.  */
    yychar = yyempty_;

    yysemantic_stack_.push (yylval);
    yylocation_stack_.push (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:
    yylen = yyr2_[yyn];
    /* If YYLEN is nonzero, implement the default value of the action:
       `$$ = $1'.  Otherwise, use the top of the stack.

       Otherwise, the following line sets YYVAL to garbage.
       This behavior is undocumented and Bison
       users should not rely upon it.  */
    if (yylen)
      yyval = yysemantic_stack_[yylen - 1];
    else
      yyval = yysemantic_stack_[0];

    {
      slice<location_type, location_stack_type> slice (yylocation_stack_, yylen);
      YYLLOC_DEFAULT (yyloc, slice, yylen);
    }
    YY_REDUCE_PRINT (yyn);
    switch (yyn)
      {
	  case 2:

/* Line 690 of lalr1.cc  */
#line 88 "parser.yy"
    {
          (yyval.querynode) = new query_true();
        }
    break;

  case 3:

/* Line 690 of lalr1.cc  */
#line 92 "parser.yy"
    {
          (yyval.querynode) = new query_true();
        }
    break;

  case 4:

/* Line 690 of lalr1.cc  */
#line 97 "parser.yy"
    {
              (yyval.stringVal) = (yysemantic_stack_[(1) - (1)].stringVal);
            }
    break;

  case 5:

/* Line 690 of lalr1.cc  */
#line 102 "parser.yy"
    {
              (yyval.stringVal) = (yysemantic_stack_[(1) - (1)].stringVal);
            }
    break;

  case 6:

/* Line 690 of lalr1.cc  */
#line 106 "parser.yy"
    {
              (yyval.stringVal) = (yysemantic_stack_[(1) - (1)].stringVal);
            }
    break;

  case 7:

/* Line 690 of lalr1.cc  */
#line 110 "parser.yy"
    {
              (yyval.stringVal) = (yysemantic_stack_[(1) - (1)].stringVal);
            }
    break;

  case 8:

/* Line 690 of lalr1.cc  */
#line 114 "parser.yy"
    {
              (yyval.stringVal) = (yysemantic_stack_[(1) - (1)].stringVal);
            }
    break;

  case 9:

/* Line 690 of lalr1.cc  */
#line 118 "parser.yy"
    {
              (yyval.stringVal) = (yysemantic_stack_[(1) - (1)].stringVal);
            }
    break;

  case 10:

/* Line 690 of lalr1.cc  */
#line 123 "parser.yy"
    {
            delete (yysemantic_stack_[(3) - (2)].stringVal);
            (yyval.querynode) = new query_tagged((yysemantic_stack_[(3) - (3)].stringVal));
          }
    break;

  case 11:

/* Line 690 of lalr1.cc  */
#line 128 "parser.yy"
    {
            delete (yysemantic_stack_[(3) - (2)].stringVal);
            (yyval.querynode) = new query_field((yysemantic_stack_[(3) - (1)].unquotedstringVal));
          }
    break;

  case 12:

/* Line 690 of lalr1.cc  */
#line 134 "parser.yy"
    {
            (yyval.querynode) = new query_field((yysemantic_stack_[(3) - (1)].unquotedstringVal), (yysemantic_stack_[(3) - (3)].stringVal), (yysemantic_stack_[(3) - (2)].stringVal));
          }
    break;

  case 13:

/* Line 690 of lalr1.cc  */
#line 138 "parser.yy"
    {
            (yyval.querynode) = new query_field((yysemantic_stack_[(3) - (1)].unquotedstringVal), (yysemantic_stack_[(3) - (3)].integerVal), (yysemantic_stack_[(3) - (2)].stringVal));
          }
    break;

  case 14:

/* Line 690 of lalr1.cc  */
#line 142 "parser.yy"
    {
            (yyval.querynode) = new query_field((yysemantic_stack_[(3) - (1)].unquotedstringVal), (yysemantic_stack_[(3) - (3)].doubleVal), (yysemantic_stack_[(3) - (2)].stringVal));
          }
    break;

  case 15:

/* Line 690 of lalr1.cc  */
#line 147 "parser.yy"
    {
          (yyval.querynode) = (yysemantic_stack_[(3) - (2)].querynode);
        }
    break;

  case 16:

/* Line 690 of lalr1.cc  */
#line 151 "parser.yy"
    {
          (yyval.querynode) = new query_and((yysemantic_stack_[(3) - (1)].querynode), (yysemantic_stack_[(3) - (3)].querynode));
        }
    break;

  case 17:

/* Line 690 of lalr1.cc  */
#line 155 "parser.yy"
    {
          (yyval.querynode) = new query_or((yysemantic_stack_[(3) - (1)].querynode), (yysemantic_stack_[(3) - (3)].querynode));
        }
    break;

  case 18:

/* Line 690 of lalr1.cc  */
#line 159 "parser.yy"
    {
          (yyval.querynode) = new query_not((yysemantic_stack_[(2) - (2)].querynode));
        }
    break;

  case 19:

/* Line 690 of lalr1.cc  */
#line 163 "parser.yy"
    {
          (yyval.querynode) = (yysemantic_stack_[(1) - (1)].querynode);
        }
    break;

  case 20:

/* Line 690 of lalr1.cc  */
#line 168 "parser.yy"
    {
            driver.query.set_expression((yysemantic_stack_[(1) - (1)].querynode));
          }
    break;

  case 21:

/* Line 690 of lalr1.cc  */
#line 172 "parser.yy"
    {
            driver.query.set_expression((yysemantic_stack_[(1) - (1)].querynode));
          }
    break;



/* Line 690 of lalr1.cc  */
#line 653 "parser.cpp"
	default:
          break;
      }
    /* User semantic actions sometimes alter yychar, and that requires
       that yytoken be updated with the new translation.  We take the
       approach of translating immediately before every use of yytoken.
       One alternative is translating here after every semantic action,
       but that translation would be missed if the semantic action
       invokes YYABORT, YYACCEPT, or YYERROR immediately after altering
       yychar.  In the case of YYABORT or YYACCEPT, an incorrect
       destructor might then be invoked immediately.  In the case of
       YYERROR, subsequent parser actions might lead to an incorrect
       destructor call or verbose syntax error message before the
       lookahead is translated.  */
    YY_SYMBOL_PRINT ("-> $$ =", yyr1_[yyn], &yyval, &yyloc);

    yypop_ (yylen);
    yylen = 0;
    YY_STACK_PRINT ();

    yysemantic_stack_.push (yyval);
    yylocation_stack_.push (yyloc);

    /* Shift the result of the reduction.  */
    yyn = yyr1_[yyn];
    yystate = yypgoto_[yyn - yyntokens_] + yystate_stack_[0];
    if (0 <= yystate && yystate <= yylast_
	&& yycheck_[yystate] == yystate_stack_[0])
      yystate = yytable_[yystate];
    else
      yystate = yydefgoto_[yyn - yyntokens_];
    goto yynewstate;

  /*------------------------------------.
  | yyerrlab -- here on detecting error |
  `------------------------------------*/
  yyerrlab:
    /* Make sure we have latest lookahead translation.  See comments at
       user semantic actions for why this is necessary.  */
    yytoken = yytranslate_ (yychar);

    /* If not already recovering from an error, report this error.  */
    if (!yyerrstatus_)
      {
	++yynerrs_;
	if (yychar == yyempty_)
	  yytoken = yyempty_;
	error (yylloc, yysyntax_error_ (yystate, yytoken));
      }

    yyerror_range[1] = yylloc;
    if (yyerrstatus_ == 3)
      {
	/* If just tried and failed to reuse lookahead token after an
	 error, discard it.  */

	if (yychar <= yyeof_)
	  {
	  /* Return failure if at end of input.  */
	  if (yychar == yyeof_)
	    YYABORT;
	  }
	else
	  {
	    yydestruct_ ("Error: discarding", yytoken, &yylval, &yylloc);
	    yychar = yyempty_;
	  }
      }

    /* Else will try to reuse lookahead token after shifting the error
       token.  */
    goto yyerrlab1;


  /*---------------------------------------------------.
  | 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.  */
    if (false)
      goto yyerrorlab;

    yyerror_range[1] = yylocation_stack_[yylen - 1];
    /* Do not reclaim the symbols of the rule which action triggered
       this YYERROR.  */
    yypop_ (yylen);
    yylen = 0;
    yystate = yystate_stack_[0];
    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 (!yy_pact_value_is_default_ (yyn))
	{
	  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 (yystate_stack_.height () == 1)
	YYABORT;

	yyerror_range[1] = yylocation_stack_[0];
	yydestruct_ ("Error: popping",
		     yystos_[yystate],
		     &yysemantic_stack_[0], &yylocation_stack_[0]);
	yypop_ ();
	yystate = yystate_stack_[0];
	YY_STACK_PRINT ();
      }

    yyerror_range[2] = yylloc;
    // Using YYLLOC is tempting, but would change the location of
    // the lookahead.  YYLOC is available though.
    YYLLOC_DEFAULT (yyloc, yyerror_range, 2);
    yysemantic_stack_.push (yylval);
    yylocation_stack_.push (yyloc);

    /* Shift the error token.  */
    YY_SYMBOL_PRINT ("Shifting", yystos_[yyn],
		     &yysemantic_stack_[0], &yylocation_stack_[0]);

    yystate = yyn;
    goto yynewstate;

    /* Accept.  */
  yyacceptlab:
    yyresult = 0;
    goto yyreturn;

    /* Abort.  */
  yyabortlab:
    yyresult = 1;
    goto yyreturn;

  yyreturn:
    if (yychar != yyempty_)
      {
        /* Make sure we have latest lookahead translation.  See comments
           at user semantic actions for why this is necessary.  */
        yytoken = yytranslate_ (yychar);
        yydestruct_ ("Cleanup: discarding lookahead", yytoken, &yylval,
                     &yylloc);
      }

    /* Do not reclaim the symbols of the rule which action triggered
       this YYABORT or YYACCEPT.  */
    yypop_ (yylen);
    while (yystate_stack_.height () != 1)
      {
	yydestruct_ ("Cleanup: popping",
		   yystos_[yystate_stack_[0]],
		   &yysemantic_stack_[0],
		   &yylocation_stack_[0]);
	yypop_ ();
      }

    return yyresult;
  }