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 |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
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 |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
2980
|
23 #if !defined (octave_tree_expr_h) |
|
24 #define octave_tree_expr_h 1 |
1739
|
25 |
4192
|
26 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) |
1739
|
27 #pragma interface |
|
28 #endif |
|
29 |
2980
|
30 #include <string> |
2124
|
31 |
2879
|
32 class octave_value; |
2979
|
33 class octave_lvalue; |
2879
|
34 |
2988
|
35 #include "pt.h" |
2124
|
36 |
2980
|
37 // A base class for expressions. |
1739
|
38 |
|
39 class |
2980
|
40 tree_expression : public tree |
2388
|
41 { |
|
42 public: |
|
43 |
2980
|
44 tree_expression (int l = -1, int c = -1) |
|
45 : tree (l, c), num_parens (0), postfix_indexed (false), |
|
46 print_flag (false) { } |
2388
|
47 |
2980
|
48 virtual ~tree_expression (void) { } |
2388
|
49 |
4267
|
50 virtual bool has_magic_end (void) const = 0; |
|
51 |
3933
|
52 virtual bool is_constant (void) const { return false; } |
2388
|
53 |
3933
|
54 virtual bool is_matrix_constant (void) const { return false; } |
2388
|
55 |
3933
|
56 virtual bool is_identifier (void) const { return false; } |
1739
|
57 |
3933
|
58 virtual bool is_index_expression (void) const { return false; } |
1739
|
59 |
3933
|
60 virtual bool is_assignment_expression (void) const { return false; } |
1739
|
61 |
3933
|
62 virtual bool is_prefix_expression (void) const { return false; } |
1739
|
63 |
4023
|
64 virtual bool is_binary_expression (void) const { return false; } |
|
65 |
|
66 virtual bool is_boolean_expression (void) const { return false; } |
|
67 |
2980
|
68 virtual bool is_logically_true (const char *); |
1739
|
69 |
3933
|
70 virtual bool lvalue_ok (void) const { return false; } |
1739
|
71 |
3933
|
72 virtual bool rvalue_ok (void) const { return false; } |
2124
|
73 |
2980
|
74 virtual octave_value rvalue (void); |
1739
|
75 |
2980
|
76 virtual octave_value_list rvalue (int nargout); |
2879
|
77 |
2980
|
78 virtual octave_lvalue lvalue (void); |
2879
|
79 |
3933
|
80 int paren_count (void) const { return num_parens; } |
2124
|
81 |
3933
|
82 bool is_postfix_indexed (void) const { return postfix_indexed; } |
2124
|
83 |
3933
|
84 bool print_result (void) const { return print_flag; } |
1739
|
85 |
3933
|
86 virtual std::string oper (void) const { return "<unknown>"; } |
1739
|
87 |
3933
|
88 virtual std::string name (void) const { return "<unknown>"; } |
2124
|
89 |
3523
|
90 virtual std::string original_text (void) const; |
1739
|
91 |
2980
|
92 tree_expression *mark_in_parens (void) |
1739
|
93 { |
2980
|
94 num_parens++; |
|
95 return this; |
1739
|
96 } |
|
97 |
2980
|
98 tree_expression *mark_postfix_indexed (void) |
|
99 { |
|
100 postfix_indexed = true; |
|
101 return this; |
|
102 } |
2971
|
103 |
2980
|
104 tree_expression *set_print_flag (bool print) |
|
105 { |
|
106 print_flag = print; |
|
107 return this; |
|
108 } |
2971
|
109 |
2980
|
110 protected: |
2971
|
111 |
2980
|
112 // A count of the number of times this expression appears directly |
|
113 // inside a set of parentheses. |
|
114 // |
|
115 // (((e1)) + e2) ==> 2 for expression e1 |
|
116 // ==> 1 for expression ((e1)) + e2 |
|
117 // ==> 0 for expression e2 |
|
118 int num_parens; |
2971
|
119 |
2980
|
120 // A flag that says whether this expression has an index associated |
|
121 // with it. See the code in tree_identifier::rvalue for the rationale. |
|
122 bool postfix_indexed; |
2971
|
123 |
2980
|
124 // Print result of rvalue for this expression? |
|
125 bool print_flag; |
2988
|
126 |
|
127 private: |
|
128 |
|
129 // No copying! |
|
130 |
|
131 tree_expression (const tree_expression&); |
|
132 |
|
133 tree_expression& operator = (const tree_expression&); |
2971
|
134 }; |
|
135 |
1739
|
136 #endif |
|
137 |
|
138 /* |
|
139 ;;; Local Variables: *** |
|
140 ;;; mode: C++ *** |
|
141 ;;; End: *** |
|
142 */ |