GNU Octave  4.0.0
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-2015 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 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26 
27 #include <cassert>
28 
29 #include "error.h"
30 #include "oct-obj.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 
100 token::token (int tv, symbol_table::symbol_record *s, int l, int c)
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 
136 std::string
137 token::text (void) const
138 {
139  assert (type_tag == string_token);
140  return *str;
141 }
142 
143 std::string
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 
177 std::string
179 {
180  assert (type_tag == scls_name_token);
181  return *sc.method_nm;
182 }
183 
184 std::string
186 {
187  assert (type_tag == scls_name_token);
188  return *sc.class_nm;
189 }
190 
191 std::string
193 {
194  return orig_text;
195 }
std::string text_rep(void)
Definition: token.cc:192
int line_num
Definition: token.h:121
token_type type_tag
Definition: token.h:124
std::string orig_text
Definition: token.h:137
symbol_table::symbol_record * sym_rec(void)
Definition: token.cc:171
int tok_val
Definition: token.h:123
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
std::string symbol_name(void) const
Definition: token.cc:144
struct token::@28::@30 sc
double num
Definition: token.h:128
F77_RET_T const double const double double * d
end_tok_type
Definition: token.h:46
std::string superclass_class_name(void)
Definition: token.cc:185
token_type ttype(void) const
Definition: token.cc:158
end_tok_type ettype(void) const
Definition: token.cc:164
int column_num
Definition: token.h:122
symbol_table::symbol_record * sr
Definition: token.h:130
token_type
Definition: token.h:35
std::string superclass_method_name(void)
Definition: token.cc:178
bool tspc
Definition: token.h:120
std::string * str
Definition: token.h:127
bool maybe_cmd
Definition: token.h:119
~token(void)
Definition: token.cc:124
end_tok_type et
Definition: token.h:129
const std::string & name(void) const
Definition: symtab.h:528