#ifndef DXI_H_1031146419
#define DXI_H_1031146419

#ifndef AG_OBJECT_WRAPPER_DEFINED
#define AG_OBJECT_WRAPPER_DEFINED

#ifndef AG_PLACEMENT_DELETE_REQUIRED
#if _MSC_VER >= 1200 || __INTEL_COMPILER
#define AG_PLACEMENT_DELETE_REQUIRED 1
#endif
#endif

template <class Object>
class AgObjectWrapper {
  Object object;
public:
  void operator delete(void *) {}
  void *operator new(size_t, void *p) { return p;}
#if AG_PLACEMENT_DELETE_REQUIRED
  void operator delete(void *, void *) { }
#endif
  AgObjectWrapper(const Object &o) : object(o) {}
  ~AgObjectWrapper() {}
  operator Object &() {return object;}
};

#endif

typedef union {
  double alignment;
  char ag_vt_2[sizeof(int)];
  char ag_vt_3[sizeof(long)];
  char ag_vt_4[sizeof(AgObjectWrapper<AgString >)];
  char ag_vt_5[sizeof(AgObjectWrapper<Value >)];
  char ag_vt_6[sizeof(AgObjectWrapper<AgStack<Value> >)];
  char ag_vt_7[sizeof(AgObjectWrapper<ForControl >)];
  char ag_vt_8[sizeof(AgObjectWrapper<AgStack<AgString> >)];
  char ag_vt_9[sizeof(double)];
} dxi_vs_type;

typedef enum {
  dxi_white_space_token = 1, dxi_syntax_selection_token = 11,
  dxi_statement_list_token, dxi_eof_token, dxi_loop_condition_token,
  dxi_statement_token = 16, dxi_UNTIL_token, dxi_until_condition_token,
  dxi_open_statement_token = 24, dxi_closed_statement_token,
  dxi_if_condition_token, dxi_ELSE_token, dxi_simple_statement_token,
  dxi_REPEAT_token, dxi_WHILE_token, dxi_for_initialization_token,
  dxi_assignment_statement_token, dxi_compound_statement_token,
  dxi_optional_expression_token = 35, dxi_dump_statement_token,
  dxi_print_statement_token, dxi_structure_declaration_token,
  dxi_FOR_token = 42, dxi_expression_token = 44, dxi_lvalue_token,
  dxi_for_increment_token = 47, dxi_name_list_token = 60,
  dxi_simple_expression_token = 62, dxi_term_token = 69,
  dxi_unary_expression_token = 74, dxi_factor_token = 82,
  dxi_primary_token = 84, dxi_constant_token = 88, dxi_function_call_token,
  dxi_optional_arg_list_token = 93, dxi_arg_list_token, dxi_string_token,
  dxi_space_token, dxi_letter_token = 107, dxi_simple_real_token = 109,
  dxi_signed_exponent_token = 111, dxi_integer_part_token,
  dxi_fraction_part_token, dxi_decimal_integer_token,
  dxi_hybrid_integer_token, dxi_octal_integer_token,
  dxi_exponent_token = 118, dxi_digit_token, dxi_hex_integer_token,
  dxi_hex_digit_token = 127, dxi_s_char_sequence_token = 130,
  dxi_s_char_token, dxi_escape_sequence_token = 133,
  dxi_simple_escape_sequence_token, dxi_octal_escape_sequence_token,
  dxi_hexadecimal_escape_sequence_token, dxi_one_octal_token = 148,
  dxi_two_octal_token, dxi_three_octal_token,
  dxi_hexadecimal_digit_token = 153, dxi_c_char_token = 155,
  dxi_SCRIPT_token = 164, dxi_WHILE_LOOP_token = 166,
  dxi_REPEAT_LOOP_token = 168, dxi_STATEMENT_token, dxi_name_token = 183,
  dxi_integer_token = 214, dxi_real_token, dxi_character_constant_token,
  dxi_string_element_token
} dxi_token_type;

typedef struct dxi_pcb_struct{
  dxi_token_type token_number, reduction_token, error_frame_token;
  int input_code;
  int input_value;
  int line, column;
  int ssx, sn, error_frame_ssx;
  int drt, dssx, dsn;
  int ss[128];
  dxi_vs_type vs[128];
  int ag_ap;
  char *error_message;
  char read_flag;
  char exit_flag;
  ParseContext input_context;
  ParseContext cs[128];
  int bts[128], btsx;
  const unsigned char * pointer;
  const unsigned char * la_ptr;
  const unsigned char *key_sp;
  int save_index, key_state;
  char ag_msg[82];
/*  Line 161, W:/agdev/agex/packages/xidek/pll/struct/dxi.syn */
    Dataset &dataset;                                           // data values
    Mode mode;                                        // Skipping or executing
    FileLocation startLocation;                           // starting location
    Value returnValue;                                          //return value

    // Constructor for parser control block
    dxi_pcb_struct(Dataset &d);
    // Functions used during parsing
    void parseSyntax(const char *select, const FileLocation &start);
    void setStart();
    void simpleLoop(const char *selector);
    ForControl forControl(const Value &,
        const Value &, const Value &, const Value &);
    void forLoop(ForControl &);
    ParseContext location();              // Capture current location of parse
    void setLocation(const FileLocation &l);          // Set location of parse
    void setReturnValue(const Value &v);

    void defineStructure (const AgString &structureName,
                       const AgStack<AgString> &fieldNames);
    void defineInstances (const AgString &structureNameame,
                        const AgStack<AgString> &instanceNames);
    void defineInstances (const AgStack<AgString> &fieldNames,
                        const AgStack<AgString> &instanceNames);

    // Mode changing functions
    int changeMode(Mode currentMode, Mode desiredMode);
    void restoreMode(Mode current);
    void restoreMode();

    void dump(const AgString &) const;         // dump variable name and value
    void print(const Value &) const;

    void reportError();                   // Record error message and location
    void reportError(const char *);       // Record error message and location
	} dxi_pcb_type;

#ifndef PRULE_CONTEXT
#define PRULE_CONTEXT(pcb)  (&((pcb).cs[(pcb).ssx]))
#define PERROR_CONTEXT(pcb) ((pcb).cs[(pcb).error_frame_ssx])
#define PCONTEXT(pcb)       ((pcb).cs[(pcb).ssx])
#endif

#ifndef AG_RUNNING_CODE_CODE
/* PCB.exit_flag values */
#define AG_RUNNING_CODE         0
#define AG_SUCCESS_CODE         1
#define AG_SYNTAX_ERROR_CODE    2
#define AG_REDUCTION_ERROR_CODE 3
#define AG_STACK_ERROR_CODE     4
#define AG_SEMANTIC_ERROR_CODE  5
#endif
void init_dxi(dxi_pcb_type *);
void dxi(dxi_pcb_type *);

Value dxi_value(dxi_pcb_type *);
#endif

