/*
 File: rhs_component.cpp
 Date and Time: Fri Jan 30 18:55:22 2015 
*/
#include "rhs_component.h"
using namespace NS_yacco2_T_enum;// enumerate
using namespace NS_yacco2_err_symbols;// error symbols
using namespace NS_yacco2_k_symbols;// lrk 
using namespace NS_yacco2_terminals;// terminals
using namespace NS_yacco2_characters;// rc 
using namespace yacco2;// yacco2 library
using namespace NS_rhs_component;// grammar's ns
// first set terminals
fsm_rules_reuse_table_type::fsm_rules_reuse_table_type(){
 no_rules_entries_ = 1;
 per_rule_s_table_[0] =  new Per_rule_s_reuse_table();
}
  Crhs_component::
  Crhs_component()
    :yacco2::CAbs_fsm
      ("rhs_component.lex"
      ,"1.0"
      ,"24 mar 2004"
      ,true
      ,"Subule's individual component recognizer except eosubrule."
      ,"Fri Jan 30 18:55:22 2015 "
      ,S1_Crhs_component){
    
  }
 
Crhs_component::~Crhs_component(){

  for(int x = 0;x < 1;++x){
   ///delete fsm_rules_reuse_table.per_rule_s_table_[x];
  }
} 

  bool Crhs_component::failed(){
      return false;
  }
  void Crhs_component::op(){
}
int Crhs_component::rhs_to_rules_mapping_[9] = {
 -1
 ,0 // subrule 1 for rule 1
 ,0 // subrule 2 for rule 1
 ,0 // subrule 3 for rule 1
 ,0 // subrule 4 for rule 1
 ,0 // subrule 5 for rule 1
 ,0 // subrule 6 for rule 1
 ,0 // subrule 7 for rule 1
 ,0 // subrule 8 for rule 1
}; 

      void Crhs_component::fnd_T_of_chr_str(const char* Str,yacco2::CAbs_lr1_sym* Tok){
        T_sym_tbl_report_card report_card;
        using namespace yacco2_stbl;
        find_sym_in_stbl(report_card,*Str);
        if(report_card.action_ == T_sym_tbl_report_card::not_fnd){
          CAbs_lr1_sym* sym = new Err_subrule_use_undefined_T;
          sym->set_rc(*parser__->start_token__,__FILE__,__LINE__);
          RSVP_FSM(sym);
          parser__->set_stop_parse(true); 
          return; 
        }
        if(report_card.tbl_entry_->type_ != table_entry::terminal){
          CAbs_lr1_sym* sym = new Err_not_T_or_R_in_subrule_expr;
          sym->set_rc(*parser__->start_token__,__FILE__,__LINE__);
          RSVP_FSM(sym);
          parser__->set_stop_parse(true); 
          return; 
        }
		report_card.tbl_entry_->used_ = true;
        CAbs_lr1_sym* sym = report_card.tbl_entry_->symbol_;
        T_in_stbl* T = (T_in_stbl*)sym;
        refered_T* rT = new refered_T(*T);
        rT->set_rc(*Tok,__FILE__,__LINE__);
        
        T->add_T_into_xref(*rT);

        RSVP_FSM(T);
        parser__->set_stop_parse(true);  
      }
  
yacco2::THR _YACCO2_CALL_TYPE
NS_rhs_component::AR_Rrhs_component(yacco2::Parser* Caller_pp){
 yacco2::KCHARP ar_name = "AR_Rrhs_component";
#include "war_begin_code.h"
 
	using namespace NS_yacco2_T_enum;
          for(i=1;i<=ie;++i){
	     if(Caller_pp->pp_accept_queue__[i].accept_token__->enumerated_id__ 
                == NS_yacco2_T_enum::T_Enum::T_T_in_stbl_){
	        goto arbitrated_parameter;
             }
	  }
          for(i=1;i<=ie;++i){
	     if(Caller_pp->pp_accept_queue__[i].accept_token__->enumerated_id__ 
                == NS_yacco2_T_enum::T_Enum::T_rule_in_stbl_){
	        goto arbitrated_parameter;
             }
	  }
           for(i=1;i<=ie;++i){
	     if(Caller_pp->pp_accept_queue__[i].accept_token__->enumerated_id__ 
                == NS_yacco2_T_enum::T_Enum::T_T_identifier_){
	        goto arbitrated_parameter;
             }
	  }

          for(i=1;i<=ie;++i){
	     if(Caller_pp->pp_accept_queue__[i].accept_token__->enumerated_id__ 
                == NS_yacco2_T_enum::T_Enum::T_T_c_string_){
	        goto arbitrated_parameter;
             }
	  }
           for(i=1;i<=ie;++i){
	     if(Caller_pp->pp_accept_queue__[i].accept_token__->enumerated_id__ 
                == NS_yacco2_T_enum::T_Enum::T_T_cweb_marker_){
	        goto arbitrated_parameter;
             }
	  }          
          for(i=1;i<=ie;++i){
	     if(Caller_pp->pp_accept_queue__[i].accept_token__->enumerated_id__ 
                == NS_yacco2_T_enum::T_Enum::T_kw_in_stbl_){
	        goto arbitrated_parameter;
             }
	  }
          for(i=1;i<=ie;++i){
	     if(Caller_pp->pp_accept_queue__[i].accept_token__->enumerated_id__ 
                == NS_yacco2_T_enum::T_Enum::T_T_unquoted_string_){
	        goto arbitrated_parameter;
             }
	  }
  
#include "war_end_code.h"
}

