/*
 File: identifier.cpp
 Date and Time: Fri Jan 30 18:55:12 2015 
*/
#include "identifier.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_identifier;// grammar's ns
// first set terminals
fsm_rules_reuse_table_type::fsm_rules_reuse_table_type(){
 no_rules_entries_ = 8;
 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();
}
  Cidentifier::
  Cidentifier()
    :yacco2::CAbs_fsm
      ("identifier.lex"
      ,"1.0"
      ,"17 Juin 2003"
      ,false
      ,"Yacco2 identifiers lexer with symbol table lookup."
      ,"Fri Jan 30 18:55:12 2015 "
      ,S1_Cidentifier){
    
    hyphen_pos_ = -1;
    hyphen_ = 0;
    hyphen_idx_ = -1;
    ddd_idx_ = 0;
    ddd_[ddd_idx_] = 0;
 
  }
 
Cidentifier::~Cidentifier(){

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

  bool Cidentifier::failed(){
      return false;
  }
  void Cidentifier::op(){
    hyphen_pos_ = -1;
    hyphen_ = 0;
    hyphen_idx_ = -1;
    ddd_idx_ = 0;
    ddd_[ddd_idx_] = 0;
 
}
int Cidentifier::rhs_to_rules_mapping_[70] = {
 -1
 ,0 // subrule 1 for rule 1
 ,0 // subrule 2 for rule 1
 ,1 // subrule 3 for rule 2
 ,2 // subrule 4 for rule 3
 ,2 // subrule 5 for rule 3
 ,2 // subrule 6 for rule 3
 ,2 // subrule 7 for rule 3
 ,3 // subrule 8 for rule 4
 ,3 // subrule 9 for rule 4
 ,3 // subrule 10 for rule 4
 ,3 // subrule 11 for rule 4
 ,3 // subrule 12 for rule 4
 ,3 // subrule 13 for rule 4
 ,3 // subrule 14 for rule 4
 ,3 // subrule 15 for rule 4
 ,3 // subrule 16 for rule 4
 ,3 // subrule 17 for rule 4
 ,3 // subrule 18 for rule 4
 ,3 // subrule 19 for rule 4
 ,3 // subrule 20 for rule 4
 ,4 // subrule 21 for rule 5
 ,4 // subrule 22 for rule 5
 ,4 // subrule 23 for rule 5
 ,4 // subrule 24 for rule 5
 ,4 // subrule 25 for rule 5
 ,4 // subrule 26 for rule 5
 ,4 // subrule 27 for rule 5
 ,4 // subrule 28 for rule 5
 ,4 // subrule 29 for rule 5
 ,4 // subrule 30 for rule 5
 ,4 // subrule 31 for rule 5
 ,4 // subrule 32 for rule 5
 ,4 // subrule 33 for rule 5
 ,5 // subrule 34 for rule 6
 ,5 // subrule 35 for rule 6
 ,5 // subrule 36 for rule 6
 ,5 // subrule 37 for rule 6
 ,5 // subrule 38 for rule 6
 ,5 // subrule 39 for rule 6
 ,5 // subrule 40 for rule 6
 ,5 // subrule 41 for rule 6
 ,5 // subrule 42 for rule 6
 ,5 // subrule 43 for rule 6
 ,5 // subrule 44 for rule 6
 ,5 // subrule 45 for rule 6
 ,5 // subrule 46 for rule 6
 ,6 // subrule 47 for rule 7
 ,6 // subrule 48 for rule 7
 ,6 // subrule 49 for rule 7
 ,6 // subrule 50 for rule 7
 ,6 // subrule 51 for rule 7
 ,6 // subrule 52 for rule 7
 ,6 // subrule 53 for rule 7
 ,6 // subrule 54 for rule 7
 ,6 // subrule 55 for rule 7
 ,6 // subrule 56 for rule 7
 ,6 // subrule 57 for rule 7
 ,6 // subrule 58 for rule 7
 ,6 // subrule 59 for rule 7
 ,7 // subrule 60 for rule 8
 ,7 // subrule 61 for rule 8
 ,7 // subrule 62 for rule 8
 ,7 // subrule 63 for rule 8
 ,7 // subrule 64 for rule 8
 ,7 // subrule 65 for rule 8
 ,7 // subrule 66 for rule 8
 ,7 // subrule 67 for rule 8
 ,7 // subrule 68 for rule 8
 ,7 // subrule 69 for rule 8
}; 
Ridentifier::Ridentifier(yacco2::Parser* P)
 :CAbs_lr1_sym
  ("Ridentifier",0,Cidentifier::R_Ridentifier_,P,false,false){
}

void Ridentifier::op(){
  sstrace_rulesss
 
    using namespace NS_yacco2_T_enum;
    using namespace NS_yacco2_terminals;
    using namespace yacco2_stbl;
    Cidentifier* fsm = (Cidentifier*) rule_info__.parser__->fsm_tbl__;
    CAbs_lr1_sym* sym(0);
	T_sym_tbl_report_card report_card;
	find_sym_in_stbl(report_card,*fsm->ddd_);
    if(report_card.action_ == T_sym_tbl_report_card::fnd) goto item_in_stbl;
    // strip out - suffix as in a-b where suffix -b is bktracked
    if(fsm->hyphen_ != 0){// re-align to - as lookahead
        rule_info__.parser__->override_current_token(*fsm->hyphen_,fsm->hyphen_pos_);
        fsm->ddd_[fsm->hyphen_idx_] = 0;
    }else{
      sym = new T_identifier((const char*)&fsm->ddd_);
      sym->set_rc(*rule_info__.parser__->start_token__,__FILE__,__LINE__);
      RSVP(sym);
      return;
    }
	find_sym_in_stbl(report_card,*fsm->ddd_);// relook up id without "-" sufx
    if(report_card.action_ == T_sym_tbl_report_card::fnd) goto item_in_stbl;
    sym = new T_identifier((const char*)&fsm->ddd_);
    sym->set_rc(*rule_info__.parser__->start_token__,__FILE__,__LINE__);
    RSVP(sym);
    return;
    
item_in_stbl:
    if(report_card.tbl_entry_->type_ != table_entry::keyword){
	  // return xxx-in-stbl where xxx one of rule, T
	  sym = report_card.tbl_entry_->symbol_; 
	  sym->set_rc(*rule_info__.parser__->start_token__,__FILE__,__LINE__);
	  RSVP(sym);
	  return;      
    }  
kw_handling:
    kw_in_stbl* kw_in = (kw_in_stbl*)report_card.tbl_entry_->symbol_;
    CAbs_lr1_sym* kw =  kw_in->keyword_in_stbl();
    CAbs_lr1_sym* nkw;
    switch(kw->enumerated_id__){
      case T_Enum::T_T_raw_characters_:{nkw = new T_raw_characters;break;}  
      case T_Enum::T_T_lr1_constant_symbols_:
	{nkw = new T_lr1_constant_symbols;break;}  
      case T_Enum::T_T_error_symbols_:{nkw = new T_error_symbols;break;}  
      case T_Enum::T_T_eocode_:{nkw = new T_eocode;break;}  

      case T_Enum::T_T_AD_:{nkw = new T_AD;break;}  
      case T_Enum::T_T_AB_:{nkw = new T_AB;break;}  
      case T_Enum::T_T_parallel_la_boundary_:
	{nkw = new T_parallel_la_boundary;break;}  
      case T_Enum::T_T_arbitrator_code_:{nkw = new T_arbitrator_code;break;}  

      case T_Enum::T_T_parallel_parser_:{nkw = new T_parallel_parser;break;}  
      case T_Enum::T_T_parallel_thread_function_:
	{nkw = new T_parallel_thread_function;break;}  
      case T_Enum::T_T_parallel_control_monitor_:
	{nkw = new T_parallel_control_monitor;break;}  
      case T_Enum::T_T_fsm_:{nkw = new T_fsm;break;}  
      case T_Enum::T_T_fsm_id_:{nkw = new T_fsm_id;break;}  
      case T_Enum::T_T_fsm_filename_:{nkw = new T_fsm_filename;break;}  
      case T_Enum::T_T_fsm_namespace_:{nkw = new T_fsm_namespace;break;}  
      case T_Enum::T_T_fsm_class_:{nkw = new T_fsm_class;break;}  
      case T_Enum::T_T_fsm_version_:{nkw = new T_fsm_version;break;}  
      case T_Enum::T_T_fsm_date_:{nkw = new T_fsm_date;break;}  
      case T_Enum::T_T_fsm_debug_:{nkw = new T_fsm_debug;break;}  
      case T_Enum::T_T_fsm_comments_:{nkw = new T_fsm_comments;break;}  
      case T_Enum::T_T_terminals_:{nkw = new T_terminals;break;}  
      case T_Enum::T_T_enumeration_:{nkw = new T_enumeration;break;}  
      case T_Enum::T_T_file_name_:{nkw = new T_file_name;break;}  
      case T_Enum::T_T_name_space_:{nkw = new T_name_space;break;}  
      case T_Enum::T_T_sym_class_:{nkw = new T_sym_class;break;}  
      case T_Enum::T_T_rules_:{nkw = new T_rules;break;}  
      case T_Enum::T_T_lhs_:{nkw = new T_lhs;break;}  
      case T_Enum::T_T_user_declaration_:{nkw = new T_user_declaration;break;}  
      case T_Enum::T_T_user_prefix_declaration_:
	{nkw = new T_user_prefix_declaration;break;}  
      case T_Enum::T_T_user_suffix_declaration_:
	{nkw = new T_user_suffix_declaration;break;}  
      case T_Enum::T_T_constructor_:{nkw = new T_constructor;break;}  
      case T_Enum::T_T_destructor_:{nkw = new T_destructor;break;}  
      case T_Enum::T_T_op_:{nkw = new T_op;break;}  
      case T_Enum::T_T_failed_:{nkw = new T_failed;break;}  
      case T_Enum::T_T_user_implementation_:
	{nkw = new T_user_implementation;break;}  
      case T_Enum::T_T_user_imp_tbl_:{nkw = new T_user_imp_tbl;break;}  
      case T_Enum::T_T_user_imp_sym_:{nkw = new T_user_imp_sym;break;}  
      case T_Enum::T_T_constant_defs_:{nkw = new T_constant_defs;break;}  
      case T_Enum::T_T_terminals_refs_:{nkw = new T_terminals_refs;break;}  
      case T_Enum::T_T_terminals_sufx_:{nkw = new T_terminals_sufx;break;}  
      case T_Enum::T_T_lrk_sufx_:{nkw = new T_lrk_sufx;break;}  
      case T_Enum::T_LR1_eog_:{nkw = new LR1_eog;break;}  
      case T_Enum::T_LR1_eolr_:{nkw = new LR1_eolr;break;}  
      case T_Enum::T_T_NULL_:{nkw = new T_NULL;break;} 
    }
    nkw->set_rc(*rule_info__.parser__->start_token__,__FILE__,__LINE__);
    RSVP(nkw);
    return;      
  
}
Rid_suffix::Rid_suffix(yacco2::Parser* P)
 :CAbs_lr1_sym
  ("Rid_suffix",0,Cidentifier::R_Rid_suffix_,P,false,false){
}

void Rid_suffix::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);
  
      Cidentifier* fsm = (Cidentifier*) rule_info__.parser__->fsm_tbl__;
      CAbs_lr1_sym* sym = sf->p1__;
      parser()->reset_current_token(parser()->current_token_pos()-1);// bk trk to previous chr which is on stack
      int id;
