/*
 File: xc_str.cpp
 Date and Time: Fri Jan 30 18:55:28 2015 
*/
#include "xc_str.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_xc_str;// grammar's ns
// first set terminals
fsm_rules_reuse_table_type::fsm_rules_reuse_table_type(){
 no_rules_entries_ = 2;
 per_rule_s_table_[0] =  new Per_rule_s_reuse_table();
 per_rule_s_table_[1] =  new Per_rule_s_reuse_table();
}
  Cxc_str::
  Cxc_str()
    :yacco2::CAbs_fsm
      ("xc_str.lex"
      ,"1.0"
      ,"27 Juin 2005"
      ,false
      ,"No escape sequence check: accept all characters between dbl. quoted string."
      ,"Fri Jan 30 18:55:28 2015 "
      ,S1_Cxc_str){
    
    ddd_idx_ = 0;
    ddd_[ddd_idx_] = 0;
 
  }
 
Cxc_str::~Cxc_str(){

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

  bool Cxc_str::failed(){
      return false;
  }
  void Cxc_str::op(){
    ddd_idx_ = 0;
    ddd_[ddd_idx_] = 0;
  
}
int Cxc_str::rhs_to_rules_mapping_[3] = {
 -1
 ,0 // subrule 1 for rule 1
 ,1 // subrule 2 for rule 2
}; 

    void Cxc_str::copy_str_into_buffer(std::string* Str){   
      const char* y = Str->c_str(); 
      int x(0);
      for(;y[x]!=0;++x,++ddd_idx_)ddd_[ddd_idx_] = y[x];
      ddd_[ddd_idx_] = 0;
    }
    void Cxc_str::copy_kstr_into_buffer(const char* Str){
      const char* y = Str; 
      int x(0);
      for(;y[x]!=0;++x,++ddd_idx_)ddd_[ddd_idx_] = y[x];
      ddd_[ddd_idx_] = 0;
    }
  
Rxc_str::Rxc_str(yacco2::Parser* P)
 :CAbs_lr1_sym
  ("Rxc_str",0,Cxc_str::R_Rxc_str_,P,false,false){
}

void Rxc_str::sr1(){
  
    Cxc_str* fsm = (Cxc_str*) rule_info__.parser__->fsm_tbl__;
    CAbs_lr1_sym* sym = new T_xc_str((const char*)&fsm->ddd_);
    sym->set_rc(*rule_info__.parser__->start_token__,__FILE__,__LINE__);
    sym->set_line_no_and_pos_in_line(*rule_info__.parser__->start_token__);
    RSVP(sym);
  
}

Rquote::Rquote(yacco2::Parser* P)
 :CAbs_lr1_sym
  ("Rquote",0,Cxc_str::R_Rquote_,P,false,false){
}

void Rquote::sr1(){
  		
	  Cxc_str* fsm = (Cxc_str*) rule_info__.parser__->fsm_tbl__;
loop:
	  switch (rule_info__.parser__->current_token()->enumerated_id__){
	  case T_Enum::T_raw_lf_: goto overrun;
	  case T_Enum::T_raw_cr_: goto overrun;
	  case T_Enum::T_LR1_eog_: goto overrun;	
	  case T_Enum::T_raw_dbl_quote_: goto dblquote;
          default: goto other;
          }
    dblquote:{ // end of string
          rule_info__.parser__->get_next_token();
        if(rule_info__.parser__->current_token()->enumerated_id__ 
            == T_Enum::T_raw_dbl_quote_){
        fsm->copy_kstr_into_buffer("\"");// due to lex scanner
        fsm->copy_kstr_into_buffer("\"");
           rule_info__.parser__->get_next_token();
           goto loop;
        }
        return;// end of c string
    }
    overrun:{
      CAbs_lr1_sym* sym = new Err_bad_eos;
      sym->set_rc(*rule_info__.parser__->start_token__,__FILE__,__LINE__);
      sym->set_line_no_and_pos_in_line(*rule_info__.parser__->start_token__);
      RSVP(sym);
      rule_info__.parser__->set_stop_parse(true);
      return;
    }
    other:{
        fsm->copy_kstr_into_buffer(rule_info__.parser__->current_token()->id__);
          rule_info__.parser__->get_next_token();
goto loop;
      }
    
}