Rrhs_component::Rrhs_component(yacco2::Parser* P)
 :CAbs_lr1_sym
  ("Rrhs_component",0,Crhs_component::R_Rrhs_component_,P,false,false){
}

void Rrhs_component::sr1(){
  struct SF{
   LR1_parallel_operator* p1__;
   State* s1__;
   bool abort1__;
   Rule_s_reuse_entry* rule_s_reuse_entry1__;
   T_identifier* p2__;
   State* s2__;
   bool abort2__;
   Rule_s_reuse_entry* rule_s_reuse_entry2__;
  };
  SF* sf = (SF*)rule_info__.parser__->parse_stack__.sf_by_top(2);
   
        const char* skey = sf->p2__->identifier()->c_str();

        rule_def* rdef = new rule_def(skey);
        rdef->set_rc(*sf->p2__,__FILE__,__LINE__);
        rule_in_stbl* ristbl = new rule_in_stbl(*rdef);
        ristbl->set_rc(*sf->p2__,__FILE__,__LINE__);
        
        refered_rule* rr = new refered_rule(*ristbl);
        rr->set_rc(*sf->p2__,__FILE__,__LINE__);
		ristbl->add_R_into_xref(*rr);
        sf->p2__->set_auto_delete(true);
        T_sym_tbl_report_card report_card;
        using namespace yacco2_stbl;
        add_sym_to_stbl(report_card,*skey,*ristbl,table_entry::used,table_entry::rule);
	  	if(report_card.status_ != T_sym_tbl_report_card::okay){
			report_card.err_entry_->set_rc(*sf->p2__,__FILE__,__LINE__);
			RSVP(report_card.err_entry_);
			rule_info__.parser__->set_stop_parse(true);
			return;
		}
	  	ristbl->stbl_idx(report_card.pos_);
        RSVP(ristbl);
        rule_info__.parser__->set_stop_parse(true);       
    
}

void Rrhs_component::sr2(){
  struct SF{
   LR1_parallel_operator* p1__;
   State* s1__;
   bool abort1__;
   Rule_s_reuse_entry* rule_s_reuse_entry1__;
   T_c_string* p2__;
   State* s2__;
   bool abort2__;
   Rule_s_reuse_entry* rule_s_reuse_entry2__;
  };
  SF* sf = (SF*)rule_info__.parser__->parse_stack__.sf_by_top(2);
  
      Crhs_component* fsm = (Crhs_component*)rule_info__.parser__->fsm_tbl__;
      fsm->fnd_T_of_chr_str(sf->p2__->c_string()->c_str(),sf->p2__);
	  sf->p2__->set_auto_delete(true);
    
}

void Rrhs_component::sr3(){
  struct SF{
   LR1_parallel_operator* p1__;
   State* s1__;
   bool abort1__;
   Rule_s_reuse_entry* rule_s_reuse_entry1__;
   T_unquoted_string* p2__;
   State* s2__;
   bool abort2__;
   Rule_s_reuse_entry* rule_s_reuse_entry2__;
  };
  SF* sf = (SF*)rule_info__.parser__->parse_stack__.sf_by_top(2);
   // only accept when no identifier
      Crhs_component* fsm = (Crhs_component*)rule_info__.parser__->fsm_tbl__;
	  sf->p2__->set_auto_delete(true);
        string eos_chk("->");
        if(eos_chk == sf->p2__->unquoted_string()->c_str()){
          rule_info__.parser__->set_abort_parse(true);
          return;        
        }        
      fsm->fnd_T_of_chr_str(sf->p2__->unquoted_string()->c_str(),sf->p2__);
    
}