filter_char:
      id = sym->enumerated_id();
      if((id >= NS_yacco2_T_enum::T_Enum::T_raw_a_) 
                &&
         (id <= NS_yacco2_T_enum::T_Enum::T_raw_z_)) goto bld_str;
      if((id >= NS_yacco2_T_enum::T_Enum::T_raw_A_) 
                &&
         (id <= NS_yacco2_T_enum::T_Enum::T_raw_Z_)) goto bld_str;
      if((id >= NS_yacco2_T_enum::T_Enum::T_raw_0_) 
                &&
         (id <= NS_yacco2_T_enum::T_Enum::T_raw_9_)) goto bld_str;
      if(id == NS_yacco2_T_enum::T_Enum::T_raw_under_score_) goto bld_str;
      if(id == NS_yacco2_T_enum::T_Enum::T_raw_minus_){
       if(fsm->hyphen_ == 0){
		fsm->hyphen_pos_ = rule_info__.parser__->current_token_pos__-1;
		fsm->hyphen_ = sym;
		// note: len rel 1, idx rel 0: "-" not added yet to str, this will be its idx value
		fsm->hyphen_idx_ = fsm->ddd_idx_;
	  }
        goto bld_str;
      }
      return; // end-of-identifier
bld_str:
      fsm->ddd_[fsm->ddd_idx_] = sym->id__[0];
      ++fsm->ddd_idx_;
      fsm->ddd_[fsm->ddd_idx_] = 0;

      parser()->get_next_token();// as current token
      sym = parser()->current_token__;
      goto filter_char;
    
}

