1739
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
1739
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
7016
|
9 Free Software Foundation; either version 3 of the License, or (at your |
|
10 option) any later version. |
1739
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
7016
|
18 along with Octave; see the file COPYING. If not, see |
|
19 <http://www.gnu.org/licenses/>. |
1739
|
20 |
|
21 */ |
|
22 |
2980
|
23 #if !defined (octave_tree_expr_h) |
|
24 #define octave_tree_expr_h 1 |
1739
|
25 |
2980
|
26 #include <string> |
2124
|
27 |
2879
|
28 class octave_value; |
2979
|
29 class octave_lvalue; |
5861
|
30 class symbol_table; |
2879
|
31 |
2988
|
32 #include "pt.h" |
2124
|
33 |
2980
|
34 // A base class for expressions. |
1739
|
35 |
|
36 class |
2980
|
37 tree_expression : public tree |
2388
|
38 { |
|
39 public: |
|
40 |
2980
|
41 tree_expression (int l = -1, int c = -1) |
|
42 : tree (l, c), num_parens (0), postfix_indexed (false), |
|
43 print_flag (false) { } |
2388
|
44 |
2980
|
45 virtual ~tree_expression (void) { } |
2388
|
46 |
4267
|
47 virtual bool has_magic_end (void) const = 0; |
|
48 |
5861
|
49 virtual tree_expression *dup (symbol_table *) = 0; |
|
50 |
3933
|
51 virtual bool is_constant (void) const { return false; } |
2388
|
52 |
3933
|
53 virtual bool is_matrix_constant (void) const { return false; } |
2388
|
54 |
3933
|
55 virtual bool is_identifier (void) const { return false; } |
1739
|
56 |
3933
|
57 virtual bool is_index_expression (void) const { return false; } |
1739
|
58 |
3933
|
59 virtual bool is_assignment_expression (void) const { return false; } |
1739
|
60 |
3933
|
61 virtual bool is_prefix_expression (void) const { return false; } |
1739
|
62 |
4023
|
63 virtual bool is_binary_expression (void) const { return false; } |
|
64 |
|
65 virtual bool is_boolean_expression (void) const { return false; } |
|
66 |
2980
|
67 virtual bool is_logically_true (const char *); |
1739
|
68 |
3933
|
69 virtual bool lvalue_ok (void) const { return false; } |
1739
|
70 |
3933
|
71 virtual bool rvalue_ok (void) const { return false; } |
2124
|
72 |
2980
|
73 virtual octave_value rvalue (void); |
1739
|
74 |
2980
|
75 virtual octave_value_list rvalue (int nargout); |
2879
|
76 |
2980
|
77 virtual octave_lvalue lvalue (void); |
2879
|
78 |
3933
|
79 int paren_count (void) const { return num_parens; } |
2124
|
80 |
3933
|
81 bool is_postfix_indexed (void) const { return postfix_indexed; } |
2124
|
82 |
3933
|
83 bool print_result (void) const { return print_flag; } |
1739
|
84 |
3933
|
85 virtual std::string oper (void) const { return "<unknown>"; } |
1739
|
86 |
3933
|
87 virtual std::string name (void) const { return "<unknown>"; } |
2124
|
88 |
3523
|
89 virtual std::string original_text (void) const; |
1739
|
90 |
2980
|
91 tree_expression *mark_in_parens (void) |
1739
|
92 { |
2980
|
93 num_parens++; |
|
94 return this; |
1739
|
95 } |
|
96 |
2980
|
97 tree_expression *mark_postfix_indexed (void) |
|
98 { |
|
99 postfix_indexed = true; |
|
100 return this; |
|
101 } |
2971
|
102 |
2980
|
103 tree_expression *set_print_flag (bool print) |
|
104 { |
|
105 print_flag = print; |
|
106 return this; |
|
107 } |
2971
|
108 |
5861
|
109 virtual void copy_base (tree_expression& e) |
|
110 { |
|
111 num_parens = e.num_parens; |
|
112 postfix_indexed = e.postfix_indexed; |
|
113 print_flag = e.print_flag; |
|
114 } |
|
115 |
2980
|
116 protected: |
2971
|
117 |
2980
|
118 // A count of the number of times this expression appears directly |
|
119 // inside a set of parentheses. |
|
120 // |
|
121 // (((e1)) + e2) ==> 2 for expression e1 |
|
122 // ==> 1 for expression ((e1)) + e2 |
|
123 // ==> 0 for expression e2 |
|
124 int num_parens; |
2971
|
125 |
2980
|
126 // A flag that says whether this expression has an index associated |
|
127 // with it. See the code in tree_identifier::rvalue for the rationale. |
|
128 bool postfix_indexed; |
2971
|
129 |
2980
|
130 // Print result of rvalue for this expression? |
|
131 bool print_flag; |
2988
|
132 |
|
133 private: |
|
134 |
|
135 // No copying! |
|
136 |
|
137 tree_expression (const tree_expression&); |
|
138 |
|
139 tree_expression& operator = (const tree_expression&); |
2971
|
140 }; |
|
141 |
1739
|
142 #endif |
|
143 |
|
144 /* |
|
145 ;;; Local Variables: *** |
|
146 ;;; mode: C++ *** |
|
147 ;;; End: *** |
|
148 */ |