/*
 File: rule_def_phrase.cpp
 Date and Time: Fri Jan 30 18:55:22 2015 
*/
#include "rule_def_phrase.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_rule_def_phrase;// grammar's ns
// first set terminals
fsm_rules_reuse_table_type::fsm_rules_reuse_table_type(){
 no_rules_entries_ = 16;
 per_rule_s_table_[0] =  new Per_rule_s_reuse_table();
 per_rule_s_table_[1] =  new Per_rule_s_reuse_table();
 per_rule_s_table_[2] =  new Per_rule_s_reuse_table();
 per_rule_s_table_[3] =  new Per_rule_s_reuse_table();
 per_rule_s_table_[4] =  new Per_rule_s_reuse_table();
 per_rule_s_table_[5] =  new Per_rule_s_reuse_table();
 per_rule_s_table_[6] =  new Per_rule_s_reuse_table();
 per_rule_s_table_[7] =  new Per_rule_s_reuse_table();
 per_rule_s_table_[8] =  new Per_rule_s_reuse_table();
 per_rule_s_table_[9] =  new Per_rule_s_reuse_table();
 per_rule_s_table_[10] =  new Per_rule_s_reuse_table();
 per_rule_s_table_[11] =  new Per_rule_s_reuse_table();
 per_rule_s_table_[12] =  new Per_rule_s_reuse_table();
 per_rule_s_table_[13] =  new Per_rule_s_reuse_table();
 per_rule_s_table_[14] =  new Per_rule_s_reuse_table();
 per_rule_s_table_[15] =  new Per_rule_s_reuse_table();
}
  Crule_def_phrase::
  Crule_def_phrase()
    :yacco2::CAbs_fsm
      ("rule_def_phrase.lex"
      ,"1.0"
      ,"24 mar 2004"
      ,false
      ,"Parse a grammar's rule  definition."
      ,"Fri Jan 30 18:55:22 2015 "
      ,S1_Crule_def_phrase){
    
      rule_def_ = 0;
  
  }
 
Crule_def_phrase::~Crule_def_phrase(){

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

  bool Crule_def_phrase::failed(){
      return false;
  }
  void Crule_def_phrase::op(){
      rule_def_ = 0;
  
}
int Crule_def_phrase::rhs_to_rules_mapping_[38] = {
 -1
 ,0 // subrule 1 for rule 1
 ,1 // subrule 2 for rule 2
 ,1 // subrule 3 for rule 2
 ,1 // subrule 4 for rule 2
 ,2 // subrule 5 for rule 3
 ,2 // subrule 6 for rule 3
 ,2 // subrule 7 for rule 3
 ,2 // subrule 8 for rule 3
 ,3 // subrule 9 for rule 4
 ,3 // subrule 10 for rule 4
 ,3 // subrule 11 for rule 4
 ,4 // subrule 12 for rule 5
 ,4 // subrule 13 for rule 5
 ,5 // subrule 14 for rule 6
 ,5 // subrule 15 for rule 6
 ,5 // subrule 16 for rule 6
 ,6 // subrule 17 for rule 7
 ,6 // subrule 18 for rule 7
 ,6 // subrule 19 for rule 7
 ,7 // subrule 20 for rule 8
 ,7 // subrule 21 for rule 8
 ,8 // subrule 22 for rule 9
 ,8 // subrule 23 for rule 9
 ,9 // subrule 24 for rule 10
 ,10 // subrule 25 for rule 11
 ,10 // subrule 26 for rule 11
 ,10 // subrule 27 for rule 11
 ,11 // subrule 28 for rule 12
 ,11 // subrule 29 for rule 12
 ,12 // subrule 30 for rule 13
 ,12 // subrule 31 for rule 13
 ,13 // subrule 32 for rule 14
 ,13 // subrule 33 for rule 14
 ,14 // subrule 34 for rule 15
 ,14 // subrule 35 for rule 15
 ,15 // subrule 36 for rule 16
 ,15 // subrule 37 for rule 16
}; 
Rrule_def_phrase::Rrule_def_phrase(yacco2::Parser* P)
 :CAbs_lr1_sym
  ("Rrule_def_phrase",0,Crule_def_phrase::R_Rrule_def_phrase_,P,false,false){
}

void Rrule_def_phrase::sr1(){
  
      Crule_def_phrase* fsm = (Crule_def_phrase*)rule_info__.parser__->fsm_tbl__;
      fsm->rule_def_->bld_its_tree();
      RSVP(fsm->rule_def_);
      fsm->rule_def_ = 0;
    
}

Rrule_cweb_k::Rrule_cweb_k(yacco2::Parser* P)
 :CAbs_lr1_sym
  ("Rrule_cweb_k",0,Crule_def_phrase::R_Rrule_cweb_k_,P,false,false){
}

void Rrule_cweb_k::sr2(){
  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);
  
        Crule_def_phrase* fsm = (Crule_def_phrase*)rule_info__.parser__->fsm_tbl__;
        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__);
        fsm->rule_def_->add_cweb_marker(cweb_t_);
        AST::set_content(*cweb_t_,*cw);
        AST::join_pts(*cweb_t_,*cwebk_t_);
	
}

