view tests/agcl/oldagsrc/good/bcip.h @ 21:1c9dac05d040

Add lint-style FALLTHROUGH annotations to fallthrough cases. (in the parse engine and thus the output code) Document this, because the old output causes warnings with gcc10.
author David A. Holland
date Mon, 13 Jun 2022 00:04:38 -0400
parents 13d2b8934445
children
line wrap: on
line source

#ifndef BCIP_H
#define BCIP_H

#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_4[sizeof(AgObjectWrapper<CodeFragment >)];
  char ag_vt_5[sizeof(double)];
} bciParse_vs_type;

typedef enum {
  bciParse_white_space_token = 1, bciParse_input_string_token = 4,
  bciParse_statements_token, bciParse_eof_token, bciParse_statement_token,
  bciParse_open_statement_token, bciParse_closed_statement_token,
  bciParse_if_clause_token, bciParse_while_clause_token = 12,
  bciParse_expression_token = 15, bciParse_simple_statement_token = 18,
  bciParse_assignment_expression_token = 24,
  bciParse_conditional_expression_token = 26,
  bciParse_logical_or_expression_token = 32,
  bciParse_logical_and_expression_token = 35,
  bciParse_equality_expression_token = 37,
  bciParse_relational_expression_token = 39,
  bciParse_additive_expression_token = 42,
  bciParse_multiplicative_expression_token = 47,
  bciParse_unary_expression_token = 50, bciParse_factor_token = 53,
  bciParse_primary_token, bciParse_simple_real_token = 71,
  bciParse_exponent_token = 74, bciParse_integer_part_token,
  bciParse_fraction_part_token = 77, bciParse_digit_token = 79,
  bciParse_name_string_token, bciParse_letter_token,
  bciParse_name_token = 100, bciParse_real_token = 120
} bciParse_token_type;

typedef struct bciParse_pcb_struct{
  bciParse_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];
  bciParse_vs_type vs[128];
  int ag_ap;
  const char *error_message;
  char read_flag;
  char exit_flag;
  int bts[128], btsx;
  unsigned char * pointer;
  unsigned char * la_ptr;
  const unsigned char *key_sp;
  int save_index, key_state;
  char ag_msg[82];
/*  Line -, bcip.syn */
    AgStringDictionary *symbolDictionary;
    AgStack<double> realList;                         // List of real constants
    int compile(AgStringDictionary *, AgString);
    CodeFragment code;

    AgCharStack charStack;           // Stack to accumulate variable names
    int locateVariable(int k);    // Identify variable named on character stack
    int stashReal(double);
    CodeFragment codeIfElse(CodeFragment &, CodeFragment &, CodeFragment &);
    CodeFragment codeWhile(CodeFragment &, CodeFragment &);
    CodeFragment codeDoWhile(CodeFragment &, CodeFragment &);
    CodeFragment codeFor(CodeFragment &, CodeFragment &, CodeFragment &, CodeFragment &);
  } bciParse_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
/* 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_bciParse(bciParse_pcb_type *);
void bciParse(bciParse_pcb_type *);

CodeFragment bciParse_value(bciParse_pcb_type *);
#endif