void Rrhs_component::sr4(){
  struct SF{
   LR1_parallel_operator* p1__;
   State* s1__;
   bool abort1__;
   Rule_s_reuse_entry* rule_s_reuse_entry1__;
   T_cweb_comment* p2__;
   State* s2__;
   bool abort2__;
   Rule_s_reuse_entry* rule_s_reuse_entry2__;
  };
  SF* sf = (SF*)rule_info__.parser__->parse_stack__.sf_by_top(2);
   
        T_cweb_comment* k = sf->p2__;
        AST* cwebk_t_ = new AST(*k);
        AST* cweb_t_ = new AST();
        T_cweb_marker* cw = new T_cweb_marker(cweb_t_);
        cw->set_rc(*k,__FILE__,__LINE__);
      AST::set_content(*cweb_t_,*cw);
        AST::join_pts(*cweb_t_,*cwebk_t_);
      RSVP(cw);
      rule_info__.parser__->set_stop_parse(true);       
    
}

void Rrhs_component::sr5(){
  struct SF{
   LR1_parallel_operator* p1__;
   State* s1__;
   bool abort1__;
   Rule_s_reuse_entry* rule_s_reuse_entry1__;
   CAbs_lr1_sym* p2__;
   State* s2__;
   bool abort2__;
   Rule_s_reuse_entry* rule_s_reuse_entry2__;
  };
  SF* sf = (SF*)rule_info__.parser__->parse_stack__.sf_by_top(2);
  
      RSVP(sf->p2__);
      rule_info__.parser__->set_stop_parse(true);       
    
}

void Rrhs_component::sr6(){
  struct SF{
   LR1_parallel_operator* p1__;
   State* s1__;
   bool abort1__;
   Rule_s_reuse_entry* rule_s_reuse_entry1__;
   rule_in_stbl* p2__;
   State* s2__;
   bool abort2__;
   Rule_s_reuse_entry* rule_s_reuse_entry2__;
  };
  SF* sf = (SF*)rule_info__.parser__->parse_stack__.sf_by_top(2);
   
			using namespace yacco2_stbl;
			T_sym_tbl_report_card report_card;
			find_sym_in_stbl(report_card,*sf->p2__->r_def()->rule_name()->c_str());
			if(report_card.action_ == T_sym_tbl_report_card::not_fnd){
				CAbs_lr1_sym* sym = new Err_rule_not_in_stbl;
				sym->set_rc(*rule_info__.parser__->start_token__,__FILE__,__LINE__);
				RSVP(sym);
				rule_info__.parser__->set_stop_parse(true); 
				return;        
			}
			report_card.tbl_entry_->used_ = true;
			refered_rule* rr = new refered_rule(*sf->p2__);
			rr->set_rc(*sf->p2__,__FILE__,__LINE__);
			sf->p2__->add_R_into_xref(*rr);
			RSVP(sf->p2__);
			rule_info__.parser__->set_stop_parse(true); 
      
}

void Rrhs_component::sr7(){
  struct SF{
   LR1_parallel_operator* p1__;
   State* s1__;
   bool abort1__;
   Rule_s_reuse_entry* rule_s_reuse_entry1__;
   T_in_stbl* p2__;
   State* s2__;
   bool abort2__;
   Rule_s_reuse_entry* rule_s_reuse_entry2__;
  };
  SF* sf = (SF*)rule_info__.parser__->parse_stack__.sf_by_top(2);
   
			using namespace yacco2_stbl;
			T_sym_tbl_report_card report_card;
			find_sym_in_stbl(report_card,*sf->p2__->t_def()->t_name()->c_str());
			if(report_card.action_ == T_sym_tbl_report_card::not_fnd){
				CAbs_lr1_sym* sym = new Err_T_not_in_stbl;
				sym->set_rc(*rule_info__.parser__->start_token__,__FILE__,__LINE__);
				RSVP(sym);
				rule_info__.parser__->set_stop_parse(true); 
				return;        
			}
			report_card.tbl_entry_->used_ = true;
			refered_T* rt = new refered_T(*sf->p2__);
			rt->set_rc(*sf->p2__,__FILE__,__LINE__);

		    sf->p2__->add_T_into_xref(*rt);
			RSVP(sf->p2__);
			rule_info__.parser__->set_stop_parse(true); 
      
}

void Rrhs_component::sr8(){
   
			CAbs_lr1_sym* sym = new Err_not_T_or_R_in_subrule_expr;
			sym->set_rc(*rule_info__.parser__->start_token__,__FILE__,__LINE__);
			RSVP(sym);
			rule_info__.parser__->set_stop_parse(true); 
      
}