void Rrule_cweb_k::sr3(){
  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); 
      
}

Rid::Rid(yacco2::Parser* P)
 :CAbs_lr1_sym
  ("Rid",0,Crule_def_phrase::R_Rid_,P,false,false){
}

void Rid::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);
   
        Crule_def_phrase* fsm = (Crule_def_phrase*)rule_info__.parser__->fsm_tbl__;
        const char* skey = sf->p2__->identifier()->c_str();
        fsm->rule_def_ = new rule_def(skey);
        rule_in_stbl* ristbl = new rule_in_stbl(*fsm->rule_def_);
        fsm->rule_def_->set_rc(*sf->p2__,__FILE__,__LINE__);
        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::defed,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_);
        report_card.tbl_entry_->defined_ = true;
      
}

void Rid::sr2(){
  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);
   
        Crule_def_phrase* fsm = (Crule_def_phrase*)rule_info__.parser__->fsm_tbl__;
		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;        
        }
         if(report_card.tbl_entry_->defined_ == true){
			CAbs_lr1_sym* sym = new Err_rule_already_defined;
			sym->set_rc(*rule_info__.parser__->start_token__,__FILE__,__LINE__);
			RSVP(sym);
			rule_info__.parser__->set_stop_parse(true); 
			return;        
        }
       fsm->rule_def_ = sf->p2__->r_def();
        report_card.tbl_entry_->defined_ = true;
      
}

void Rid::sr3(){
  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);
   
		CAbs_lr1_sym* sym = new Err_stble_has_entry_but_not_a_rule;
		sym->set_rc(*sf->p2__,__FILE__,__LINE__);
		RSVP(sym);
		rule_info__.parser__->set_stop_parse(true); 
		return;
      
}

void Rid::sr4(){
  struct SF{
   CAbs_lr1_sym* p1__;
   State* s1__;
   bool abort1__;
   Rule_s_reuse_entry* rule_s_reuse_entry1__;
  };
  SF* sf = (SF*)rule_info__.parser__->parse_stack__.sf_by_top(1);
  
        CAbs_lr1_sym* sym = new Err_no_rule_name_present;
        sym->set_rc(*sf->p1__,__FILE__,__LINE__);
        RSVP(sym);
        rule_info__.parser__->set_stop_parse(true);
      
}

Rad_ab_tags::Rad_ab_tags(yacco2::Parser* P)
 :CAbs_lr1_sym
  ("Rad_ab_tags",0,Crule_def_phrase::R_Rad_ab_tags_,P,false,false){
}

Rad_ab_tag::Rad_ab_tag(yacco2::Parser* P)
 :CAbs_lr1_sym
  ("Rad_ab_tag",0,Crule_def_phrase::R_Rad_ab_tag_,P,false,false){
}

void Rad_ab_tag::sr1(){
  struct SF{
   LR1_parallel_operator* p1__;
   State* s1__;
   bool abort1__;
   Rule_s_reuse_entry* rule_s_reuse_entry1__;
   T_AD* 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);
   
        Crule_def_phrase* fsm = (Crule_def_phrase*)rule_info__.parser__->fsm_tbl__;
        if(fsm->rule_def_->autodelete() == true){
			CAbs_lr1_sym* sym = new Err_already_defined_AD;
			sym->set_rc(*sf->p2__,__FILE__,__LINE__);
			RSVP(sym);
			rule_info__.parser__->set_stop_parse(true);
			return;
        }
        fsm->rule_def_->autodelete(true);
      
}

