GNU Octave
3.8.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Pages
libinterp
parse-tree
token.cc
Go to the documentation of this file.
1
/*
2
3
Copyright (C) 1993-2013 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;
42
type_tag
=
generic_token
;
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;
52
type_tag
= is_kw ?
keyword_token
:
generic_token
;
53
}
54
55
token::token
(
int
tv,
const
std::string& 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;
62
type_tag
=
string_token
;
63
str
=
new
std::string (s);
64
}
65
66
token::token
(
int
tv,
double
d
,
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;
73
type_tag
=
double_token
;
74
num
=
d
;
75
orig_text
= s;
76
}
77
78
token::token
(
int
tv,
end_tok_type
t,
int
l,
int
c)
79
{
80
maybe_cmd
=
false
;
81
tspc
=
false
;
82
line_num
= l;
83
column_num
= c;
84
tok_val
= tv;
85
type_tag
=
ettype_token
;
86
et
= t;
87
}
88
89
token::token
(
int
tv,
symbol_table::symbol_record
*s,
int
l,
int
c)
90
{
91
maybe_cmd
=
false
;
92
tspc
=
false
;
93
line_num
= l;
94
column_num
= c;
95
tok_val
= tv;
96
type_tag
=
sym_rec_token
;
97
sr
= s;
98
}
99
100
token::token
(
int
tv,
symbol_table::symbol_record
*cls,
101
symbol_table::symbol_record
*pkg,
int
l,
int
c)
102
{
103
maybe_cmd
=
false
;
104
tspc
=
false
;
105
line_num
= l;
106
column_num
= c;
107
tok_val
= tv;
108
type_tag
=
meta_rec_token
;
109
mc
.cr = cls;
110
mc
.pr = pkg;
111
}
112
113
token::token
(
int
tv,
symbol_table::symbol_record
*mth,
114
symbol_table::symbol_record
*cls,
115
symbol_table::symbol_record
*pkg,
int
l,
int
c)
116
{
117
maybe_cmd
=
false
;
118
tspc
=
false
;
119
line_num
= l;
120
column_num
= c;
121
tok_val
= tv;
122
type_tag
=
scls_rec_token
;
123
sc
.mr = mth;
124
sc
.cr = cls;
125
sc
.pr = pkg;
126
}
127
128
token::~token
(
void
)
129
{
130
if
(
type_tag
==
string_token
)
131
delete
str
;
132
}
133
134
std::string
135
token::text
(
void
)
const
136
{
137
assert (
type_tag
==
string_token
);
138
return
*
str
;
139
}
140
141
std::string
142
token::symbol_name
(
void
)
const
143
{
144
assert (
type_tag
==
sym_rec_token
);
145
return
sr
->
name
();
146
}
147
148
double
149
token::number
(
void
)
const
150
{
151
assert (
type_tag
==
double_token
);
152
return
num
;
153
}
154
155
token::token_type
156
token::ttype
(
void
)
const
157
{
158
return
type_tag
;
159
}
160
161
token::end_tok_type
162
token::ettype
(
void
)
const
163
{
164
assert (
type_tag
==
ettype_token
);
165
return
et
;
166
}
167
168
symbol_table::symbol_record
*
169
token::sym_rec
(
void
)
170
{
171
assert (
type_tag
==
sym_rec_token
);
172
return
sr
;
173
}
174
175
symbol_table::symbol_record
*
176
token::method_rec
(
void
)
177
{
178
assert (
type_tag
==
scls_rec_token
);
179
return
sc
.mr;
180
}
181
182
symbol_table::symbol_record
*
183
token::class_rec
(
void
)
184
{
185
assert (
type_tag
==
scls_rec_token
);
186
return
sc
.cr;
187
}
188
189
symbol_table::symbol_record
*
190
token::package_rec
(
void
)
191
{
192
assert (
type_tag
==
scls_rec_token
);
193
return
sc
.pr;
194
}
195
196
symbol_table::symbol_record
*
197
token::meta_class_rec
(
void
)
198
{
199
assert (
type_tag
==
meta_rec_token
);
200
return
mc
.cr;
201
}
202
203
symbol_table::symbol_record
*
204
token::meta_package_rec
(
void
)
205
{
206
assert (
type_tag
==
meta_rec_token
);
207
return
mc
.pr;
208
}
209
210
std::string
211
token::text_rep
(
void
)
212
{
213
return
orig_text
;
214
}
Generated on Mon Dec 30 2013 03:04:38 for GNU Octave by
1.8.1.2