142
|
1 // token.cc -*- C++ -*- |
|
2 /* |
|
3 |
|
4 Copyright (C) 1992, 1993 John W. Eaton |
|
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 |
|
24 #ifdef __GNUG__ |
|
25 #pragma implementation |
|
26 #endif |
|
27 |
|
28 #include <assert.h> |
|
29 |
|
30 #include "token.h" |
|
31 #include "utils.h" |
|
32 #include "symtab.h" |
|
33 |
|
34 token::token (int l = -1, int c = -1) |
|
35 { |
|
36 line_num = l; |
|
37 column_num = c; |
|
38 type_tag = generic_token; |
|
39 } |
|
40 |
|
41 token::token (char *s, int l = -1, int c = -1) |
|
42 { |
|
43 line_num = l; |
|
44 column_num = c; |
|
45 type_tag = string_token; |
|
46 str = strsave (s); |
|
47 } |
|
48 |
|
49 token::token (double d, int l = -1, int c = -1) |
|
50 { |
|
51 line_num = l; |
|
52 column_num = c; |
|
53 type_tag = double_token; |
|
54 num = d; |
|
55 } |
|
56 |
|
57 token::token (end_tok_type t, int l = -1, int c = -1) |
|
58 { |
|
59 line_num = l; |
|
60 column_num = c; |
|
61 type_tag = ettype_token; |
|
62 et = t; |
|
63 } |
|
64 |
|
65 token::token (plot_tok_type t, int l = -1, int c = -1) |
|
66 { |
|
67 line_num = l; |
|
68 column_num = c; |
|
69 type_tag = pttype_token; |
|
70 pt = t; |
|
71 } |
|
72 |
|
73 token::token (symbol_record *s, int l = -1, int c = -1) |
|
74 { |
|
75 line_num = l; |
|
76 column_num = c; |
|
77 type_tag = sym_rec_token; |
|
78 sr = s; |
|
79 } |
|
80 |
|
81 token::~token (void) |
|
82 { |
|
83 if (type_tag == string_token) |
|
84 delete [] str; |
|
85 } |
|
86 |
|
87 int |
|
88 token::line (void) |
|
89 { |
|
90 return line_num; |
|
91 } |
|
92 |
|
93 int |
|
94 token::column (void) |
|
95 { |
|
96 return column_num; |
|
97 } |
|
98 |
|
99 char * |
|
100 token::string (void) |
|
101 { |
|
102 assert (type_tag == string_token); |
|
103 return str; |
|
104 } |
|
105 |
|
106 double |
|
107 token::number (void) |
|
108 { |
|
109 assert (type_tag == double_token); |
|
110 return num; |
|
111 } |
|
112 |
|
113 token::end_tok_type |
|
114 token::ettype (void) |
|
115 { |
|
116 assert (type_tag == ettype_token); |
|
117 return et; |
|
118 } |
|
119 |
|
120 token::plot_tok_type |
|
121 token::pttype (void) |
|
122 { |
|
123 assert (type_tag == pttype_token); |
|
124 return pt; |
|
125 } |
|
126 |
|
127 symbol_record * |
|
128 token::sym_rec (void) |
|
129 { |
|
130 assert (type_tag == sym_rec_token); |
|
131 return sr; |
|
132 } |
|
133 |
|
134 /* |
|
135 ;;; Local Variables: *** |
|
136 ;;; mode: C++ *** |
|
137 ;;; page-delimiter: "^/\\*" *** |
|
138 ;;; End: *** |
|
139 */ |