142
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
142
|
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 2, or (at your option) any |
|
10 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, write to the Free |
1315
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
142
|
20 |
|
21 */ |
|
22 |
4066
|
23 #if defined (__GNUG__) && ! defined (NO_PRAGMA_INTERFACE_IMPLEMENTATION) |
1297
|
24 #pragma implementation |
|
25 #endif |
|
26 |
240
|
27 #ifdef HAVE_CONFIG_H |
1192
|
28 #include <config.h> |
142
|
29 #endif |
|
30 |
1343
|
31 #include <cassert> |
142
|
32 |
1288
|
33 #include "error.h" |
4055
|
34 #include "oct-obj.h" |
1352
|
35 #include "symtab.h" |
142
|
36 #include "token.h" |
|
37 #include "utils.h" |
|
38 |
529
|
39 token::token (int l, int c) |
142
|
40 { |
|
41 line_num = l; |
|
42 column_num = c; |
|
43 type_tag = generic_token; |
|
44 } |
|
45 |
3523
|
46 token::token (const std::string& s, int l, int c) |
142
|
47 { |
|
48 line_num = l; |
|
49 column_num = c; |
|
50 type_tag = string_token; |
3523
|
51 str = new std::string (s); |
142
|
52 } |
|
53 |
3523
|
54 token::token (double d, const std::string& s, int l, int c) |
142
|
55 { |
|
56 line_num = l; |
|
57 column_num = c; |
|
58 type_tag = double_token; |
|
59 num = d; |
1971
|
60 orig_text = s; |
142
|
61 } |
|
62 |
529
|
63 token::token (end_tok_type t, int l, int c) |
142
|
64 { |
|
65 line_num = l; |
|
66 column_num = c; |
|
67 type_tag = ettype_token; |
|
68 et = t; |
|
69 } |
|
70 |
529
|
71 token::token (plot_tok_type t, int l, int c) |
142
|
72 { |
|
73 line_num = l; |
|
74 column_num = c; |
|
75 type_tag = pttype_token; |
|
76 pt = t; |
|
77 } |
|
78 |
529
|
79 token::token (symbol_record *s, int l, int c) |
142
|
80 { |
|
81 line_num = l; |
|
82 column_num = c; |
|
83 type_tag = sym_rec_token; |
|
84 sr = s; |
|
85 } |
|
86 |
|
87 token::~token (void) |
|
88 { |
|
89 if (type_tag == string_token) |
1755
|
90 delete str; |
142
|
91 } |
|
92 |
3536
|
93 std::string |
1755
|
94 token::text (void) |
142
|
95 { |
|
96 assert (type_tag == string_token); |
1755
|
97 return *str; |
142
|
98 } |
|
99 |
|
100 double |
|
101 token::number (void) |
|
102 { |
|
103 assert (type_tag == double_token); |
|
104 return num; |
|
105 } |
|
106 |
|
107 token::end_tok_type |
|
108 token::ettype (void) |
|
109 { |
|
110 assert (type_tag == ettype_token); |
|
111 return et; |
|
112 } |
|
113 |
|
114 token::plot_tok_type |
|
115 token::pttype (void) |
|
116 { |
|
117 assert (type_tag == pttype_token); |
|
118 return pt; |
|
119 } |
|
120 |
|
121 symbol_record * |
|
122 token::sym_rec (void) |
|
123 { |
|
124 assert (type_tag == sym_rec_token); |
|
125 return sr; |
|
126 } |
|
127 |
3536
|
128 std::string |
581
|
129 token::text_rep (void) |
|
130 { |
|
131 return orig_text; |
|
132 } |
|
133 |
142
|
134 /* |
|
135 ;;; Local Variables: *** |
|
136 ;;; mode: C++ *** |
|
137 ;;; End: *** |
|
138 */ |