GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
token.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1993-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_token_h)
24 #define octave_token_h 1
25 
26 #include "octave-config.h"
27 
28 #include <string>
29 
30 #include "symrec.h"
31 
32 namespace octave
33 {
34  class
35  token
36  {
37  public:
38 
40  {
48  };
49 
51  {
66  };
67 
68  token (int tv, int l = -1, int c = -1);
69  token (int tv, bool is_keyword, int l = -1, int c = -1);
70  token (int tv, const char *s, int l = -1, int c = -1);
71  token (int tv, const std::string& s, int l = -1, int c = -1);
72  token (int tv, double d, const std::string& s = "",
73  int l = -1, int c = -1);
74  token (int tv, end_tok_type t, int l = -1, int c = -1);
75  token (int tv, const symbol_record& s,
76  int l = -1, int c = -1);
77  token (int tv, const std::string& mth, const std::string& cls,
78  int l = -1, int c = -1);
79 
80  // No copying!
81 
82  token (const token&) = delete;
83 
84  token& operator = (const token&) = delete;
85 
86  ~token (void);
87 
88  void mark_may_be_command (void) { m_maybe_cmd = true; }
89  bool may_be_command (void) const { return m_maybe_cmd; }
90 
91  void mark_trailing_space (void) { m_tspc = true; }
92  bool space_follows_token (void) const { return m_tspc; }
93 
94  int token_value (void) const { return m_tok_val; }
95  bool token_value_is (int tv) const { return tv == m_tok_val; }
96 
97  int line (void) const { return m_line_num; }
98  int column (void) const { return m_column_num; }
99 
100  bool is_keyword (void) const
101  {
102  return m_type_tag == keyword_token || m_type_tag == ettype_token;
103  }
104 
105  bool is_symbol (void) const
106  {
107  return m_type_tag == sym_rec_token;
108  }
109 
110  std::string text (void) const;
111  std::string symbol_name (void) const;
112  double number (void) const;
113  token_type ttype (void) const;
114  end_tok_type ettype (void) const;
115  symbol_record sym_rec (void) const;
116 
117  std::string superclass_method_name (void) const;
118  std::string superclass_class_name (void) const;
119 
120  std::string text_rep (void) const;
121 
122  private:
123 
125 
126  bool m_tspc;
127 
129 
131 
133 
135 
136  union tok_info
137  {
138  tok_info (void) { }
139 
140  tok_info (const char *s) : m_str (new std::string (s)) { }
141 
142  tok_info (const std::string& str) : m_str (new std::string (str)) { }
143 
144  tok_info (double num) : m_num (num) { }
145 
146  tok_info (end_tok_type et) : m_et (et) { }
147 
149  : m_sr (new symbol_record (sr))
150  { }
151 
152  tok_info (const std::string& method_nm, const std::string& class_nm)
153  : m_superclass_info (new superclass_info (method_nm, class_nm))
154  { }
155 
156  tok_info (const tok_info&) = delete;
157 
158  tok_info& operator = (const tok_info&) = delete;
159 
160  ~tok_info (void) { }
161 
163 
164  double m_num;
165 
167 
169 
171  {
172  superclass_info (void) = delete;
173 
174  superclass_info (const std::string& method_nm,
175  const std::string& class_nm)
176  : m_method_nm (method_nm), m_class_nm (class_nm)
177  { }
178 
179  superclass_info (const superclass_info&) = delete;
180 
181  superclass_info& operator = (const superclass_info&) = delete;
182 
183  ~superclass_info (void) = default;
184 
187  };
188 
190  };
191 
193 
195  };
196 }
197 
198 #if defined (OCTAVE_USE_DEPRECATED_FUNCTIONS)
199 
200 OCTAVE_DEPRECATED (4.4, "use 'octave::token' instead")
201 typedef octave::token token;
202 
203 #endif
204 
205 #endif
std::string m_orig_text
Definition: token.h:194
void mark_trailing_space(void)
Definition: token.h:91
tok_info m_tok_info
Definition: token.h:192
std::string * m_str
Definition: token.h:162
int m_line_num
Definition: token.h:128
superclass_info(const std::string &method_nm, const std::string &class_nm)
Definition: token.h:174
tok_info(const std::string &str)
Definition: token.h:142
end_tok_type m_et
Definition: token.h:166
for fields that display a single number
Definition: time.cc:441
tok_info(double num)
Definition: token.h:144
int m_tok_val
Definition: token.h:132
STL namespace.
bool m_maybe_cmd
Definition: token.h:124
bool m_tspc
Definition: token.h:126
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function t
Definition: ov-usr-fcn.cc:997
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
s
Definition: file-io.cc:2729
int column(void) const
Definition: token.h:98
token_type m_type_tag
Definition: token.h:134
F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
void mark_may_be_command(void)
Definition: token.h:88
tok_info(end_tok_type et)
Definition: token.h:146
bool is_keyword(void) const
Definition: token.h:100
std::string str
Definition: hash.cc:118
bool is_symbol(void) const
Definition: token.h:105
tok_info(const char *s)
Definition: token.h:140
symbol_record * m_sr
Definition: token.h:168
bool space_follows_token(void) const
Definition: token.h:92
int line(void) const
Definition: token.h:97
bool is_keyword(const std::string &s)
tok_info(const std::string &method_nm, const std::string &class_nm)
Definition: token.h:152
bool may_be_command(void) const
Definition: token.h:89
OCTAVE_EXPORT octave_value_list the first data row corresponds to an index of zero The a spreadsheet style form such as the file is read until end of file is reached The such as text
Definition: dlmread.cc:194
superclass_info * m_superclass_info
Definition: token.h:189
bool token_value_is(int tv) const
Definition: token.h:95
tok_info(const symbol_record &sr)
Definition: token.h:148
int token_value(void) const
Definition: token.h:94
int m_column_num
Definition: token.h:130
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