142
|
1 // token.cc -*- C++ -*- |
|
2 /* |
|
3 |
1009
|
4 Copyright (C) 1992, 1993, 1994, 1995 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 |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
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 |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
1315
|
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
142
|
21 |
|
22 */ |
|
23 |
1297
|
24 #if defined (__GNUG__) |
|
25 #pragma implementation |
|
26 #endif |
|
27 |
240
|
28 #ifdef HAVE_CONFIG_H |
1192
|
29 #include <config.h> |
142
|
30 #endif |
|
31 |
|
32 #include <assert.h> |
|
33 |
1288
|
34 #include "error.h" |
142
|
35 #include "token.h" |
|
36 #include "utils.h" |
|
37 #include "symtab.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; |
581
|
44 orig_text = 0; |
142
|
45 } |
|
46 |
529
|
47 token::token (char *s, int l, int c) |
142
|
48 { |
|
49 line_num = l; |
|
50 column_num = c; |
|
51 type_tag = string_token; |
|
52 str = strsave (s); |
581
|
53 orig_text = 0; |
142
|
54 } |
|
55 |
581
|
56 token::token (double d, char *s, int l, int c) |
142
|
57 { |
|
58 line_num = l; |
|
59 column_num = c; |
|
60 type_tag = double_token; |
|
61 num = d; |
1288
|
62 orig_text = 0; // strsave (s); |
142
|
63 } |
|
64 |
529
|
65 token::token (end_tok_type t, int l, int c) |
142
|
66 { |
|
67 line_num = l; |
|
68 column_num = c; |
|
69 type_tag = ettype_token; |
|
70 et = t; |
581
|
71 orig_text = 0; |
142
|
72 } |
|
73 |
529
|
74 token::token (plot_tok_type t, int l, int c) |
142
|
75 { |
|
76 line_num = l; |
|
77 column_num = c; |
|
78 type_tag = pttype_token; |
|
79 pt = t; |
581
|
80 orig_text = 0; |
142
|
81 } |
|
82 |
529
|
83 token::token (symbol_record *s, int l, int c) |
142
|
84 { |
|
85 line_num = l; |
|
86 column_num = c; |
|
87 type_tag = sym_rec_token; |
|
88 sr = s; |
581
|
89 orig_text = 0; |
142
|
90 } |
|
91 |
|
92 token::~token (void) |
|
93 { |
|
94 if (type_tag == string_token) |
|
95 delete [] str; |
581
|
96 delete [] orig_text; |
142
|
97 } |
|
98 |
|
99 int |
|
100 token::line (void) |
|
101 { |
|
102 return line_num; |
|
103 } |
|
104 |
|
105 int |
|
106 token::column (void) |
|
107 { |
|
108 return column_num; |
|
109 } |
|
110 |
|
111 char * |
|
112 token::string (void) |
|
113 { |
|
114 assert (type_tag == string_token); |
|
115 return str; |
|
116 } |
|
117 |
|
118 double |
|
119 token::number (void) |
|
120 { |
|
121 assert (type_tag == double_token); |
|
122 return num; |
|
123 } |
|
124 |
|
125 token::end_tok_type |
|
126 token::ettype (void) |
|
127 { |
|
128 assert (type_tag == ettype_token); |
|
129 return et; |
|
130 } |
|
131 |
|
132 token::plot_tok_type |
|
133 token::pttype (void) |
|
134 { |
|
135 assert (type_tag == pttype_token); |
|
136 return pt; |
|
137 } |
|
138 |
|
139 symbol_record * |
|
140 token::sym_rec (void) |
|
141 { |
|
142 assert (type_tag == sym_rec_token); |
|
143 return sr; |
|
144 } |
|
145 |
581
|
146 char * |
|
147 token::text_rep (void) |
|
148 { |
|
149 return orig_text; |
|
150 } |
|
151 |
1288
|
152 token::token (const token& tok) |
|
153 { |
|
154 panic_impossible (); |
|
155 } |
|
156 |
|
157 token& |
1289
|
158 token::operator = (const token& tok) |
1288
|
159 { |
|
160 panic_impossible (); |
|
161 } |
|
162 |
142
|
163 /* |
|
164 ;;; Local Variables: *** |
|
165 ;;; mode: C++ *** |
|
166 ;;; page-delimiter: "^/\\*" *** |
|
167 ;;; End: *** |
|
168 */ |