GNU Octave  3.8.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
pt-exp.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2013 John W. Eaton
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 3 of the License, or (at your
10 option) any 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, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if !defined (octave_pt_exp_h)
24 #define octave_pt_exp_h 1
25 
26 #include <string>
27 #include <list>
28 
29 class octave_value;
30 class octave_lvalue;
31 
32 #include "pt.h"
33 #include "symtab.h"
34 
35 // A base class for expressions.
36 
37 class
38 tree_expression : public tree
39 {
40 public:
41 
42  tree_expression (int l = -1, int c = -1)
43  : tree (l, c), num_parens (0), postfix_indexed (false),
44  print_flag (false) { }
45 
46  virtual ~tree_expression (void) { }
47 
48  virtual bool has_magic_end (void) const = 0;
49 
52 
53  virtual bool is_constant (void) const { return false; }
54 
55  virtual bool is_matrix (void) const { return false; }
56 
57  virtual bool is_cell (void) const { return false; }
58 
59  virtual bool is_identifier (void) const { return false; }
60 
61  virtual bool is_index_expression (void) const { return false; }
62 
63  virtual bool is_assignment_expression (void) const { return false; }
64 
65  virtual bool is_prefix_expression (void) const { return false; }
66 
67  virtual bool is_unary_expression (void) const { return false; }
68 
69  virtual bool is_binary_expression (void) const { return false; }
70 
71  virtual bool is_boolean_expression (void) const { return false; }
72 
73  virtual bool is_logically_true (const char *);
74 
75  virtual bool lvalue_ok (void) const { return false; }
76 
77  virtual bool rvalue_ok (void) const { return false; }
78 
79  virtual octave_value rvalue1 (int nargout = 1);
80 
81  virtual octave_value_list rvalue (int nargout);
82 
83  virtual octave_value_list
84  rvalue (int nargout, const std::list<octave_lvalue> *lvalue_list);
85 
86  virtual octave_lvalue lvalue (void);
87 
88  int paren_count (void) const { return num_parens; }
89 
90  bool is_postfix_indexed (void) const { return postfix_indexed; }
91 
92  // Check if the result of the expression should be printed.
93  // Should normally be used in conjunction with
94  // tree_evaluator::statement_printing_enabled.
95  bool print_result (void) const { return print_flag; }
96 
97  virtual std::string oper (void) const { return "<unknown>"; }
98 
99  virtual std::string name (void) const { return "<unknown>"; }
100 
101  virtual std::string original_text (void) const;
102 
103  virtual void mark_braindead_shortcircuit (const std::string&) { }
104 
105  tree_expression *mark_in_parens (void)
106  {
107  num_parens++;
108  return this;
109  }
110 
111  tree_expression *mark_postfix_indexed (void)
112  {
113  postfix_indexed = true;
114  return this;
115  }
116 
117  tree_expression *set_print_flag (bool print)
118  {
119  print_flag = print;
120  return this;
121  }
122 
123  virtual void copy_base (const tree_expression& e)
124  {
125  num_parens = e.num_parens;
126  postfix_indexed = e.postfix_indexed;
127  print_flag = e.print_flag;
128  }
129 
130 protected:
131 
132  // A count of the number of times this expression appears directly
133  // inside a set of parentheses.
134  //
135  // (((e1)) + e2) ==> 2 for expression e1
136  // ==> 1 for expression ((e1)) + e2
137  // ==> 0 for expression e2
139 
140  // A flag that says whether this expression has an index associated
141  // with it. See the code in tree_identifier::rvalue for the rationale.
143 
144  // Print result of rvalue for this expression?
146 
147 private:
148 
149  // No copying!
150 
152 
154 };
155 
156 #endif