Rstart_char::Rstart_char(yacco2::Parser* P)
 :CAbs_lr1_sym
  ("Rstart_char",0,Cidentifier::R_Rstart_char_,P,false,false){
}

RUPPER_A_M::RUPPER_A_M(yacco2::Parser* P)
 :CAbs_lr1_sym
  ("RUPPER_A_M",0,Cidentifier::R_RUPPER_A_M_,P,false,false){
}

void RUPPER_A_M::op(){
  sstrace_rulesss
 
    Cidentifier* fsm = (Cidentifier*) rule_info__.parser__->fsm_tbl__;
    size_t pos = rule_info__.parser__->parse_stack__.top_sub__ - 1;
    CAbs_lr1_sym* sym = rule_info__.parser__->get_spec_stack_token(pos);
      fsm->ddd_[fsm->ddd_idx_] = sym->id__[0];
      ++fsm->ddd_idx_;
      fsm->ddd_[fsm->ddd_idx_] = 0;
  
}
RUPPER_N_Z::RUPPER_N_Z(yacco2::Parser* P)
 :CAbs_lr1_sym
  ("RUPPER_N_Z",0,Cidentifier::R_RUPPER_N_Z_,P,false,false){
}

void RUPPER_N_Z::op(){
  sstrace_rulesss
 
    Cidentifier* fsm = (Cidentifier*) rule_info__.parser__->fsm_tbl__;
    size_t pos = rule_info__.parser__->parse_stack__.top_sub__ - 1;
    CAbs_lr1_sym* sym = rule_info__.parser__->get_spec_stack_token(pos);
      fsm->ddd_[fsm->ddd_idx_] = sym->id__[0];
      ++fsm->ddd_idx_;
      fsm->ddd_[fsm->ddd_idx_] = 0;
  
}
Rlower_a_m::Rlower_a_m(yacco2::Parser* P)
 :CAbs_lr1_sym
  ("Rlower_a_m",0,Cidentifier::R_Rlower_a_m_,P,false,false){
}

