1739
|
1 /* |
|
2 |
7017
|
3 Copyright (C) 1996, 1997, 2000, 2002, 2003, 2004, 2005, 2006, 2007 |
|
4 John W. Eaton |
1739
|
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 |
7016
|
10 Free Software Foundation; either version 3 of the License, or (at your |
|
11 option) any later version. |
1739
|
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 |
7016
|
19 along with Octave; see the file COPYING. If not, see |
|
20 <http://www.gnu.org/licenses/>. |
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; |
5861
|
31 class symbol_table; |
2879
|
32 |
2988
|
33 #include "pt.h" |
2124
|
34 |
2980
|
35 // A base class for expressions. |
1739
|
36 |
|
37 class |
2980
|
38 tree_expression : public tree |
2388
|
39 { |
|
40 public: |
|
41 |
2980
|
42 tree_expression (int l = -1, int c = -1) |
|
43 : tree (l, c), num_parens (0), postfix_indexed (false), |
|
44 print_flag (false) { } |
2388
|
45 |
2980
|
46 virtual ~tree_expression (void) { } |
2388
|
47 |
4267
|
48 virtual bool has_magic_end (void) const = 0; |
|
49 |
5861
|
50 virtual tree_expression *dup (symbol_table *) = 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 |
5861
|
110 virtual void copy_base (tree_expression& e) |
|
111 { |
|
112 num_parens = e.num_parens; |
|
113 postfix_indexed = e.postfix_indexed; |
|
114 print_flag = e.print_flag; |
|
115 } |
|
116 |
2980
|
117 protected: |
2971
|
118 |
2980
|
119 // A count of the number of times this expression appears directly |
|
120 // inside a set of parentheses. |
|
121 // |
|
122 // (((e1)) + e2) ==> 2 for expression e1 |
|
123 // ==> 1 for expression ((e1)) + e2 |
|
124 // ==> 0 for expression e2 |
|
125 int num_parens; |
2971
|
126 |
2980
|
127 // A flag that says whether this expression has an index associated |
|
128 // with it. See the code in tree_identifier::rvalue for the rationale. |
|
129 bool postfix_indexed; |
2971
|
130 |
2980
|
131 // Print result of rvalue for this expression? |
|
132 bool print_flag; |
2988
|
133 |
|
134 private: |
|
135 |
|
136 // No copying! |
|
137 |
|
138 tree_expression (const tree_expression&); |
|
139 |
|
140 tree_expression& operator = (const tree_expression&); |
2971
|
141 }; |
|
142 |
1739
|
143 #endif |
|
144 |
|
145 /* |
|
146 ;;; Local Variables: *** |
|
147 ;;; mode: C++ *** |
|
148 ;;; End: *** |
|
149 */ |