142
|
1 /* |
|
2 |
7017
|
3 Copyright (C) 1993, 1994, 1995, 1996, 1997, 2000, 2002, 2004, 2005, |
|
4 2007 John W. Eaton |
142
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
7016
|
10 Free Software Foundation; either version 3 of the License, or (at your |
|
11 option) any later version. |
142
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
7016
|
19 along with Octave; see the file COPYING. If not, see |
|
20 <http://www.gnu.org/licenses/>. |
142
|
21 |
|
22 */ |
|
23 |
240
|
24 #ifdef HAVE_CONFIG_H |
1192
|
25 #include <config.h> |
142
|
26 #endif |
|
27 |
1343
|
28 #include <cassert> |
142
|
29 |
1288
|
30 #include "error.h" |
4055
|
31 #include "oct-obj.h" |
1352
|
32 #include "symtab.h" |
142
|
33 #include "token.h" |
|
34 #include "utils.h" |
|
35 |
529
|
36 token::token (int l, int c) |
142
|
37 { |
|
38 line_num = l; |
|
39 column_num = c; |
|
40 type_tag = generic_token; |
|
41 } |
|
42 |
3523
|
43 token::token (const std::string& s, int l, int c) |
142
|
44 { |
|
45 line_num = l; |
|
46 column_num = c; |
|
47 type_tag = string_token; |
3523
|
48 str = new std::string (s); |
142
|
49 } |
|
50 |
3523
|
51 token::token (double d, const std::string& s, int l, int c) |
142
|
52 { |
|
53 line_num = l; |
|
54 column_num = c; |
|
55 type_tag = double_token; |
|
56 num = d; |
1971
|
57 orig_text = s; |
142
|
58 } |
|
59 |
529
|
60 token::token (end_tok_type t, int l, int c) |
142
|
61 { |
|
62 line_num = l; |
|
63 column_num = c; |
|
64 type_tag = ettype_token; |
|
65 et = t; |
|
66 } |
|
67 |
529
|
68 token::token (plot_tok_type t, int l, int c) |
142
|
69 { |
|
70 line_num = l; |
|
71 column_num = c; |
|
72 type_tag = pttype_token; |
|
73 pt = t; |
|
74 } |
|
75 |
529
|
76 token::token (symbol_record *s, int l, int c) |
142
|
77 { |
|
78 line_num = l; |
|
79 column_num = c; |
|
80 type_tag = sym_rec_token; |
|
81 sr = s; |
|
82 } |
|
83 |
|
84 token::~token (void) |
|
85 { |
|
86 if (type_tag == string_token) |
1755
|
87 delete str; |
142
|
88 } |
|
89 |
3536
|
90 std::string |
1755
|
91 token::text (void) |
142
|
92 { |
|
93 assert (type_tag == string_token); |
1755
|
94 return *str; |
142
|
95 } |
|
96 |
|
97 double |
|
98 token::number (void) |
|
99 { |
|
100 assert (type_tag == double_token); |
|
101 return num; |
|
102 } |
|
103 |
|
104 token::end_tok_type |
|
105 token::ettype (void) |
|
106 { |
|
107 assert (type_tag == ettype_token); |
|
108 return et; |
|
109 } |
|
110 |
|
111 token::plot_tok_type |
|
112 token::pttype (void) |
|
113 { |
|
114 assert (type_tag == pttype_token); |
|
115 return pt; |
|
116 } |
|
117 |
|
118 symbol_record * |
|
119 token::sym_rec (void) |
|
120 { |
|
121 assert (type_tag == sym_rec_token); |
|
122 return sr; |
|
123 } |
|
124 |
3536
|
125 std::string |
581
|
126 token::text_rep (void) |
|
127 { |
|
128 return orig_text; |
|
129 } |
|
130 |
142
|
131 /* |
|
132 ;;; Local Variables: *** |
|
133 ;;; mode: C++ *** |
|
134 ;;; End: *** |
|
135 */ |