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 |
|
20 Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
21 |
|
22 */ |
|
23 |
240
|
24 #ifdef HAVE_CONFIG_H |
1192
|
25 #include <config.h> |
142
|
26 #endif |
|
27 |
|
28 #include <assert.h> |
|
29 |
1288
|
30 #include "error.h" |
142
|
31 #include "token.h" |
|
32 #include "utils.h" |
|
33 #include "symtab.h" |
|
34 |
529
|
35 token::token (int l, int c) |
142
|
36 { |
|
37 line_num = l; |
|
38 column_num = c; |
|
39 type_tag = generic_token; |
581
|
40 orig_text = 0; |
142
|
41 } |
|
42 |
529
|
43 token::token (char *s, int l, int c) |
142
|
44 { |
|
45 line_num = l; |
|
46 column_num = c; |
|
47 type_tag = string_token; |
|
48 str = strsave (s); |
581
|
49 orig_text = 0; |
142
|
50 } |
|
51 |
581
|
52 token::token (double d, char *s, int l, int c) |
142
|
53 { |
|
54 line_num = l; |
|
55 column_num = c; |
|
56 type_tag = double_token; |
|
57 num = d; |
1288
|
58 orig_text = 0; // strsave (s); |
142
|
59 } |
|
60 |
529
|
61 token::token (end_tok_type t, int l, int c) |
142
|
62 { |
|
63 line_num = l; |
|
64 column_num = c; |
|
65 type_tag = ettype_token; |
|
66 et = t; |
581
|
67 orig_text = 0; |
142
|
68 } |
|
69 |
529
|
70 token::token (plot_tok_type t, int l, int c) |
142
|
71 { |
|
72 line_num = l; |
|
73 column_num = c; |
|
74 type_tag = pttype_token; |
|
75 pt = t; |
581
|
76 orig_text = 0; |
142
|
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; |
581
|
85 orig_text = 0; |
142
|
86 } |
|
87 |
|
88 token::~token (void) |
|
89 { |
|
90 if (type_tag == string_token) |
|
91 delete [] str; |
581
|
92 delete [] orig_text; |
142
|
93 } |
|
94 |
|
95 int |
|
96 token::line (void) |
|
97 { |
|
98 return line_num; |
|
99 } |
|
100 |
|
101 int |
|
102 token::column (void) |
|
103 { |
|
104 return column_num; |
|
105 } |
|
106 |
|
107 char * |
|
108 token::string (void) |
|
109 { |
|
110 assert (type_tag == string_token); |
|
111 return str; |
|
112 } |
|
113 |
|
114 double |
|
115 token::number (void) |
|
116 { |
|
117 assert (type_tag == double_token); |
|
118 return num; |
|
119 } |
|
120 |
|
121 token::end_tok_type |
|
122 token::ettype (void) |
|
123 { |
|
124 assert (type_tag == ettype_token); |
|
125 return et; |
|
126 } |
|
127 |
|
128 token::plot_tok_type |
|
129 token::pttype (void) |
|
130 { |
|
131 assert (type_tag == pttype_token); |
|
132 return pt; |
|
133 } |
|
134 |
|
135 symbol_record * |
|
136 token::sym_rec (void) |
|
137 { |
|
138 assert (type_tag == sym_rec_token); |
|
139 return sr; |
|
140 } |
|
141 |
581
|
142 char * |
|
143 token::text_rep (void) |
|
144 { |
|
145 return orig_text; |
|
146 } |
|
147 |
1288
|
148 token::token (const token& tok) |
|
149 { |
|
150 panic_impossible (); |
|
151 } |
|
152 |
|
153 token& |
|
154 operator = (const token& tok) |
|
155 { |
|
156 panic_impossible (); |
|
157 } |
|
158 |
142
|
159 /* |
|
160 ;;; Local Variables: *** |
|
161 ;;; mode: C++ *** |
|
162 ;;; page-delimiter: "^/\\*" *** |
|
163 ;;; End: *** |
|
164 */ |