void Rad_ab_tag::sr2(){
  struct SF{
   LR1_parallel_operator* p1__;
   State* s1__;
   bool abort1__;
   Rule_s_reuse_entry* rule_s_reuse_entry1__;
   T_AB* 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);
   
        Crule_def_phrase* fsm = (Crule_def_phrase*)rule_info__.parser__->fsm_tbl__;
        if(fsm->rule_def_->autoabort() == true){
			CAbs_lr1_sym* sym = new Err_already_defined_AB;
			sym->set_rc(*sf->p2__,__FILE__,__LINE__);
			RSVP(sym);
			rule_info__.parser__->set_stop_parse(true);
			return;
        }
        fsm->rule_def_->autoabort(true);
      
}

Rrule_parameters::Rrule_parameters(yacco2::Parser* P)
 :CAbs_lr1_sym
  ("Rrule_parameters",0,Crule_def_phrase::R_Rrule_parameters_,P,false,false){
}

Rrule_parameter::Rrule_parameter(yacco2::Parser* P)
 :CAbs_lr1_sym
  ("Rrule_parameter",0,Crule_def_phrase::R_Rrule_parameter_,P,false,false){
}

void Rrule_parameter::sr1(){
  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);
  
        CAbs_lr1_sym* sym = new Err_not_lhs_pcnrl_mntr;
        sym->set_rc(*sf->p2__,__FILE__,__LINE__);
        RSVP(sym);
        rule_info__.parser__->set_stop_parse(true);
    
}

Rlhs_phrase::Rlhs_phrase(yacco2::Parser* P)
 :CAbs_lr1_sym
  ("Rlhs_phrase",0,Crule_def_phrase::R_Rlhs_phrase_,P,false,false){
}

void Rlhs_phrase::sr1(){
  struct SF{
   LR1_fset_transience_operator* p1__;
   State* s1__;
   bool abort1__;
   Rule_s_reuse_entry* rule_s_reuse_entry1__;
   T_rule_lhs_phrase* 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);
  
      Crule_def_phrase* fsm = (Crule_def_phrase*)rule_info__.parser__->fsm_tbl__;
      fsm->rule_def_->rule_lhs(sf->p2__);
    
}

void Rlhs_phrase::sr2(){
  struct SF{
   LR1_fset_transience_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);
    
}

Rparallel_monitor_phrase::Rparallel_monitor_phrase(yacco2::Parser* P)
 :CAbs_lr1_sym
  ("Rparallel_monitor_phrase",0,Crule_def_phrase::R_Rparallel_monitor_phrase_,P,false,false){
}

void Rparallel_monitor_phrase::sr1(){
  struct SF{
   LR1_fset_transience_operator* p1__;
   State* s1__;
   bool abort1__;
   Rule_s_reuse_entry* rule_s_reuse_entry1__;
   T_parallel_monitor_phrase* 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);
  
      Crule_def_phrase* fsm = (Crule_def_phrase*)rule_info__.parser__->fsm_tbl__;
      fsm->rule_def_->parallel_mntr(sf->p2__);
    
}

void Rparallel_monitor_phrase::sr2(){
  struct SF{
   LR1_fset_transience_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);
    
}

Rrule_body::Rrule_body(yacco2::Parser* P)
 :CAbs_lr1_sym
  ("Rrule_body",0,Crule_def_phrase::R_Rrule_body_,P,false,false){
}

Rsubrules::Rsubrules(yacco2::Parser* P)
 :CAbs_lr1_sym
  ("Rsubrules",0,Crule_def_phrase::R_Rsubrules_,P,false,false){
}

void Rsubrules::sr1(){
  struct SF{
   LR1_parallel_operator* p1__;
   State* s1__;
   bool abort1__;
   Rule_s_reuse_entry* rule_s_reuse_entry1__;
   T_subrules_phrase* 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);
  
      Crule_def_phrase* fsm = (Crule_def_phrase*)rule_info__.parser__->fsm_tbl__;
      fsm->rule_def_->subrules(sf->p2__);
      // distribute rule def to its subrules
      std::vector<T_subrule_def*>::iterator i = sf->p2__->subrules()->begin();
      std::vector<T_subrule_def*>::iterator ie = sf->p2__->subrules()->end();
      for(;i != ie;++i){
        T_subrule_def* srd = *i;
        srd->its_rule_def(fsm->rule_def_);
      }
    
}