void Rlower_a_m::op(){
  sstrace_rulesss
 
    Cidentifier* fsm = (Cidentifier*) rule_info__.parser__->fsm_tbl__;
    size_t pos = rule_info__.parser__->parse_stack__.top_sub__ - 1;
    CAbs_lr1_sym* sym = rule_info__.parser__->get_spec_stack_token(pos);
      fsm->ddd_[fsm->ddd_idx_] = sym->id__[0];
      ++fsm->ddd_idx_;
      fsm->ddd_[fsm->ddd_idx_] = 0;
  
}
Rlower_n_z::Rlower_n_z(yacco2::Parser* P)
 :CAbs_lr1_sym
  ("Rlower_n_z",0,Cidentifier::R_Rlower_n_z_,P,false,false){
}

void Rlower_n_z::op(){
  sstrace_rulesss
 
    Cidentifier* fsm = (Cidentifier*) rule_info__.parser__->fsm_tbl__;
    size_t pos = rule_info__.parser__->parse_stack__.top_sub__ - 1;
    CAbs_lr1_sym* sym = rule_info__.parser__->get_spec_stack_token(pos);
      fsm->ddd_[fsm->ddd_idx_] = sym->id__[0];
      ++fsm->ddd_idx_;
      fsm->ddd_[fsm->ddd_idx_] = 0;
  
}
RNUMBERS::RNUMBERS(yacco2::Parser* P)
 :CAbs_lr1_sym
  ("RNUMBERS",0,Cidentifier::R_RNUMBERS_,P,false,false){
}

void RNUMBERS::op(){
  sstrace_rulesss
 
    Cidentifier* fsm = (Cidentifier*) rule_info__.parser__->fsm_tbl__;
    size_t pos = rule_info__.parser__->parse_stack__.top_sub__ - 1;
    CAbs_lr1_sym* sym = rule_info__.parser__->get_spec_stack_token(pos);
      fsm->ddd_[fsm->ddd_idx_] = sym->id__[0];
      ++fsm->ddd_idx_;
      fsm->ddd_[fsm->ddd_idx_] = 0;
  
}
