/*
 File: mpost_output.h
 Date and Time: Fri Jan 30 18:55:16 2015 
*/
#ifndef __mpost_output_h__
#define __mpost_output_h__ 1
#include "yacco2.h"
#include "yacco2_T_enumeration.h"
#include "yacco2_k_symbols.h"
#include "yacco2_err_symbols.h"
#include "yacco2_terminals.h"
#include "yacco2_characters.h"

#include "time.h"
#include "o2_externs.h"
extern void XLATE_SYMBOLS_FOR_cweave(const char* Sym_to_xlate,char* Xlated_sym);
extern void PRT_RULE_S_FIRST_SET(std::ofstream& Ofile,NS_yacco2_terminals::rule_def* Rule_def);
extern int MPOST_CWEB_xlated_symbol(AST* Sym,char* Xlated_sym);
extern STATES_type LR1_STATES;
extern COMMON_LA_SETS_type COMMON_LA_SETS;
#include "cweave_fsm_sdc.h"
#include "cweave_lhs_sdc.h"
#include "cweave_sdc.h"
#include "cweave_T_sdc.h"
  
// monolithic grammar: no thread
extern yacco2::State S1_Cmpost_output;
namespace NS_mpost_output {
using namespace NS_yacco2_T_enum;// enumerate
using namespace yacco2;
struct fsm_rules_reuse_table_type{
 fsm_rules_reuse_table_type();
 int no_rules_entries_;
 Per_rule_s_reuse_table* per_rule_s_table_[21];
};
class Cmpost_output: public yacco2::CAbs_fsm {
 public:
  enum rules_and_subrules{
   start_of_rule_list = NS_yacco2_T_enum::T_Enum::sum_total_T
   ,R_Rmpost_output_ = 569//start_of_rule_list + 0
    ,rhs1_Rmpost_output_ = 1
   ,R_Rgrammar_phrase_ = 570//start_of_rule_list + 2
    ,rhs1_Rgrammar_phrase_ = 2
   ,R_Rks_epi_ = 571//start_of_rule_list + 4
    ,rhs1_Rks_epi_ = 3
    ,rhs2_Rks_epi_ = 4
   ,R_Rks_ = 572//start_of_rule_list + 6
    ,rhs1_Rks_ = 5
    ,rhs2_Rks_ = 6
   ,R_Rk_ = 573//start_of_rule_list + 8
    ,rhs1_Rk_ = 7
   ,R_Rfsm_phrase_ = 574//start_of_rule_list + 10
    ,rhs1_Rfsm_phrase_ = 8
   ,R_Rparallel_phrase_ = 575//start_of_rule_list + 12
    ,rhs1_Rparallel_phrase_ = 9
    ,rhs2_Rparallel_phrase_ = 10
   ,R_RT_enum_phrase_ = 576//start_of_rule_list + 14
    ,rhs1_RT_enum_phrase_ = 11
   ,R_Rerr_phrase_ = 577//start_of_rule_list + 16
    ,rhs1_Rerr_phrase_ = 12
   ,R_Rrc_phrase_ = 578//start_of_rule_list + 18
    ,rhs1_Rrc_phrase_ = 13
   ,R_Rlr1_k_phrase_ = 579//start_of_rule_list + 20
    ,rhs1_Rlr1_k_phrase_ = 14
   ,R_Rterms_phrase_ = 580//start_of_rule_list + 22
    ,rhs1_Rterms_phrase_ = 15
   ,R_Rrule_phrase_ = 581//start_of_rule_list + 24
    ,rhs1_Rrule_phrase_ = 16
   ,R_Rrules_ = 582//start_of_rule_list + 26
    ,rhs1_Rrules_ = 17
    ,rhs2_Rrules_ = 18
   ,R_Rrule_ = 583//start_of_rule_list + 28
    ,rhs1_Rrule_ = 19
   ,R_Rrule_def_ = 584//start_of_rule_list + 30
    ,rhs1_Rrule_def_ = 20
   ,R_Rsubrules_ = 585//start_of_rule_list + 32
    ,rhs1_Rsubrules_ = 21
    ,rhs2_Rsubrules_ = 22
   ,R_Rsubrule_ = 586//start_of_rule_list + 34
    ,rhs1_Rsubrule_ = 23
   ,R_Rsubrule_def_ = 587//start_of_rule_list + 36
    ,rhs1_Rsubrule_def_ = 24
   ,R_Relements_ = 588//start_of_rule_list + 38
    ,rhs1_Relements_ = 25
    ,rhs2_Relements_ = 26
   ,R_Relement_ = 589//start_of_rule_list + 40
    ,rhs1_Relement_ = 27
    ,rhs2_Relement_ = 28
    ,rhs3_Relement_ = 29
    ,rhs4_Relement_ = 30
    ,rhs5_Relement_ = 31
    ,rhs6_Relement_ = 32
  };
  //no of la sets = 26
  //no of states = 56
  Cmpost_output();
  ~Cmpost_output();
  void op();
  bool failed();
  void reduce_rhs_of_rule
      (yacco2::UINT Sub_rule_no,yacco2::Rule_s_reuse_entry** Recycled_rule);
  fsm_rules_reuse_table_type fsm_rules_reuse_table;
  static int rhs_to_rules_mapping_[33];
  
