Annotation of parser3/src/main/compile_tools.h, revision 1.10
1.1 paf 1: /*
1.10 ! paf 2: $Id: compile_tools.h,v 1.9 2001/02/22 13:52:26 paf Exp $
1.1 paf 3: */
4:
5: #ifndef COMPILE_TOOLS
6: #define COMPILE_TOOLS
7:
8: #include "code.h"
9: #include "pa_types.h"
1.6 paf 10: #include "pa_pool.h"
11: #include "pa_array.h"
1.9 paf 12: #include "pa_string.h"
1.10 ! paf 13: #include "pa_vstring.h"
1.1 paf 14:
15: enum lexical_state {
16: LS_USER,
1.7 paf 17: LS_DEF_NAME,
18: LS_DEF_PARAMS,
19: LS_DEF_LOCALS,
20: LS_DEF_COMMENT,
1.1 paf 21: LS_VAR_NAME_SIMPLE,
22: LS_VAR_NAME_CURLY,
23: LS_VAR_ROUND,
24: LS_VAR_CURLY,
25: LS_METHOD_NAME,
26: LS_METHOD_ROUND,
27: LS_METHOD_CURLY,
28: LS_METHOD_AFTER
29: };
30: struct parse_control {
31: /* input */
1.3 paf 32: Pool *pool;
1.6 paf 33: Array *methods;
1.1 paf 34: #ifndef NO_CSTRING_ORIGIN
35: char *source;
36: char *file;
1.4 paf 37: int line, col;
1.1 paf 38: #endif
39: /* state */
40: int pending_state/*=0*/;
1.3 paf 41: String *string/*=new(pool) String(pool)*/;
1.1 paf 42:
43: #define MAX_LEXICAL_STATES 100
44: enum lexical_state ls/*=LS_USER*/;
45: int sp/*=0*/;
46: enum lexical_state stack[MAX_LEXICAL_STATES];
47: int brackets_nestages[MAX_LEXICAL_STATES];
48:
1.6 paf 49: /* output: filled input 'methods' and 'error' if any */
1.5 paf 50: char error[MAX_STRING];
1.1 paf 51: };
52:
1.3 paf 53: /* New array // return empty array */
1.6 paf 54: inline Array/*<op>*/ *N(Pool& pool) {
55: return new(pool) Array/*<op>*/(pool);
1.3 paf 56: }
57:
58: /* Assembler instruction // append ordinary instruction to ops */
59: inline void OP(Array/*<op>*/ *result, enum OPCODE code) {
60: Operation op; op.code=code;
61: *result+=op.cast;
62: }
63:
64: /* Argument String // append String to ops*/
65: inline void AS(Array/*<op>*/ *result, String *string) {
66: *result+=string;
67: }
68: /* Argument Array // append Array to ops */
69: inline void AA(Array/*<op>*/ *result, Array/*<op>*/ *array) {
70: *result+=array;
71: }
72: /* Argument Eval_expression // append eval_expression to ops */
73: inline void AE(Array/*<op>*/ *result, char *eval_expression) {
74: *result+=eval_expression;
75: }
76:
77: inline void P(Array/*<op>*/ *result, Array *code_array) {
78: result->append_array(*code_array);
79: }
1.1 paf 80:
81:
1.3 paf 82: /* Literal // returns array with
83: // first: OP_STRING instruction
84: // second op: string itself
85: */
1.10 ! paf 86: Array *L(VString *vstring);
1.3 paf 87: /* Literal Array to(2) String // return string value from literal array OP+string array */
1.7 paf 88: String *LA2S(Array *literal_string_array, int offset=0);
1.1 paf 89:
1.7 paf 90: void push_LS(struct parse_control *pc, lexical_state new_state);
1.3 paf 91: void pop_LS(struct parse_control *pc);
1.1 paf 92:
93: #endif
E-mail: