1
|
1 // tree-base.h -*- C++ -*- |
|
2 /* |
|
3 |
|
4 Copyright (C) 1992, 1993 John W. Eaton |
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
|
20 Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
21 |
|
22 */ |
|
23 |
|
24 #if !defined (_tree_base_h) |
|
25 #define _tree_base_h 1 |
|
26 |
191
|
27 #include <stdio.h> |
|
28 #include <time.h> |
|
29 #include <assert.h> |
|
30 |
1
|
31 #ifndef NULL_TREE |
|
32 #define NULL_TREE (tree *)NULL |
|
33 #endif |
|
34 |
|
35 #ifndef NULL_TREE_CONST |
|
36 #define NULL_TREE_CONST (tree_constant *)NULL |
|
37 #endif |
|
38 |
164
|
39 class ostream; |
1
|
40 class tree_constant; |
|
41 class tree_identifier; |
|
42 class tree_argument_list; |
|
43 |
|
44 /* |
|
45 * Base class for the parse tree. |
|
46 */ |
|
47 class |
|
48 tree |
|
49 { |
|
50 public: |
|
51 enum matrix_dir |
|
52 { |
|
53 md_none, |
|
54 md_right, |
|
55 md_down, |
|
56 }; |
|
57 |
|
58 enum expression_type |
|
59 { |
|
60 unknown, |
|
61 assignment, |
|
62 simple_assignment, |
|
63 multi_assignment, |
|
64 add, |
|
65 subtract, |
|
66 multiply, |
|
67 el_mul, |
|
68 divide, |
|
69 el_div, |
|
70 leftdiv, |
|
71 el_leftdiv, |
|
72 power, |
|
73 elem_pow, |
|
74 cmp_lt, |
|
75 cmp_le, |
|
76 cmp_eq, |
|
77 cmp_ge, |
|
78 cmp_gt, |
|
79 cmp_ne, |
|
80 and, |
|
81 or, |
|
82 not, |
|
83 unot, |
|
84 uminus, |
|
85 hermitian, |
|
86 transpose, |
|
87 colon, |
|
88 index, |
|
89 increment, |
|
90 decrement, |
|
91 }; |
|
92 |
|
93 virtual ~tree (void) { } |
|
94 |
|
95 // Only the finest cheese... |
164
|
96 virtual int is_identifier (void) const |
1
|
97 { return 0; } |
|
98 |
164
|
99 virtual int is_constant (void) const |
1
|
100 { return 0; } |
|
101 |
164
|
102 virtual int is_builtin (void) const |
1
|
103 { return 0; } |
|
104 |
164
|
105 virtual int is_index_expression (void) const |
1
|
106 { return 0; } |
|
107 |
164
|
108 virtual int is_assignment_expression (void) const |
1
|
109 { return 0; } |
|
110 |
195
|
111 virtual int is_prefix_expression (void) const |
|
112 { return 0; } |
|
113 |
200
|
114 virtual char *name (void) const |
1
|
115 { assert (0); return (char *) NULL; } |
|
116 |
|
117 virtual int max_expected_args (void) |
|
118 { assert (0); return 0; } |
|
119 |
|
120 virtual void set_print_flag (int print) |
|
121 { assert (0); } |
|
122 |
195
|
123 virtual void mark_for_possible_ans_assign (void) |
|
124 { assert (0); } |
|
125 |
1
|
126 virtual tree_constant assign (tree_constant& t, tree_constant *args, |
|
127 int nargs); |
|
128 |
|
129 virtual void bump_value (tree::expression_type) |
|
130 { assert (0); } |
|
131 |
|
132 virtual char *m_file_name (void) |
|
133 { return (char *) NULL; } |
|
134 |
|
135 virtual time_t time_parsed (void) |
|
136 { assert (0); return 0; } |
|
137 |
195
|
138 virtual int is_system_m_file (void) const |
|
139 { return 0; } |
|
140 |
1
|
141 virtual tree_constant eval (int print) = 0; |
|
142 |
|
143 virtual tree_constant *eval (int print, int nargout); |
|
144 |
|
145 virtual tree_constant eval (int argc, char **argv, int print); |
|
146 |
164
|
147 virtual tree_constant *eval (const tree_constant *args, int n_in, int nout, |
1
|
148 int print) |
|
149 { assert (0); return NULL_TREE_CONST; } |
|
150 |
273
|
151 virtual int save (ostream& os, int mark_as_global = 0, |
|
152 int precision = 17) |
1
|
153 { assert (0); return 0; } |
143
|
154 |
164
|
155 virtual int line (void) const { return line_num; } |
|
156 virtual int column (void) const { return column_num; } |
143
|
157 |
|
158 protected: |
|
159 int line_num; |
|
160 int column_num; |
1
|
161 }; |
|
162 |
|
163 #endif |
|
164 |
|
165 /* |
|
166 ;;; Local Variables: *** |
|
167 ;;; mode: C++ *** |
|
168 ;;; page-delimiter: "^/\\*" *** |
|
169 ;;; End: *** |
|
170 */ |