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 |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
1739
|
21 |
|
22 */ |
|
23 |
2980
|
24 #if !defined (octave_tree_expr_h) |
|
25 #define octave_tree_expr_h 1 |
1739
|
26 |
2980
|
27 #include <string> |
2124
|
28 |
2879
|
29 class octave_value; |
2979
|
30 class octave_lvalue; |
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 |
3933
|
49 virtual bool is_constant (void) const { return false; } |
2388
|
50 |
3933
|
51 virtual bool is_matrix_constant (void) const { return false; } |
2388
|
52 |
3933
|
53 virtual bool is_identifier (void) const { return false; } |
1739
|
54 |
3933
|
55 virtual bool is_index_expression (void) const { return false; } |
1739
|
56 |
3933
|
57 virtual bool is_assignment_expression (void) const { return false; } |
1739
|
58 |
3933
|
59 virtual bool is_prefix_expression (void) const { return false; } |
1739
|
60 |
4023
|
61 virtual bool is_binary_expression (void) const { return false; } |
|
62 |
|
63 virtual bool is_boolean_expression (void) const { return false; } |
|
64 |
2980
|
65 virtual bool is_logically_true (const char *); |
1739
|
66 |
3933
|
67 virtual bool lvalue_ok (void) const { return false; } |
1739
|
68 |
3933
|
69 virtual bool rvalue_ok (void) const { return false; } |
2124
|
70 |
2980
|
71 virtual octave_value rvalue (void); |
1739
|
72 |
2980
|
73 virtual octave_value_list rvalue (int nargout); |
2879
|
74 |
2980
|
75 virtual octave_lvalue lvalue (void); |
2879
|
76 |
3933
|
77 int paren_count (void) const { return num_parens; } |
2124
|
78 |
3933
|
79 bool is_postfix_indexed (void) const { return postfix_indexed; } |
2124
|
80 |
3933
|
81 bool print_result (void) const { return print_flag; } |
1739
|
82 |
3933
|
83 virtual std::string oper (void) const { return "<unknown>"; } |
1739
|
84 |
3933
|
85 virtual std::string name (void) const { return "<unknown>"; } |
2124
|
86 |
3523
|
87 virtual std::string original_text (void) const; |
1739
|
88 |
2980
|
89 tree_expression *mark_in_parens (void) |
1739
|
90 { |
2980
|
91 num_parens++; |
|
92 return this; |
1739
|
93 } |
|
94 |
2980
|
95 tree_expression *mark_postfix_indexed (void) |
|
96 { |
|
97 postfix_indexed = true; |
|
98 return this; |
|
99 } |
2971
|
100 |
2980
|
101 tree_expression *set_print_flag (bool print) |
|
102 { |
|
103 print_flag = print; |
|
104 return this; |
|
105 } |
2971
|
106 |
2980
|
107 protected: |
2971
|
108 |
2980
|
109 // A count of the number of times this expression appears directly |
|
110 // inside a set of parentheses. |
|
111 // |
|
112 // (((e1)) + e2) ==> 2 for expression e1 |
|
113 // ==> 1 for expression ((e1)) + e2 |
|
114 // ==> 0 for expression e2 |
|
115 int num_parens; |
2971
|
116 |
2980
|
117 // A flag that says whether this expression has an index associated |
|
118 // with it. See the code in tree_identifier::rvalue for the rationale. |
|
119 bool postfix_indexed; |
2971
|
120 |
2980
|
121 // Print result of rvalue for this expression? |
|
122 bool print_flag; |
2988
|
123 |
|
124 private: |
|
125 |
|
126 // No copying! |
|
127 |
|
128 tree_expression (const tree_expression&); |
|
129 |
|
130 tree_expression& operator = (const tree_expression&); |
2971
|
131 }; |
|
132 |
1739
|
133 #endif |
|
134 |
|
135 /* |
|
136 ;;; Local Variables: *** |
|
137 ;;; mode: C++ *** |
|
138 ;;; End: *** |
|
139 */ |