/*
 File: enumerate_T_alphabet.cpp
 Date and Time: Fri Jan 30 18:55:09 2015 
*/
#include "enumerate_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_enumerate_T_alphabet;// grammar's ns
// first set terminals
fsm_rules_reuse_table_type::fsm_rules_reuse_table_type(){
 no_rules_entries_ = 5;
 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();
}
  Cenumerate_T_alphabet::
  Cenumerate_T_alphabet()
    :yacco2::CAbs_fsm
      ("enumerate_T_alphabet.lex"
      ,"1.0"
      ,"9 Aug. 2005"
      ,false
      ,"Enumerate grammar's terminal symbols: \na 0 and a 1, ... the oracle for parsing lookups."
      ,"Fri Jan 30 18:55:09 2015 "
      ,S1_Cenumerate_T_alphabet){
    
    START_OF_RULES_ENUM = 0;
    enum_phrase_ = 0;      
  
  }
 
Cenumerate_T_alphabet::~Cenumerate_T_alphabet(){

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

  bool Cenumerate_T_alphabet::failed(){
      return false;
  }
  void Cenumerate_T_alphabet::op(){
    START_OF_RULES_ENUM = 0;
    CAbs_lr1_sym* gps = O2_FSM_PHASE;
    CAbs_lr1_sym* esym(0);
    CAbs_lr1_sym* ph = O2_T_ENUM_PHASE;
     
    if(ph == 0){
      esym = new ERR_no_T_enum_phrase;
      goto error_fnd;
    }
    gps = ph;
    ph = O2_ERROR_PHASE;
    if(ph == 0){
      esym = new ERR_no_errors_phrase;
      goto error_fnd;
    }
    gps = ph;
    ph = O2_RC_PHASE;
    if(ph == 0){
      esym = new ERR_no_rc_phrase;
      goto error_fnd;
    }
    gps = ph;
    ph = O2_LRK_PHASE;
    if(ph == 0){
      esym = new ERR_no_lrk_phrase;
      goto error_fnd;
    }
    gps = ph;
    ph = O2_T_PHASE;
    if(ph == 0){
      esym = new ERR_no_terminals_phrase;
      goto error_fnd;
    }
    all_phases_ok:
      enum_phrase_ = O2_T_ENUM_PHASE;      
      return;
    error_fnd:
      parser__->add_token_to_error_queue(*esym);
      if(gps != 0) // anchor error against previously good phase
        esym->set_rc(*gps,__FILE__,__LINE__);
      parser__->set_abort_parse(true);
      return;
  
}
int Cenumerate_T_alphabet::rhs_to_rules_mapping_[6] = {
 -1
 ,0 // subrule 1 for rule 1
 ,1 // subrule 2 for rule 2
 ,2 // subrule 3 for rule 3
 ,3 // subrule 4 for rule 4
 ,4 // subrule 5 for rule 5
}; 
Renumerate_T_alphabet::Renumerate_T_alphabet(yacco2::Parser* P)
 :CAbs_lr1_sym
  ("Renumerate_T_alphabet",0,Cenumerate_T_alphabet::R_Renumerate_T_alphabet_,P,false,false){
}

void Renumerate_T_alphabet::sr1(){
  
    Cenumerate_T_alphabet* fsm = (Cenumerate_T_alphabet*)rule_info__.parser__->fsm_tbl__;
    fsm->enum_phrase_->total_enumerate(START_OF_RULES_ENUM);
    lrclog << "Total symbols: " << START_OF_RULES_ENUM << std::endl;
  
}

Renum_lrk::Renum_lrk(yacco2::Parser* P)
 :CAbs_lr1_sym
  ("Renum_lrk",0,Cenumerate_T_alphabet::R_Renum_lrk_,P,false,false){
}

void Renum_lrk::sr1(){
  
    Cenumerate_T_alphabet* fsm = (Cenumerate_T_alphabet*)rule_info__.parser__->fsm_tbl__;
    T_lr1_k_phrase* lr_ph = O2_LRK_PHASE;
    std::vector<T_terminal_def*>* order = lr_ph->crt_order();
    std::vector<T_terminal_def*>::iterator i = order->begin();
    std::vector<T_terminal_def*>::iterator ie = order->end();
    for(fsm->enum_phrase_->start_lrk_enumerate(START_OF_RULES_ENUM);
	i!=ie;++i,++START_OF_RULES_ENUM){
      T_terminal_def* tdef = *i;
      tdef->enum_id(START_OF_RULES_ENUM);
    }
    fsm->enum_phrase_->stop_lrk_enumerate(START_OF_RULES_ENUM-1);
    fsm->enum_phrase_->
		total_lrk_enumerate
			(fsm->enum_phrase_->stop_lrk_enumerate() 
				- fsm->enum_phrase_->start_lrk_enumerate() + 1);
    lrclog << "Total lrk symbols: " 
		<< fsm->enum_phrase_->total_lrk_enumerate() << std::endl;
    lrclog << "Start lrk symbol: " 
		<< fsm->enum_phrase_->start_lrk_enumerate()
        << " Stop lrk symbol: " 
		<< fsm->enum_phrase_->stop_lrk_enumerate() << std::endl;
  
}

Renum_rc::Renum_rc(yacco2::Parser* P)
 :CAbs_lr1_sym
  ("Renum_rc",0,Cenumerate_T_alphabet::R_Renum_rc_,P,false,false){
}

void Renum_rc::sr1(){
  
    Cenumerate_T_alphabet* fsm = 
	(Cenumerate_T_alphabet*)rule_info__.parser__->fsm_tbl__;
    T_rc_phrase* lr_ph = O2_RC_PHASE;

    std::vector<T_terminal_def*>* order = lr_ph->crt_order();
    std::vector<T_terminal_def*>::iterator i = order->begin();
    std::vector<T_terminal_def*>::iterator ie = order->end();
    for(fsm->enum_phrase_->start_rc_enumerate
		(START_OF_RULES_ENUM);i!=ie;++i,++START_OF_RULES_ENUM){
      T_terminal_def* tdef = *i;
      tdef->enum_id(START_OF_RULES_ENUM);
    }
    fsm->enum_phrase_->stop_rc_enumerate(START_OF_RULES_ENUM-1);
    fsm->enum_phrase_->
		total_rc_enumerate
			(fsm->enum_phrase_->stop_rc_enumerate() 
				- fsm->enum_phrase_->start_rc_enumerate() + 1);
    lrclog << "Total rc symbols: " 
		<< fsm->enum_phrase_->total_rc_enumerate() << std::endl;
    lrclog << "Start rc symbol: " 
		<< fsm->enum_phrase_->start_rc_enumerate() 
		<< " Stop rc symbol: " 
		<< fsm->enum_phrase_->stop_rc_enumerate() << std::endl;
  
}

Renum_T::Renum_T(yacco2::Parser* P)
 :CAbs_lr1_sym
  ("Renum_T",0,Cenumerate_T_alphabet::R_Renum_T_,P,false,false){
}

void Renum_T::sr1(){
  
    Cenumerate_T_alphabet* fsm = (Cenumerate_T_alphabet*)rule_info__.parser__->fsm_tbl__;
    T_terminals_phrase* lr_ph = O2_T_PHASE;

    std::vector<T_terminal_def*>* order = lr_ph->crt_order();
    std::vector<T_terminal_def*>::iterator i = order->begin();
    std::vector<T_terminal_def*>::iterator ie = order->end();
    for(fsm->enum_phrase_->start_T_enumerate(START_OF_RULES_ENUM);
		i!=ie;++i,++START_OF_RULES_ENUM){
      T_terminal_def* tdef = *i;
      tdef->enum_id(START_OF_RULES_ENUM);
    }
    fsm->enum_phrase_->stop_T_enumerate(START_OF_RULES_ENUM-1);
    fsm->enum_phrase_->
		total_T_enumerate
			(fsm->enum_phrase_->stop_T_enumerate() 
			- fsm->enum_phrase_->start_T_enumerate() + 1);
    lrclog << "Total T symbols: " 
		<< fsm->enum_phrase_->total_T_enumerate() << std::endl;
    lrclog << "Start T symbol: " 
		<< fsm->enum_phrase_->start_T_enumerate() 
		<< " Stop T symbol: " 
		<< fsm->enum_phrase_->stop_T_enumerate() << std::endl;
  
}

Renum_err::Renum_err(yacco2::Parser* P)
 :CAbs_lr1_sym
  ("Renum_err",0,Cenumerate_T_alphabet::R_Renum_err_,P,false,false){
}

void Renum_err::sr1(){
  
    Cenumerate_T_alphabet* fsm = (Cenumerate_T_alphabet*)rule_info__.parser__->fsm_tbl__;
    T_error_symbols_phrase* lr_ph = O2_ERROR_PHASE;

    std::vector<T_terminal_def*>* order = lr_ph->crt_order();
    std::vector<T_terminal_def*>::iterator i = order->begin();
    std::vector<T_terminal_def*>::iterator ie = order->end();
    for(fsm->enum_phrase_->start_err_enumerate(START_OF_RULES_ENUM);
		i!=ie;++i,++START_OF_RULES_ENUM){
      T_terminal_def* tdef = *i;
      tdef->enum_id(START_OF_RULES_ENUM);
    }
    fsm->enum_phrase_->stop_err_enumerate(START_OF_RULES_ENUM-1);
    fsm->enum_phrase_->
		total_err_enumerate
			(fsm->enum_phrase_->stop_err_enumerate() 
		- fsm->enum_phrase_->start_err_enumerate() + 1);
    lrclog << "Total error symbols: " 
		<< fsm->enum_phrase_->total_err_enumerate() << std::endl;
    lrclog << "Start error symbol: " 
		<< fsm->enum_phrase_->start_err_enumerate() 
		<< " Stop error symbol: " 
		<< fsm->enum_phrase_->stop_err_enumerate() << std::endl;
  
}

