/* File: c_string.cpp Date and Time: Fri Jan 30 18:55:06 2015 */ #include "c_string.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_c_string;// 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(); } Cc_string:: Cc_string() :yacco2::CAbs_fsm ("c_string.lex" ,"1.0" ,"17 Juin 2003" ,false ,"C string lexer." ,"Fri Jan 30 18:55:06 2015 " ,S1_Cc_string){ ddd_idx_ = 0; ddd_[ddd_idx_] = 0; } Cc_string::~Cc_string(){ for(int x = 0;x < 2;++x){ ///delete fsm_rules_reuse_table.per_rule_s_table_[x]; } } bool Cc_string::failed(){ return false; } void Cc_string::op(){ ddd_idx_ = 0; ddd_[ddd_idx_] = 0; } int Cc_string::rhs_to_rules_mapping_[3] = { -1 ,0 // subrule 1 for rule 1 ,1 // subrule 2 for rule 2 }; void Cc_string::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 Cc_string::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; } Rc_string::Rc_string(yacco2::Parser* P) :CAbs_lr1_sym ("Rc_string",0,Cc_string::R_Rc_string_,P,false,false){ } void Rc_string::op(){ sstrace_rulesss Cc_string* fsm = (Cc_string*) rule_info__.parser__->fsm_tbl__; CAbs_lr1_sym* sym = new T_c_string((const char*)&fsm->ddd_); sym->set_rc(*rule_info__.parser__->start_token__,__FILE__,__LINE__); RSVP(sym); } Rquote::Rquote(yacco2::Parser* P) :CAbs_lr1_sym ("Rquote",0,Cc_string::R_Rquote_,P,false,false){ } void Rquote::sr1(){ Cc_string* fsm = (Cc_string*) 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; case T_Enum::T_raw_back_slash_: goto escseq; 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__); RSVP(sym); rule_info__.parser__->set_stop_parse(true); return; } escseq:{// what type of escape using namespace NS_esc_seq; Parser::parse_result result = rule_info__.parser__->start_manually_parallel_parsing(ITH_esc_seq.thd_id__); if(result == Parser::erred){ // in this case, it will not happen: here for education rule_info__.parser__->set_abort_parse(true); return; } // process returned token Caccept_parse& accept_parm = *rule_info__.parser__->arbitrated_token__; CAbs_lr1_sym* rtn_tok = accept_parm.accept_token__; int id = rtn_tok->enumerated_id__; accept_parm.accept_token__ = 0; if(id != T_Enum::T_T_esc_seq_) { RSVP(rtn_tok); return; } T_esc_seq* finc = (T_esc_seq*)(rtn_tok); fsm->copy_str_into_buffer(finc->esc_data()); rule_info__.parser__->override_current_token(*accept_parm.la_token__ ,accept_parm.la_token_pos__); delete finc; goto loop; }; other:{ fsm->copy_kstr_into_buffer(rule_info__.parser__->current_token()->id__); rule_info__.parser__->get_next_token(); goto loop; } }