/*
 File: pass3.cpp
 Date and Time: Fri Jan 30 18:55:20 2015 
*/
#include "pass3.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_pass3;// grammar's ns
// first set terminals
fsm_rules_reuse_table_type::fsm_rules_reuse_table_type(){
 no_rules_entries_ = 4;
 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();
}
  Cpass3::
  Cpass3()
    :yacco2::CAbs_fsm
      ("pass3.lex"
      ,"1.0"
      ,"17 Apr 2001"
      ,false
      ,"\\O2's lexer constructing tokens for syntax parser stage."
      ,"Fri Jan 30 18:55:20 2015 "
      ,S1_Cpass3){
    
  }
 
Cpass3::~Cpass3(){

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

  bool Cpass3::failed(){
      return false;
  }
  void Cpass3::op(){
    ++Cpass3::nested_use_cnt_;  
  
}
int Cpass3::rhs_to_rules_mapping_[22] = {
 -1
 ,0 // subrule 1 for rule 1
 ,0 // subrule 2 for rule 1
 ,1 // subrule 3 for rule 2
 ,1 // subrule 4 for rule 2
 ,2 // subrule 5 for rule 3
 ,2 // subrule 6 for rule 3
 ,2 // subrule 7 for rule 3
 ,2 // subrule 8 for rule 3
 ,2 // subrule 9 for rule 3
 ,2 // subrule 10 for rule 3
 ,2 // subrule 11 for rule 3
 ,2 // subrule 12 for rule 3
 ,2 // subrule 13 for rule 3
 ,2 // subrule 14 for rule 3
 ,2 // subrule 15 for rule 3
 ,2 // subrule 16 for rule 3
 ,2 // subrule 17 for rule 3
 ,2 // subrule 18 for rule 3
 ,3 // subrule 19 for rule 4
 ,3 // subrule 20 for rule 4
 ,3 // subrule 21 for rule 4
}; 

    int Cpass3::nested_use_cnt_(0);
  
Rpass3::Rpass3(yacco2::Parser* P)
 :CAbs_lr1_sym
  ("Rpass3",0,Cpass3::R_Rpass3_,P,false,false){
}

void Rpass3::op(){
  sstrace_rulesss
 
    using namespace NS_yacco2_k_symbols;
    if(Cpass3::nested_use_cnt_ == 1){
       ADD_TOKEN_TO_PRODUCER_QUEUE(*yacco2::PTR_LR1_eog__);   
       ADD_TOKEN_TO_PRODUCER_QUEUE(*yacco2::PTR_LR1_eog__);  
    } 
    --Cpass3::nested_use_cnt_; 
  
}
void Rpass3::sr1(){
  
        CAbs_lr1_sym* sym = new Err_empty_file;
        sym->set_rc(*rule_info__.parser__->current_token(),__FILE__,__LINE__);
        ADD_TOKEN_TO_ERROR_QUEUE(*sym);
        rule_info__.parser__->set_abort_parse(true);
    
}

void Rpass3::sr2(){
  
      if (GRAMMAR_TREE == 0){
        CAbs_lr1_sym* sym = new Err_empty_file;
        sym->set_rc(*rule_info__.parser__->current_token(),__FILE__,__LINE__);
        ADD_TOKEN_TO_ERROR_QUEUE(*sym);
        rule_info__.parser__->set_abort_parse(true);
      }
    
}

Relems::Relems(yacco2::Parser* P)
 :CAbs_lr1_sym
  ("Relems",0,Cpass3::R_Relems_,P,false,false){
}

Rtoken::Rtoken(yacco2::Parser* P)
 :CAbs_lr1_sym
  ("Rtoken",0,Cpass3::R_Rtoken_,P,false,false){
}

void Rtoken::sr3(){
  struct SF{
   LR1_parallel_operator* p1__;
   State* s1__;
   bool abort1__;
   Rule_s_reuse_entry* rule_s_reuse_entry1__;
   T_identifier* p2__;
   State* s2__;
   bool abort2__;
   Rule_s_reuse_entry* rule_s_reuse_entry2__;
  };
  SF* sf = (SF*)rule_info__.parser__->parse_stack__.sf_by_top(2);
  
      sf->p2__->set_auto_delete(true);
      CAbs_lr1_sym* sym = new Err_misplaced_or_misspelt_Rule_or_T;
      sym->set_rc(*sf->p2__,__FILE__,__LINE__);
      ADD_TOKEN_TO_ERROR_QUEUE(*sym);
      rule_info__.parser__->set_abort_parse(true);
    
}

void Rtoken::sr4(){
  struct SF{
   LR1_parallel_operator* p1__;
   State* s1__;
   bool abort1__;
   Rule_s_reuse_entry* rule_s_reuse_entry1__;
   CAbs_lr1_sym* p2__;
   State* s2__;
   bool abort2__;
   Rule_s_reuse_entry* rule_s_reuse_entry2__;
  };
  SF* sf = (SF*)rule_info__.parser__->parse_stack__.sf_by_top(2);
  
      CAbs_lr1_sym* key = sf->p2__;// extract specific keyword
      yacco2::INT cont_pos = rule_info__.parser__->current_token_pos__;
      CAbs_lr1_sym* cont_tok = rule_info__.parser__->current_token();
      bool result = 
	PROCESS_KEYWORD_FOR_SYNTAX_CODE(*rule_info__.parser__,key,&cont_tok,&cont_pos);
      if(result == false){
        rule_info__.parser__->set_abort_parse(true);
        return;
      }
      ADD_TOKEN_TO_PRODUCER_QUEUE(*key);
      // adv. to phrase's LA pos
      rule_info__.parser__->override_current_token(*cont_tok,cont_pos);
    
}

void Rtoken::sr5(){
  struct SF{
   LR1_parallel_operator* p1__;
   State* s1__;
   bool abort1__;
   Rule_s_reuse_entry* rule_s_reuse_entry1__;
   rule_in_stbl* p2__;
   State* s2__;
   bool abort2__;
   Rule_s_reuse_entry* rule_s_reuse_entry2__;
  };
  SF* sf = (SF*)rule_info__.parser__->parse_stack__.sf_by_top(2);
  
      sf->p2__->set_auto_delete(true);
      CAbs_lr1_sym* sym = new Err_use_of_N_outside_Rules_construct;
      sym->set_rc(*sf->p2__,__FILE__,__LINE__);
      ADD_TOKEN_TO_ERROR_QUEUE(*sym);
      rule_info__.parser__->set_abort_parse(true);
    
}

void Rtoken::sr6(){
  struct SF{
   LR1_parallel_operator* p1__;
   State* s1__;
   bool abort1__;
   Rule_s_reuse_entry* rule_s_reuse_entry1__;
   T_in_stbl* p2__;
   State* s2__;
   bool abort2__;
   Rule_s_reuse_entry* rule_s_reuse_entry2__;
  };
  SF* sf = (SF*)rule_info__.parser__->parse_stack__.sf_by_top(2);
  
      sf->p2__->set_auto_delete(true);
      CAbs_lr1_sym* sym = new Err_use_of_T_outside_Rules_construct;
      sym->set_rc(*sf->p2__,__FILE__,__LINE__);
      ADD_TOKEN_TO_ERROR_QUEUE(*sym);
      rule_info__.parser__->set_abort_parse(true);
    
}

void Rtoken::sr8(){
  struct SF{
   LR1_parallel_operator* p1__;
   State* s1__;
   bool abort1__;
   Rule_s_reuse_entry* rule_s_reuse_entry1__;
   T_comment* p2__;
   State* s2__;
   bool abort2__;
   Rule_s_reuse_entry* rule_s_reuse_entry2__;
  };
  SF* sf = (SF*)rule_info__.parser__->parse_stack__.sf_by_top(2);
  
      T_comment* k = sf->p2__;
      k->set_auto_delete(true);
    
}

void Rtoken::sr9(){
  struct SF{
   LR1_parallel_operator* p1__;
   State* s1__;
   bool abort1__;
   Rule_s_reuse_entry* rule_s_reuse_entry1__;
   T_cweb_comment* p2__;
   State* s2__;
   bool abort2__;
   Rule_s_reuse_entry* rule_s_reuse_entry2__;
  };
  SF* sf = (SF*)rule_info__.parser__->parse_stack__.sf_by_top(2);
  
      T_cweb_comment* k = sf->p2__;
      AST* cwebk_t_ = new AST(*k);

      AST* cweb_t_ = new AST();
      T_cweb_marker* cw = new T_cweb_marker(cweb_t_); 
      cw->set_rc(*k,__FILE__,__LINE__);
      AST::set_content(*cweb_t_,*cw);
      AST::join_pts(*cweb_t_,*cwebk_t_);
        BUILD_GRAMMAR_TREE(*cweb_t_);
	CWEB_MARKER = 0;	
    
}

void Rtoken::sr10(){
  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_not_kw_defining_grammar_construct;
      sym->set_rc(*sf->p1__,__FILE__,__LINE__);
      ADD_TOKEN_TO_ERROR_QUEUE(*sym);
      rule_info__.parser__->set_abort_parse(true);
    
}

void Rtoken::sr11(){
  struct SF{
   LR1_parallel_operator* p1__;
   State* s1__;
   bool abort1__;
   Rule_s_reuse_entry* rule_s_reuse_entry1__;
   Err_bad_eos* p2__;
   State* s2__;
   bool abort2__;
   Rule_s_reuse_entry* rule_s_reuse_entry2__;
  };
  SF* sf = (SF*)rule_info__.parser__->parse_stack__.sf_by_top(2);
  
      ADD_TOKEN_TO_ERROR_QUEUE(*sf->p2__);
      rule_info__.parser__->set_abort_parse(true);
    
}

void Rtoken::sr12(){
  struct SF{
   LR1_parallel_operator* p1__;
   State* s1__;
   bool abort1__;
   Rule_s_reuse_entry* rule_s_reuse_entry1__;
   Err_comment_overrun* p2__;
   State* s2__;
   bool abort2__;
   Rule_s_reuse_entry* rule_s_reuse_entry2__;
  };
  SF* sf = (SF*)rule_info__.parser__->parse_stack__.sf_by_top(2);
  
      ADD_TOKEN_TO_ERROR_QUEUE(*sf->p2__);
      rule_info__.parser__->set_abort_parse(true);
    
}

void Rtoken::sr13(){
  struct SF{
   LR1_parallel_operator* p1__;
   State* s1__;
   bool abort1__;
   Rule_s_reuse_entry* rule_s_reuse_entry1__;
   Err_bad_esc* p2__;
   State* s2__;
   bool abort2__;
   Rule_s_reuse_entry* rule_s_reuse_entry2__;
  };
  SF* sf = (SF*)rule_info__.parser__->parse_stack__.sf_by_top(2);
  
      ADD_TOKEN_TO_ERROR_QUEUE(*sf->p2__);
      rule_info__.parser__->set_abort_parse(true);
    
}

void Rtoken::sr14(){
  struct SF{
   LR1_parallel_operator* p1__;
   State* s1__;
   bool abort1__;
   Rule_s_reuse_entry* rule_s_reuse_entry1__;
   Err_bad_char* p2__;
   State* s2__;
   bool abort2__;
   Rule_s_reuse_entry* rule_s_reuse_entry2__;
  };
  SF* sf = (SF*)rule_info__.parser__->parse_stack__.sf_by_top(2);
  
      Err_bad_char* k = sf->p2__;
      ADD_TOKEN_TO_ERROR_QUEUE(*k);
      rule_info__.parser__->set_abort_parse(true);
    
}

Rprefile_inc_dispatcher::Rprefile_inc_dispatcher(yacco2::Parser* P)
 :CAbs_lr1_sym
  ("Rprefile_inc_dispatcher",0,Cpass3::R_Rprefile_inc_dispatcher_,P,false,false){
}

void Rprefile_inc_dispatcher::sr1(){
  struct SF{
   LR1_fset_transience_operator* p1__;
   State* s1__;
   bool abort1__;
   Rule_s_reuse_entry* rule_s_reuse_entry1__;
   T_file_inclusion* p2__;
   State* s2__;
   bool abort2__;
   Rule_s_reuse_entry* rule_s_reuse_entry2__;
  };
  SF* sf = (SF*)rule_info__.parser__->parse_stack__.sf_by_top(2);
  
          CAbs_lr1_sym* err = sf->p2__->error_sym();
          if(err != 0) {
            rule_info__.parser__->set_abort_parse(true);
            ADD_TOKEN_TO_ERROR_QUEUE(*sf->p2__); 
            ADD_TOKEN_TO_ERROR_QUEUE(*sf->p2__->error_sym()); 
            return;
          }
           bool result = PROCESS_INCLUDE_FILE(*rule_info__.parser__
		,*sf->p2__,*rule_info__.parser__->token_producer__);
          if(result == false){ // exceeded nested file limit
            rule_info__.parser__->set_abort_parse(true);
            return;
          }
          ADD_TOKEN_TO_RECYCLE_BIN(*sf->p2__);//file name inside
          return;
    
}

void Rprefile_inc_dispatcher::sr2(){
  struct SF{
   LR1_fset_transience_operator* p1__;
   State* s1__;
   bool abort1__;
   Rule_s_reuse_entry* rule_s_reuse_entry1__;
   CAbs_lr1_sym* p2__;
   State* s2__;
   bool abort2__;
   Rule_s_reuse_entry* rule_s_reuse_entry2__;
  };
  SF* sf = (SF*)rule_info__.parser__->parse_stack__.sf_by_top(2);
  
        sf->p2__->set_auto_delete(true);
        CAbs_lr1_sym* sym = new Err_bad_directive;
        sym->set_rc(*sf->p2__,__FILE__,__LINE__);
        RSVP(sym);
        rule_info__.parser__->set_stop_parse(true);
      
}

void Rprefile_inc_dispatcher::sr3(){
  
        CAbs_lr1_sym* sym = new Err_no_directive_present;
        sym->set_rc(*rule_info__.parser__->current_token(),__FILE__,__LINE__);
        RSVP(sym);
        rule_info__.parser__->set_stop_parse(true);
      
}

