GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
token.cc
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 (HAVE_CONFIG_H)
24 # include "config.h"
25 #endif
26 
27 #include <cassert>
28 
29 #include "symrec.h"
30 #include "token.h"
31 
32 namespace octave
33 {
34  token::token (int tv, int l, int c)
35  : m_maybe_cmd (false), m_tspc (false), m_line_num (l), m_column_num (c),
36  m_tok_val (tv), m_type_tag (generic_token), m_tok_info (),
37  m_orig_text ()
38  { }
39 
40  token::token (int tv, bool is_kw, int l, int c)
41  : m_maybe_cmd (false), m_tspc (false), m_line_num (l), m_column_num (c),
42  m_tok_val (tv), m_type_tag (is_kw ? keyword_token : generic_token),
43  m_tok_info (), m_orig_text ()
44  { }
45 
46  token::token (int tv, const char *s, int l, int c)
47  : m_maybe_cmd (false), m_tspc (false), m_line_num (l), m_column_num (c),
48  m_tok_val (tv), m_type_tag (string_token), m_tok_info (s),
49  m_orig_text ()
50  { }
51 
52  token::token (int tv, const std::string& s, int l, int c)
53  : m_maybe_cmd (false), m_tspc (false), m_line_num (l), m_column_num (c),
54  m_tok_val (tv), m_type_tag (string_token), m_tok_info (s),
55  m_orig_text ()
56  { }
57 
58  token::token (int tv, double d, const std::string& s, int l, int c)
59  : m_maybe_cmd (false), m_tspc (false), m_line_num (l), m_column_num (c),
60  m_tok_val (tv), m_type_tag (double_token), m_tok_info (d),
61  m_orig_text (s)
62  { }
63 
64  token::token (int tv, end_tok_type t, int l, int c)
65  : m_maybe_cmd (false), m_tspc (false), m_line_num (l), m_column_num (c),
66  m_tok_val (tv), m_type_tag (ettype_token), m_tok_info (t),
67  m_orig_text ()
68  { }
69 
70  token::token (int tv, const symbol_record& sr, int l, int c)
71  : m_maybe_cmd (false), m_tspc (false), m_line_num (l), m_column_num (c),
72  m_tok_val (tv), m_type_tag (sym_rec_token), m_tok_info (sr),
73  m_orig_text ()
74  { }
75 
76  token::token (int tv, const std::string& method_nm,
77  const std::string& class_nm, int l, int c)
78  : m_maybe_cmd (false), m_tspc (false), m_line_num (l), m_column_num (c),
79  m_tok_val (tv), m_type_tag (scls_name_token),
80  m_tok_info (method_nm, class_nm), m_orig_text ()
81  { }
82 
84  {
85  if (m_type_tag == string_token)
86  delete m_tok_info.m_str;
87 
89  delete m_tok_info.m_sr;
90 
93  }
94 
96  token::text (void) const
97  {
98  assert (m_type_tag == string_token);
99  return *m_tok_info.m_str;
100  }
101 
103  token::symbol_name (void) const
104  {
105  assert (m_type_tag == sym_rec_token);
106  return m_tok_info.m_sr->name ();
107  }
108 
109  double
110  token::number (void) const
111  {
112  assert (m_type_tag == double_token);
113  return m_tok_info.m_num;
114  }
115 
117  token::ttype (void) const
118  {
119  return m_type_tag;
120  }
121 
123  token::ettype (void) const
124  {
125  assert (m_type_tag == ettype_token);
126  return m_tok_info.m_et;
127  }
128 
130  token::sym_rec (void) const
131  {
132  assert (m_type_tag == sym_rec_token);
133  return *m_tok_info.m_sr;
134  }
135 
138  {
139  assert (m_type_tag == scls_name_token);
141  }
142 
145  {
146  assert (m_type_tag == scls_name_token);
148  }
149 
151  token::text_rep (void) const
152  {
153  return m_orig_text;
154  }
155 }
token_type ttype(void) const
Definition: token.cc:117
std::string m_orig_text
Definition: token.h:194
tok_info m_tok_info
Definition: token.h:192
std::string * m_str
Definition: token.h:162
end_tok_type m_et
Definition: token.h:166
std::string symbol_name(void) const
Definition: token.cc:103
token(int tv, int l=-1, int c=-1)
Definition: token.cc:34
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
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
symbol_record sym_rec(void) const
Definition: token.cc:130
std::string name(void) const
Definition: symrec.h:576
std::string text(void) const
Definition: token.cc:96
is false
Definition: cellfun.cc:400
~token(void)
Definition: token.cc:83
symbol_record * m_sr
Definition: token.h:168
double number(void) const
Definition: token.cc:110
end_tok_type ettype(void) const
Definition: token.cc:123
std::string superclass_method_name(void) const
Definition: token.cc:137
superclass_info * m_superclass_info
Definition: token.h:189
std::string text_rep(void) const
Definition: token.cc:151
std::string superclass_class_name(void) const
Definition: token.cc:144
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