/*
 File: t_alphabet.cpp
 Date and Time: Fri Jan 30 18:55:25 2015 
*/
#include "t_alphabet.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_t_alphabet;// grammar's ns
// first set terminals
fsm_rules_reuse_table_type::fsm_rules_reuse_table_type(){
 no_rules_entries_ = 6;
 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();
}
  Ct_alphabet::
  Ct_alphabet()
    :yacco2::CAbs_fsm
      ("t_alphabet.lex"
      ,"1.0"
      ,"9 Feb. 2005"
      ,false
      ,"Parse Linker's t-alphabet language."
      ,"Fri Jan 30 18:55:25 2015 "
      ,S1_Ct_alphabet){
    
    enum_cnt_ = 0;
  
  }
 
Ct_alphabet::~Ct_alphabet(){

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

  bool Ct_alphabet::failed(){
      return false;
  }
  void Ct_alphabet::op(){
}
int Ct_alphabet::rhs_to_rules_mapping_[11] = {
 -1
 ,0 // subrule 1 for rule 1
 ,1 // subrule 2 for rule 2
 ,2 // subrule 3 for rule 3
 ,2 // subrule 4 for rule 3
 ,3 // subrule 5 for rule 4
 ,3 // subrule 6 for rule 4
 ,3 // subrule 7 for rule 4
 ,4 // subrule 8 for rule 5
 ,5 // subrule 9 for rule 6
 ,5 // subrule 10 for rule 6
}; 
Rt_alphabet::Rt_alphabet(yacco2::Parser* P)
 :CAbs_lr1_sym
  ("Rt_alphabet",0,Ct_alphabet::R_Rt_alphabet_,P,false,false){
}

void Rt_alphabet::op(){
  sstrace_rulesss
 
       using namespace NS_yacco2_k_symbols;
       ADD_TOKEN_TO_PRODUCER_QUEUE(*yacco2::PTR_LR1_eog__);   
       ADD_TOKEN_TO_PRODUCER_QUEUE(*yacco2::PTR_LR1_eog__);  
  
}
Reog::Reog(yacco2::Parser* P)
 :CAbs_lr1_sym
  ("Reog",0,Ct_alphabet::R_Reog_,P,false,false){
}

void Reog::sr1(){
  struct SF{
   LR1_eog* 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);
   
 	  Ct_alphabet* fsm = (Ct_alphabet*) rule_info__.parser__->fsm_tbl__;
      if(fsm->T_dictionary_.empty()){
        CAbs_lr1_sym* sym = new Err_no_terminals_present_in_T_alphabet;
        sym->set_rc(*sf->p1__,__FILE__,__LINE__);
        ADD_TOKEN_TO_ERROR_QUEUE(*sym);
        rule_info__.parser__->set_stop_parse(true);
      }
    
}

RT_alphabet::RT_alphabet(yacco2::Parser* P)
 :CAbs_lr1_sym
  ("RT_alphabet",0,Ct_alphabet::R_RT_alphabet_,P,false,false){
}

void RT_alphabet::sr2(){
  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_T_alphabet_kw_not_present;
      sym->set_rc(*sf->p1__,__FILE__,__LINE__);
      ADD_TOKEN_TO_ERROR_QUEUE(*sym);
      rule_info__.parser__->set_stop_parse(true);
    
}

Rlist_of_Ts::Rlist_of_Ts(yacco2::Parser* P)
 :CAbs_lr1_sym
  ("Rlist_of_Ts",0,Ct_alphabet::R_Rlist_of_Ts_,P,false,false){
}

void Rlist_of_Ts::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_terminals_in_T_alphabet_list;
       sym->set_rc(*sf->p1__,__FILE__,__LINE__); 
       ADD_TOKEN_TO_ERROR_QUEUE(*sym);
       rule_info__.parser__->set_stop_parse(true);
    
}

Ra_T::Ra_T(yacco2::Parser* P)
 :CAbs_lr1_sym
  ("Ra_T",0,Ct_alphabet::R_Ra_T_,P,false,false){
}

void Ra_T::sr1(){
  struct SF{
   T_identifier* 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);
  
 	  Ct_alphabet* fsm = (Ct_alphabet*) rule_info__.parser__->fsm_tbl__;
      T_identifier* k = sf->p1__;
      // add to T dictionary
      std::map<std::string,int>::iterator i = 
	fsm->T_dictionary_.find(k->identifier()->c_str());
      if(i != fsm->T_dictionary_.end()){
        CAbs_lr1_sym* sym = new Err_dup_entry_in_sym_table;
        sym->set_rc(*sf->p1__,__FILE__,__LINE__); 
        ADD_TOKEN_TO_ERROR_QUEUE(*sym);
        rule_info__.parser__->set_stop_parse(true);
        return;
      }
      fsm->T_dictionary_[k->identifier()->c_str()]=fsm->enum_cnt_;
      string xxx(k->identifier()->c_str());
      fsm->enum_T_dictionary_[fsm->enum_cnt_] = xxx;
	  using namespace yacco2_stbl;
	  T_sym_tbl_report_card report_card;
	  T_attributes* T_att = new T_attributes(k->identifier()->c_str(),fsm->enum_cnt_);
	  tth_in_stbl* t = new tth_in_stbl(T_att,k,rule_info__.parser__);
	  add_sym_to_stbl(report_card,*k->identifier()->c_str()
		,*t,table_entry::defed,table_entry::terminal);
	  	if(report_card.status_ != T_sym_tbl_report_card::okay){
			report_card.err_entry_->set_rc(*sf->p1__,__FILE__,__LINE__);
			ADD_TOKEN_TO_ERROR_QUEUE(*report_card.err_entry_);
			rule_info__.parser__->set_stop_parse(true);
			return;
		}
	  t->stbl_idx(report_card.pos_);
      T_DICTIONARY.push_back(report_card.tbl_entry_);
      T_THREAD_ID_LIST.push_back(std::set<int>());
      ++fsm->enum_cnt_;
    
}

Rend_T_alphabet::Rend_T_alphabet(yacco2::Parser* P)
 :CAbs_lr1_sym
  ("Rend_T_alphabet",0,Ct_alphabet::R_Rend_T_alphabet_,P,false,false){
}

void Rend_T_alphabet::sr2(){
  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_end_T_alphabet_kw_not_present;
       sym->set_rc(*sf->p1__,__FILE__,__LINE__); 
       ADD_TOKEN_TO_ERROR_QUEUE(*sym);
       rule_info__.parser__->set_stop_parse(true);
    
}