    public:
	  char big_buf_[BIG_BUFFER_32K];		
	  std::map <int , std::string> xlated_names_;
	  std::vector <int> no_subrules_per_rule_;
	  std::string gened_date_time_;
      std::string mp_filename_;
      std::ofstream omp_file_;
      std::string w_filename_;
      std::string w_index_filename_;
      std::ofstream ow_file_;
      std::ofstream ow_index_file_;
      std::ofstream ow_t_file_;
      std::ofstream ow_err_file_;
      std::ofstream ow_lrk_file_;
      std::string grammar_filename_prefix_;
	  std::string fq_filename_noext_;
      int w_fig_no_;
      int rule_no_;
      int subrule_no_;
      int elem_no_;
      int no_of_rules_;
      int no_of_subrules_;
      std::string rule_name_;
      std::string elem_name_;
	  rule_def* rule_def_;
	  T_subrule_def* subrule_def_;
      std::string mp_dimension_;
   static void MPOST_CWEB_gen_dimension_name(Cmpost_output* Fsm
	,std::string& Mp_obj_name,int Dimension);
   static void MPOST_CWEB_calc_mp_obj_name(Cmpost_output* Fsm
	,std::string& Mp_obj_name,int Elem_no);
   static void MPOST_CWEB_wrt_mp_rhs_elem(Cmpost_output* Fsm
	,std::string& Elem_name,std::string& Drw_how);
   static void MPOST_CWEB_gen_sr_elem_xrefs(Cmpost_output* Fsm
	,AST* Subrule_tree);   
   static void MPOST_CWEB_woutput_sr_sdcode(Cmpost_output* Fsm
	,T_subrule_def* Subrule_def);
   static void MPOST_CWEB_wrt_fsm(Cmpost_output* Fsm
	,T_fsm_phrase* Fsm_phrase);
   static void MPOST_CWEB_wrt_rule_s_lhs_sdc(Cmpost_output* Fsm,
	rule_def* Rule_def);
   static bool MPOST_CWEB_should_subrule_be_printed(Cmpost_output* Fs
	,T_subrule_def* Subrule_def);
   static void MPOST_CWEB_xref_refered_T(Cmpost_output* Fsm
	,refered_T* R_T);
   static void MPOST_CWEB_xref_refered_rule(Cmpost_output* Fsm
	,refered_rule* R_rule);
   static void MPOST_CWEB_LOAD_XLATE_CHRS(Cmpost_output* Fsm);
   static void MPOST_CWEB_EMIT_PREFIX_CODE(Cmpost_output* Fsm);
   static void MPOST_CWEB_wrt_T(Cmpost_output* Fsm
	,T_terminals_phrase* T_phrase);
   static void MPOST_CWEB_wrt_Err(Cmpost_output* Fsm
	,T_error_symbols_phrase* Err_phrase);
   static void MPOST_CWEB_wrt_Lrk(Cmpost_output* Fsm
	,T_lr1_k_phrase* Lrk_phrase);
   std::list<NS_yacco2_terminals::rule_def*> rules_for_fs_prt_;
   static void MPOST_CWEB_crt_rhs_sym_str(state_element* se,std::string* Xlated_str);
  
 };
struct Rmpost_output;
struct Rgrammar_phrase;
struct Rks_epi;
struct Rks;
struct Rk;
struct Rfsm_phrase;
struct Rparallel_phrase;
struct RT_enum_phrase;
struct Rerr_phrase;
struct Rrc_phrase;
struct Rlr1_k_phrase;
struct Rterms_phrase;
struct Rrule_phrase;
struct Rrules;
struct Rrule;
struct Rrule_def;
struct Rsubrules;
struct Rsubrule;
struct Rsubrule_def;
struct Relements;
struct Relement;
struct Rmpost_output:public yacco2::CAbs_lr1_sym {
  Rmpost_output(yacco2::Parser* P);
  public:
  void sr1();
};

struct Rgrammar_phrase:public yacco2::CAbs_lr1_sym {
  Rgrammar_phrase(yacco2::Parser* P);
  public:
};

struct Rks_epi:public yacco2::CAbs_lr1_sym {
  Rks_epi(yacco2::Parser* P);
  public:
};

struct Rks:public yacco2::CAbs_lr1_sym {
  Rks(yacco2::Parser* P);
  public:
};

struct Rk:public yacco2::CAbs_lr1_sym {
  Rk(yacco2::Parser* P);
  public:
  void sr1();
};

struct Rfsm_phrase:public yacco2::CAbs_lr1_sym {
  Rfsm_phrase(yacco2::Parser* P);
  public:
  void sr1();
};

struct Rparallel_phrase:public yacco2::CAbs_lr1_sym {
  Rparallel_phrase(yacco2::Parser* P);
  public:
};

struct RT_enum_phrase:public yacco2::CAbs_lr1_sym {
  RT_enum_phrase(yacco2::Parser* P);
  public:
};

struct Rerr_phrase:public yacco2::CAbs_lr1_sym {
  Rerr_phrase(yacco2::Parser* P);
  public:
  void sr1();
};

struct Rrc_phrase:public yacco2::CAbs_lr1_sym {
  Rrc_phrase(yacco2::Parser* P);
  public:
};

struct Rlr1_k_phrase:public yacco2::CAbs_lr1_sym {
  Rlr1_k_phrase(yacco2::Parser* P);
  public:
  void sr1();
};

struct Rterms_phrase:public yacco2::CAbs_lr1_sym {
  Rterms_phrase(yacco2::Parser* P);
  public:
  void sr1();
};

struct Rrule_phrase:public yacco2::CAbs_lr1_sym {
  Rrule_phrase(yacco2::Parser* P);
  public:
  void sr1();
};

struct Rrules:public yacco2::CAbs_lr1_sym {
  Rrules(yacco2::Parser* P);
  public:
};

struct Rrule:public yacco2::CAbs_lr1_sym {
  Rrule(yacco2::Parser* P);
  public:
};

struct Rrule_def:public yacco2::CAbs_lr1_sym {
  Rrule_def(yacco2::Parser* P);
  public:
  void sr1();
};

struct Rsubrules:public yacco2::CAbs_lr1_sym {
  Rsubrules(yacco2::Parser* P);
  public:
};

struct Rsubrule:public yacco2::CAbs_lr1_sym {
  Rsubrule(yacco2::Parser* P);
  public:
};

struct Rsubrule_def:public yacco2::CAbs_lr1_sym {
  Rsubrule_def(yacco2::Parser* P);
  public:
  void sr1();
};

struct Relements:public yacco2::CAbs_lr1_sym {
  Relements(yacco2::Parser* P);
  public:
};

struct Relement:public yacco2::CAbs_lr1_sym {
  Relement(yacco2::Parser* P);
  public:
  void sr1();
  void sr2();
  void sr3();
  void sr4();
  void sr5();
  void sr6();
};

} // end of namespace

#endif
