GNU Octave  4.2.1
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
token.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1993-2017 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 (HAVE_CONFIG_H)
24 # include "config.h"
25 #endif
26 
27 #include <cassert>
28 
29 #include "error.h"
30 #include "ovl.h"
31 #include "symtab.h"
32 #include "token.h"
33 #include "utils.h"
34 
35 token::token (int tv, int l, int c)
36 {
37  maybe_cmd = false;
38  tspc = false;
39  line_num = l;
40  column_num = c;
41  tok_val = tv;
43 }
44 
45 token::token (int tv, bool is_kw, int l, int c)
46 {
47  maybe_cmd = false;
48  tspc = false;
49  line_num = l;
50  column_num = c;
51  tok_val = tv;
53 }
54 
55 token::token (int tv, const char *s, int l, int c)
56 {
57  maybe_cmd = false;
58  tspc = false;
59  line_num = l;
60  column_num = c;
61  tok_val = tv;
63  str = new std::string (s);
64 }
65 
66 token::token (int tv, const std::string& s, int l, int c)
67 {
68  maybe_cmd = false;
69  tspc = false;
70  line_num = l;
71  column_num = c;
72  tok_val = tv;
74  str = new std::string (s);
75 }
76 
77 token::token (int tv, double d, const std::string& s, int l, int c)
78 {
79  maybe_cmd = false;
80  tspc = false;
81  line_num = l;
82  column_num = c;
83  tok_val = tv;
85  num = d;
86  orig_text = s;
87 }
88 
89 token::token (int tv, end_tok_type t, int l, int c)
90 {
91  maybe_cmd = false;
92  tspc = false;
93  line_num = l;
94  column_num = c;
95  tok_val = tv;
97  et = t;
98 }
99 
101 {
102  maybe_cmd = false;
103  tspc = false;
104  line_num = l;
105  column_num = c;
106  tok_val = tv;
108  sr = s;
109 }
110 
111 token::token (int tv, const std::string& mth, const std::string& cls,
112  int l, int c)
113 {
114  maybe_cmd = false;
115  tspc = false;
116  line_num = l;
117  column_num = c;
118  tok_val = tv;
120  sc.method_nm = new std::string (mth);
121  sc.class_nm = new std::string (cls);
122 }
123 
125 {
126  if (type_tag == string_token)
127  delete str;
128 
129  if (type_tag == scls_name_token)
130  {
131  delete sc.method_nm;
132  delete sc.class_nm;
133  }
134 }
135 
137 token::text (void) const
138 {
139  assert (type_tag == string_token);
140  return *str;
141 }
142 
144 token::symbol_name (void) const
145 {
146  assert (type_tag == sym_rec_token);
147  return sr->name ();
148 }
149 
150 double
151 token::number (void) const
152 {
153  assert (type_tag == double_token);
154  return num;
155 }
156 
158 token::ttype (void) const
159 {
160  return type_tag;
161 }
162 
164 token::ettype (void) const
165 {
166  assert (type_tag == ettype_token);
167  return et;
168 }
169 
172 {
173  assert (type_tag == sym_rec_token);
174  return sr;
175 }
176 
179 {
180  assert (type_tag == scls_name_token);
181  return *sc.method_nm;
182 }
183 
186 {
187  assert (type_tag == scls_name_token);
188  return *sc.class_nm;
189 }
190 
193 {
194  return orig_text;
195 }
std::string text_rep(void)
Definition: token.cc:192
int line_num
Definition: token.h:123
token_type type_tag
Definition: token.h:126
std::string orig_text
Definition: token.h:139
symbol_table::symbol_record * sym_rec(void)
Definition: token.cc:171
int tok_val
Definition: token.h:125
std::string text(void) const
Definition: token.cc:137
double number(void) const
Definition: token.cc:151
token(int tv, int l=-1, int c=-1)
Definition: token.cc:35
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:935
std::string symbol_name(void) const
Definition: token.cc:144
s
Definition: file-io.cc:2682
double num
Definition: token.h:130
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &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 F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
struct token::@36::@38 sc
end_tok_type
Definition: token.h:48
std::string superclass_class_name(void)
Definition: token.cc:185
token_type ttype(void) const
Definition: token.cc:158
the sparsity preserving column transformation such that that defines the pivoting threshold can be given in which case it defines the c
Definition: lu.cc:138
end_tok_type ettype(void) const
Definition: token.cc:164
int column_num
Definition: token.h:124
symbol_table::symbol_record * sr
Definition: token.h:132
token_type
Definition: token.h:37
std::string superclass_method_name(void)
Definition: token.cc:178
bool tspc
Definition: token.h:122
std::string * str
Definition: token.h:129
bool maybe_cmd
Definition: token.h:121
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:854
~token(void)
Definition: token.cc:124
end_tok_type et
Definition: token.h:131
const std::string & name(void) const
Definition: symtab.h:524