Octave-Forge - Extra packages for GNU Octave | |
Home · Packages · Developers · Documentation · FAQ · Bugs · Mailing Lists · Links · Code |
00001 /* 00002 00003 Copyright (C) 1996, 1997, 2000, 2002, 2003, 2004, 2005, 2006, 2007, 00004 2008, 2009 John W. Eaton 00005 00006 This file is part of Octave. 00007 00008 Octave is free software; you can redistribute it and/or modify it 00009 under the terms of the GNU General Public License as published by the 00010 Free Software Foundation; either version 3 of the License, or (at your 00011 option) any later version. 00012 00013 Octave is distributed in the hope that it will be useful, but WITHOUT 00014 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00015 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00016 for more details. 00017 00018 You should have received a copy of the GNU General Public License 00019 along with Octave; see the file COPYING. If not, see 00020 <http://www.gnu.org/licenses/>. 00021 00022 */ 00023 00024 #if !defined (octave_tree_expr_h) 00025 #define octave_tree_expr_h 1 00026 00027 #include <string> 00028 00029 class octave_value; 00030 class octave_lvalue; 00031 00032 #include "pt.h" 00033 #include "symtab.h" 00034 00035 // A base class for expressions. 00036 00037 class 00038 tree_expression : public tree 00039 { 00040 public: 00041 00042 tree_expression (int l = -1, int c = -1) 00043 : tree (l, c), num_parens (0), postfix_indexed (false), 00044 print_flag (false) { } 00045 00046 virtual ~tree_expression (void) { } 00047 00048 virtual bool has_magic_end (void) const = 0; 00049 00050 virtual tree_expression *dup (symbol_table::scope_id, 00051 symbol_table::context_id context) const = 0; 00052 00053 virtual bool is_constant (void) const { return false; } 00054 00055 virtual bool is_matrix_constant (void) const { return false; } 00056 00057 virtual bool is_identifier (void) const { return false; } 00058 00059 virtual bool is_index_expression (void) const { return false; } 00060 00061 virtual bool is_assignment_expression (void) const { return false; } 00062 00063 virtual bool is_prefix_expression (void) const { return false; } 00064 00065 virtual bool is_unary_expression (void) const { return false; } 00066 00067 virtual bool is_binary_expression (void) const { return false; } 00068 00069 virtual bool is_boolean_expression (void) const { return false; } 00070 00071 virtual bool is_logically_true (const char *); 00072 00073 virtual bool lvalue_ok (void) const { return false; } 00074 00075 virtual bool rvalue_ok (void) const { return false; } 00076 00077 virtual octave_value rvalue1 (int nargout = 1); 00078 00079 virtual octave_value_list rvalue (int nargout); 00080 00081 virtual octave_lvalue lvalue (void); 00082 00083 int paren_count (void) const { return num_parens; } 00084 00085 bool is_postfix_indexed (void) const { return postfix_indexed; } 00086 00087 bool print_result (void) const { return print_flag; } 00088 00089 virtual std::string oper (void) const { return "<unknown>"; } 00090 00091 virtual std::string name (void) const { return "<unknown>"; } 00092 00093 virtual std::string original_text (void) const; 00094 00095 tree_expression *mark_in_parens (void) 00096 { 00097 num_parens++; 00098 return this; 00099 } 00100 00101 tree_expression *mark_postfix_indexed (void) 00102 { 00103 postfix_indexed = true; 00104 return this; 00105 } 00106 00107 tree_expression *set_print_flag (bool print) 00108 { 00109 print_flag = print; 00110 return this; 00111 } 00112 00113 virtual void copy_base (const tree_expression& e) 00114 { 00115 num_parens = e.num_parens; 00116 postfix_indexed = e.postfix_indexed; 00117 print_flag = e.print_flag; 00118 } 00119 00120 protected: 00121 00122 // A count of the number of times this expression appears directly 00123 // inside a set of parentheses. 00124 // 00125 // (((e1)) + e2) ==> 2 for expression e1 00126 // ==> 1 for expression ((e1)) + e2 00127 // ==> 0 for expression e2 00128 int num_parens; 00129 00130 // A flag that says whether this expression has an index associated 00131 // with it. See the code in tree_identifier::rvalue for the rationale. 00132 bool postfix_indexed; 00133 00134 // Print result of rvalue for this expression? 00135 bool print_flag; 00136 00137 private: 00138 00139 // No copying! 00140 00141 tree_expression (const tree_expression&); 00142 00143 tree_expression& operator = (const tree_expression&); 00144 }; 00145 00146 #endif 00147 00148 /* 00149 ;;; Local Variables: *** 00150 ;;; mode: C++ *** 00151 ;;; End: *** 00152 */