comparison tests/agcl/oldagsrc/good/bcip.h @ 0:13d2b8934445

Import AnaGram (near-)release tree into Mercurial.
author David A. Holland
date Sat, 22 Dec 2007 17:52:45 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:13d2b8934445
1 #ifndef BCIP_H
2 #define BCIP_H
3
4 #ifndef AG_OBJECT_WRAPPER_DEFINED
5 #define AG_OBJECT_WRAPPER_DEFINED
6
7 #ifndef AG_PLACEMENT_DELETE_REQUIRED
8 #if _MSC_VER >= 1200 || __INTEL_COMPILER
9 #define AG_PLACEMENT_DELETE_REQUIRED 1
10 #endif
11 #endif
12
13 template <class Object>
14 class AgObjectWrapper {
15 Object object;
16 public:
17 void operator delete(void *) {}
18 void *operator new(size_t, void *p) { return p;}
19 #if AG_PLACEMENT_DELETE_REQUIRED
20 void operator delete(void *, void *) { }
21 #endif
22 AgObjectWrapper(const Object &o) : object(o) {}
23 ~AgObjectWrapper() {}
24 operator Object &() {return object;}
25 };
26
27 #endif
28
29 typedef union {
30 double alignment;
31 char ag_vt_2[sizeof(int)];
32 char ag_vt_4[sizeof(AgObjectWrapper<CodeFragment >)];
33 char ag_vt_5[sizeof(double)];
34 } bciParse_vs_type;
35
36 typedef enum {
37 bciParse_white_space_token = 1, bciParse_input_string_token = 4,
38 bciParse_statements_token, bciParse_eof_token, bciParse_statement_token,
39 bciParse_open_statement_token, bciParse_closed_statement_token,
40 bciParse_if_clause_token, bciParse_while_clause_token = 12,
41 bciParse_expression_token = 15, bciParse_simple_statement_token = 18,
42 bciParse_assignment_expression_token = 24,
43 bciParse_conditional_expression_token = 26,
44 bciParse_logical_or_expression_token = 32,
45 bciParse_logical_and_expression_token = 35,
46 bciParse_equality_expression_token = 37,
47 bciParse_relational_expression_token = 39,
48 bciParse_additive_expression_token = 42,
49 bciParse_multiplicative_expression_token = 47,
50 bciParse_unary_expression_token = 50, bciParse_factor_token = 53,
51 bciParse_primary_token, bciParse_simple_real_token = 71,
52 bciParse_exponent_token = 74, bciParse_integer_part_token,
53 bciParse_fraction_part_token = 77, bciParse_digit_token = 79,
54 bciParse_name_string_token, bciParse_letter_token,
55 bciParse_name_token = 100, bciParse_real_token = 120
56 } bciParse_token_type;
57
58 typedef struct bciParse_pcb_struct{
59 bciParse_token_type token_number, reduction_token, error_frame_token;
60 int input_code;
61 int input_value;
62 int line, column;
63 int ssx, sn, error_frame_ssx;
64 int drt, dssx, dsn;
65 int ss[128];
66 bciParse_vs_type vs[128];
67 int ag_ap;
68 const char *error_message;
69 char read_flag;
70 char exit_flag;
71 int bts[128], btsx;
72 unsigned char * pointer;
73 unsigned char * la_ptr;
74 const unsigned char *key_sp;
75 int save_index, key_state;
76 char ag_msg[82];
77 /* Line -, bcip.syn */
78 AgStringDictionary *symbolDictionary;
79 AgStack<double> realList; // List of real constants
80 int compile(AgStringDictionary *, AgString);
81 CodeFragment code;
82
83 AgCharStack charStack; // Stack to accumulate variable names
84 int locateVariable(int k); // Identify variable named on character stack
85 int stashReal(double);
86 CodeFragment codeIfElse(CodeFragment &, CodeFragment &, CodeFragment &);
87 CodeFragment codeWhile(CodeFragment &, CodeFragment &);
88 CodeFragment codeDoWhile(CodeFragment &, CodeFragment &);
89 CodeFragment codeFor(CodeFragment &, CodeFragment &, CodeFragment &, CodeFragment &);
90 } bciParse_pcb_type;
91
92 #ifndef PRULE_CONTEXT
93 #define PRULE_CONTEXT(pcb) (&((pcb).cs[(pcb).ssx]))
94 #define PERROR_CONTEXT(pcb) ((pcb).cs[(pcb).error_frame_ssx])
95 #define PCONTEXT(pcb) ((pcb).cs[(pcb).ssx])
96 #endif
97
98 #ifndef AG_RUNNING_CODE
99 /* PCB.exit_flag values */
100 #define AG_RUNNING_CODE 0
101 #define AG_SUCCESS_CODE 1
102 #define AG_SYNTAX_ERROR_CODE 2
103 #define AG_REDUCTION_ERROR_CODE 3
104 #define AG_STACK_ERROR_CODE 4
105 #define AG_SEMANTIC_ERROR_CODE 5
106 #endif
107 void init_bciParse(bciParse_pcb_type *);
108 void bciParse(bciParse_pcb_type *);
109
110 CodeFragment bciParse_value(bciParse_pcb_type *);
111 #endif
112