GNU Octave 11.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
pt-exp.h
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 1996-2026 The Octave Project Developers
4//
5// See the file COPYRIGHT.md in the top-level directory of this
6// distribution or <https://octave.org/copyright/>.
7//
8// This file is part of Octave.
9//
10// Octave is free software: you can redistribute it and/or modify it
11// under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// Octave is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with Octave; see the file COPYING. If not, see
22// <https://www.gnu.org/licenses/>.
23//
24////////////////////////////////////////////////////////////////////////
25
26#if ! defined (octave_pt_exp_h)
27#define octave_pt_exp_h 1
28
29#include "octave-config.h"
30
31#include <string>
32#include <list>
33
34class octave_value;
35
36#include "pt.h"
37#include "pt-delimiter-list.h"
38#include "pt-eval.h"
39#include "token.h"
40
42
43class symbol_scope;
44class octave_lvalue;
45
46// A base class for expressions.
47
48class OCTINTERP_API tree_expression : public tree
49{
50public:
51
53 : m_postfix_index_type ('\0'), m_for_cmd_expr (false), m_print_flag (false)
54 { }
55
56 OCTAVE_DISABLE_COPY_MOVE (tree_expression)
57
58 virtual ~tree_expression () = default;
59
60 virtual tree_expression * dup (symbol_scope& scope) const = 0;
61
62 virtual bool is_constant () const { return false; }
63
64 virtual bool is_matrix () const { return false; }
65
66 virtual bool iscell () const { return false; }
67
68 virtual bool is_identifier () const { return false; }
69
70 virtual bool is_index_expression () const { return false; }
71
72 virtual bool is_assignment_expression () const { return false; }
73
74 virtual bool is_prefix_expression () const { return false; }
75
76 virtual bool is_unary_expression () const { return false; }
77
78 virtual bool is_binary_expression () const { return false; }
79
80 virtual bool is_boolean_expression () const { return false; }
81
82 virtual bool is_colon_expression () const { return false; }
83
84 virtual bool lvalue_ok () const { return false; }
85
86 virtual bool rvalue_ok () const { return false; }
87
88 virtual octave_lvalue lvalue (tree_evaluator&);
89
90 // The number of times this expression appears directly inside a set
91 // of delimiters.
92 //
93 // (([e1]) + e2) ==> 2 for expression e1
94 // ==> 1 for expression ([e1]) + e2
95 // ==> 0 for expression e2
96
97 size_t delim_count () const { return m_delims.count (); }
98
99 bool is_postfix_indexed () const
100 { return (m_postfix_index_type != '\0'); }
101
102 char postfix_index () const { return m_postfix_index_type; }
103
104 // Check if the result of the expression should be printed.
105 // Should normally be used in conjunction with
106 // tree_evaluator::statement_printing_enabled.
107 bool print_result () const { return m_print_flag; }
108
109 OCTAVE_DEPRECATED (11, "use tree_expression::op_str instead")
110 virtual std::string oper () const { return "<unknown>"; }
111
112 virtual std::string op_str () const { return "<unknown>"; }
113
114 virtual std::string name () const { return "<unknown>"; }
115
116 virtual std::string original_text () const;
117
118 tree_delimiter_list delims () const { return m_delims; }
119
120 void mark_as_for_cmd_expr () { m_for_cmd_expr = true; }
121
122 bool is_for_cmd_expr () const { return m_for_cmd_expr; }
123
124 tree_expression * mark_in_delims (const token& open_delim, const token& close_delim)
125 {
126 m_delims.push (open_delim, close_delim);
127 return this;
128 }
129
131 {
132 m_postfix_index_type = type;
133 return this;
134 }
135
137 {
138 m_print_flag = print;
139 return this;
140 }
141
142 virtual void copy_base (const tree_expression& e)
143 {
144 m_postfix_index_type = e.m_postfix_index_type;
145 m_print_flag = e.m_print_flag;
146 m_delims = e.m_delims;
147 }
148
149 virtual octave_value evaluate (tree_evaluator& tw, int nargout = 1) = 0;
150
151 virtual octave_value_list
152 evaluate_n (tree_evaluator& tw, int nargout = 1) = 0;
153
154protected:
155
156 // The first index type associated with this expression. This field
157 // is 0 (character '\0') if the expression has no associated index.
158 // See the code in tree_identifier::rvalue for the rationale.
160
161 // TRUE if this expression is the EXPR in for loop:
162 // FOR i = EXPR ... END
164
165 // Print result of rvalue for this expression?
167
168 // Tokens for any delimiters surrounding this expression.
170};
171
172OCTAVE_END_NAMESPACE(octave)
173
174#endif
Definition token.h:42
char postfix_index() const
Definition pt-exp.h:102
virtual octave_value evaluate(tree_evaluator &tw, int nargout=1)=0
virtual bool is_binary_expression() const
Definition pt-exp.h:78
virtual std::string op_str() const
Definition pt-exp.h:112
virtual bool is_boolean_expression() const
Definition pt-exp.h:80
virtual bool is_identifier() const
Definition pt-exp.h:68
virtual bool is_colon_expression() const
Definition pt-exp.h:82
bool is_postfix_indexed() const
Definition pt-exp.h:99
void mark_as_for_cmd_expr()
Definition pt-exp.h:120
bool print_result() const
Definition pt-exp.h:107
virtual bool is_unary_expression() const
Definition pt-exp.h:76
virtual bool iscell() const
Definition pt-exp.h:66
tree_expression * mark_in_delims(const token &open_delim, const token &close_delim)
Definition pt-exp.h:124
bool m_for_cmd_expr
Definition pt-exp.h:163
virtual bool rvalue_ok() const
Definition pt-exp.h:86
bool is_for_cmd_expr() const
Definition pt-exp.h:122
virtual bool is_index_expression() const
Definition pt-exp.h:70
virtual bool is_prefix_expression() const
Definition pt-exp.h:74
tree_delimiter_list delims() const
Definition pt-exp.h:118
size_t delim_count() const
Definition pt-exp.h:97
tree_expression * set_print_flag(bool print)
Definition pt-exp.h:136
bool m_print_flag
Definition pt-exp.h:166
virtual bool lvalue_ok() const
Definition pt-exp.h:84
tree_delimiter_list m_delims
Definition pt-exp.h:169
tree_expression * set_postfix_index(char type)
Definition pt-exp.h:130
virtual void copy_base(const tree_expression &e)
Definition pt-exp.h:142
virtual std::string name() const
Definition pt-exp.h:114
virtual bool is_matrix() const
Definition pt-exp.h:64
virtual bool is_assignment_expression() const
Definition pt-exp.h:72
char m_postfix_index_type
Definition pt-exp.h:159
virtual octave_value_list evaluate_n(tree_evaluator &tw, int nargout=1)=0
Definition pt.h:47
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
OCTAVE_DEPRECATED(11, "") typedef bool(*b_d_Mapper)(double)