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 |
|
30 #include "token.h" |
|
31 #include "utils.h" |
|
32 #include "symtab.h" |
|
33 |
529
|
34 token::token (int l, int c) |
142
|
35 { |
|
36 line_num = l; |
|
37 column_num = c; |
|
38 type_tag = generic_token; |
581
|
39 orig_text = 0; |
142
|
40 } |
|
41 |
529
|
42 token::token (char *s, int l, int c) |
142
|
43 { |
|
44 line_num = l; |
|
45 column_num = c; |
|
46 type_tag = string_token; |
|
47 str = strsave (s); |
581
|
48 orig_text = 0; |
142
|
49 } |
|
50 |
581
|
51 token::token (double d, char *s, int l, int c) |
142
|
52 { |
|
53 line_num = l; |
|
54 column_num = c; |
|
55 type_tag = double_token; |
|
56 num = d; |
581
|
57 orig_text = strsave (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; |
581
|
66 orig_text = 0; |
142
|
67 } |
|
68 |
529
|
69 token::token (plot_tok_type t, int l, int c) |
142
|
70 { |
|
71 line_num = l; |
|
72 column_num = c; |
|
73 type_tag = pttype_token; |
|
74 pt = t; |
581
|
75 orig_text = 0; |
142
|
76 } |
|
77 |
529
|
78 token::token (symbol_record *s, int l, int c) |
142
|
79 { |
|
80 line_num = l; |
|
81 column_num = c; |
|
82 type_tag = sym_rec_token; |
|
83 sr = s; |
581
|
84 orig_text = 0; |
142
|
85 } |
|
86 |
|
87 token::~token (void) |
|
88 { |
|
89 if (type_tag == string_token) |
|
90 delete [] str; |
581
|
91 delete [] orig_text; |
142
|
92 } |
|
93 |
|
94 int |
|
95 token::line (void) |
|
96 { |
|
97 return line_num; |
|
98 } |
|
99 |
|
100 int |
|
101 token::column (void) |
|
102 { |
|
103 return column_num; |
|
104 } |
|
105 |
|
106 char * |
|
107 token::string (void) |
|
108 { |
|
109 assert (type_tag == string_token); |
|
110 return str; |
|
111 } |
|
112 |
|
113 double |
|
114 token::number (void) |
|
115 { |
|
116 assert (type_tag == double_token); |
|
117 return num; |
|
118 } |
|
119 |
|
120 token::end_tok_type |
|
121 token::ettype (void) |
|
122 { |
|
123 assert (type_tag == ettype_token); |
|
124 return et; |
|
125 } |
|
126 |
|
127 token::plot_tok_type |
|
128 token::pttype (void) |
|
129 { |
|
130 assert (type_tag == pttype_token); |
|
131 return pt; |
|
132 } |
|
133 |
|
134 symbol_record * |
|
135 token::sym_rec (void) |
|
136 { |
|
137 assert (type_tag == sym_rec_token); |
|
138 return sr; |
|
139 } |
|
140 |
581
|
141 char * |
|
142 token::text_rep (void) |
|
143 { |
|
144 return orig_text; |
|
145 } |
|
146 |
142
|
147 /* |
|
148 ;;; Local Variables: *** |
|
149 ;;; mode: C++ *** |
|
150 ;;; page-delimiter: "^/\\*" *** |
|
151 ;;; End: *** |
|
152 */ |