GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
pt-exp.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2018 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
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License 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 <https://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if ! defined (octave_pt_exp_h)
24 #define octave_pt_exp_h 1
25 
26 #include "octave-config.h"
27 
28 #include <string>
29 #include <list>
30 
31 class octave_value;
32 
33 #include "pt.h"
34 
35 namespace octave
36 {
37  class symbol_scope;
38  class octave_lvalue;
39  class tree_evaluator;
40 
41  // A base class for expressions.
42 
43  class tree_expression : public tree
44  {
45  public:
46 
47  tree_expression (int l = -1, int c = -1)
48  : tree (l, c), num_parens (0), postfix_index_type ('\0'),
50 
51  // No copying!
52 
53  tree_expression (const tree_expression&) = delete;
54 
56 
57  virtual ~tree_expression (void) = default;
58 
59  virtual bool has_magic_end (void) const = 0;
60 
61  virtual tree_expression * dup (symbol_scope& scope) const = 0;
62 
63  virtual bool is_constant (void) const { return false; }
64 
65  virtual bool is_matrix (void) const { return false; }
66 
67  virtual bool iscell (void) const { return false; }
68 
69  virtual bool is_identifier (void) const { return false; }
70 
71  virtual bool is_index_expression (void) const { return false; }
72 
73  virtual bool is_assignment_expression (void) const { return false; }
74 
75  virtual bool is_prefix_expression (void) const { return false; }
76 
77  virtual bool is_unary_expression (void) const { return false; }
78 
79  virtual bool is_binary_expression (void) const { return false; }
80 
81  virtual bool is_boolean_expression (void) const { return false; }
82 
83  virtual bool lvalue_ok (void) const { return false; }
84 
85  virtual bool rvalue_ok (void) const { return false; }
86 
88 
89  int paren_count (void) const { return num_parens; }
90 
91  bool is_postfix_indexed (void) const { return (postfix_index_type != '\0'); }
92 
93  char postfix_index (void) const { return postfix_index_type; }
94 
95  // Check if the result of the expression should be printed.
96  // Should normally be used in conjunction with
97  // tree_evaluator::statement_printing_enabled.
98  bool print_result (void) const { return print_flag; }
99 
100  virtual std::string oper (void) const { return "<unknown>"; }
101 
102  virtual std::string name (void) const { return "<unknown>"; }
103 
104  virtual std::string original_text (void) const;
105 
106  virtual void mark_braindead_shortcircuit (void) { }
107 
108  void mark_as_for_cmd_expr (void) { for_cmd_expr = true; }
109 
110  bool is_for_cmd_expr (void) const { return for_cmd_expr; }
111 
113  {
114  num_parens++;
115  return this;
116  }
117 
119  {
121  return this;
122  }
123 
125  {
126  print_flag = print;
127  return this;
128  }
129 
130  virtual void copy_base (const tree_expression& e)
131  {
132  num_parens = e.num_parens;
133  postfix_index_type = e.postfix_index_type;
134  print_flag = e.print_flag;
135  }
136 
137  protected:
138 
139  // A count of the number of times this expression appears directly
140  // inside a set of parentheses.
141  //
142  // (((e1)) + e2) ==> 2 for expression e1
143  // ==> 1 for expression ((e1)) + e2
144  // ==> 0 for expression e2
146 
147  // The first index type associated with this expression. This field
148  // is 0 (character '\0') if the expression has no associated index.
149  // See the code in tree_identifier::rvalue for the rationale.
151 
152  // TRUE if this expression is the EXPR in for loop:
153  // FOR i = EXPR ... END
155 
156  // Print result of rvalue for this expression?
158  };
159 }
160 
161 #if defined (OCTAVE_USE_DEPRECATED_FUNCTIONS)
162 
163 OCTAVE_DEPRECATED (4.4, "use 'octave::tree_expression' instead")
164 typedef octave::tree_expression tree_expression;
165 
166 #endif
167 
168 #endif
virtual std::string name(void) const
Definition: pt-exp.h:102
virtual bool iscell(void) const
Definition: pt-exp.h:67
virtual bool is_matrix(void) const
Definition: pt-exp.h:65
virtual void mark_braindead_shortcircuit(void)
Definition: pt-exp.h:106
virtual std::string oper(void) const
Definition: pt-exp.h:100
virtual bool has_magic_end(void) const =0
virtual std::string original_text(void) const
Definition: pt-exp.cc:47
void mark_as_for_cmd_expr(void)
Definition: pt-exp.h:108
char postfix_index(void) const
Definition: pt-exp.h:93
nd example oindent opens the file binary numeric values will be read assuming they are stored in IEEE format with the least significant bit and then converted to the native representation Opening a file that is already open simply opens it again and returns a separate file id It is not an error to open a file several though writing to the same file through several different file ids may produce unexpected results The possible values of text mode reading and writing automatically converts linefeeds to the appropriate line end character for the you may append a you must also open the file in binary mode The parameter conversions are currently only supported for and permissions will be set to and then everything is written in a single operation This is very efficient and improves performance c
Definition: file-io.cc:587
i e
Definition: data.cc:2591
tree_expression(int l=-1, int c=-1)
Definition: pt-exp.h:47
virtual bool lvalue_ok(void) const
Definition: pt-exp.h:83
virtual bool is_boolean_expression(void) const
Definition: pt-exp.h:81
virtual void copy_base(const tree_expression &e)
Definition: pt-exp.h:130
virtual bool is_index_expression(void) const
Definition: pt-exp.h:71
tree_expression * set_postfix_index(char type)
Definition: pt-exp.h:118
is false
Definition: cellfun.cc:400
idx type
Definition: ov.cc:3114
virtual bool is_constant(void) const
Definition: pt-exp.h:63
virtual bool is_identifier(void) const
Definition: pt-exp.h:69
virtual octave_lvalue lvalue(tree_evaluator *)
Definition: pt-exp.cc:41
bool is_for_cmd_expr(void) const
Definition: pt-exp.h:110
virtual bool rvalue_ok(void) const
Definition: pt-exp.h:85
tree_expression & operator=(const tree_expression &)=delete
bool is_postfix_indexed(void) const
Definition: pt-exp.h:91
virtual ~tree_expression(void)=default
virtual bool is_unary_expression(void) const
Definition: pt-exp.h:77
int paren_count(void) const
Definition: pt-exp.h:89
virtual bool is_assignment_expression(void) const
Definition: pt-exp.h:73
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:888
virtual bool is_prefix_expression(void) const
Definition: pt-exp.h:75
virtual tree_expression * dup(symbol_scope &scope) const =0
virtual bool is_binary_expression(void) const
Definition: pt-exp.h:79
tree_expression * mark_in_parens(void)
Definition: pt-exp.h:112
bool print_result(void) const
Definition: pt-exp.h:98
tree_expression * set_print_flag(bool print)
Definition: pt-exp.h:124