void Rsubrules::sr2(){
  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 Rsubrules::sr3(){
  struct SF{
   CAbs_lr1_sym* p1__;
   State* s1__;
   bool abort1__;
   Rule_s_reuse_entry* rule_s_reuse_entry1__;
  };
  SF* sf = (SF*)rule_info__.parser__->parse_stack__.sf_by_top(1);
  
        CAbs_lr1_sym* sym = new Err_no_sub_rule_present;
        sym->set_rc(*sf->p1__,__FILE__,__LINE__);
        RSVP(sym);
        rule_info__.parser__->set_stop_parse(true);
      
}

Ropen_par::Ropen_par(yacco2::Parser* P)
 :CAbs_lr1_sym
  ("Ropen_par",0,Crule_def_phrase::R_Ropen_par_,P,false,false){
}

void Ropen_par::sr1(){
  struct SF{
   CAbs_lr1_sym* p1__;
   State* s1__;
   bool abort1__;
   Rule_s_reuse_entry* rule_s_reuse_entry1__;
  };
  SF* sf = (SF*)rule_info__.parser__->parse_stack__.sf_by_top(1);
  
        CAbs_lr1_sym* sym = new Err_no_open_parenthesis;
        sym->set_rc(*sf->p1__,__FILE__,__LINE__);
        RSVP(sym);
        rule_info__.parser__->set_stop_parse(true);
      
}

Rclose_par::Rclose_par(yacco2::Parser* P)
 :CAbs_lr1_sym
  ("Rclose_par",0,Crule_def_phrase::R_Rclose_par_,P,false,false){
}

void Rclose_par::sr1(){
  struct SF{
   CAbs_lr1_sym* p1__;
   State* s1__;
   bool abort1__;
   Rule_s_reuse_entry* rule_s_reuse_entry1__;
  };
  SF* sf = (SF*)rule_info__.parser__->parse_stack__.sf_by_top(1);
  
        CAbs_lr1_sym* sym = new Err_no_close_parenthesis;
        sym->set_rc(*sf->p1__,__FILE__,__LINE__);
        RSVP(sym);
        rule_info__.parser__->set_stop_parse(true);
      
}

Ropen_brace::Ropen_brace(yacco2::Parser* P)
 :CAbs_lr1_sym
  ("Ropen_brace",0,Crule_def_phrase::R_Ropen_brace_,P,false,false){
}

void Ropen_brace::sr1(){
  struct SF{
   CAbs_lr1_sym* p1__;
   State* s1__;
   bool abort1__;
   Rule_s_reuse_entry* rule_s_reuse_entry1__;
  };
  SF* sf = (SF*)rule_info__.parser__->parse_stack__.sf_by_top(1);
  
        CAbs_lr1_sym* sym = new Err_no_open_brace;
        sym->set_rc(*sf->p1__,__FILE__,__LINE__);
        RSVP(sym);
        rule_info__.parser__->set_stop_parse(true);
      
}

Rclose_brace::Rclose_brace(yacco2::Parser* P)
 :CAbs_lr1_sym
  ("Rclose_brace",0,Crule_def_phrase::R_Rclose_brace_,P,false,false){
}

void Rclose_brace::sr1(){
  struct SF{
   CAbs_lr1_sym* p1__;
   State* s1__;
   bool abort1__;
   Rule_s_reuse_entry* rule_s_reuse_entry1__;
  };
  SF* sf = (SF*)rule_info__.parser__->parse_stack__.sf_by_top(1);
  
        CAbs_lr1_sym* sym = new Err_no_close_brace;
        sym->set_rc(*sf->p1__,__FILE__,__LINE__);
        RSVP(sym);
        rule_info__.parser__->set_stop_parse(true);
      
}

Rlint::Rlint(yacco2::Parser* P)
 :CAbs_lr1_sym
  ("Rlint",0,Crule_def_phrase::R_Rlint_,P,false,false){
}

