GNU Octave  3.8.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
token.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1993-2013 John W. Eaton
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 3 of the License, or (at your
10 option) any 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, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if !defined (octave_token_h)
24 #define octave_token_h 1
25 
26 #include <string>
27 
28 #include "symtab.h"
29 
30 class
31 token
32 {
33 public:
34 
36  {
44  meta_rec_token
45  };
46 
48  {
62  unwind_protect_end
63  };
64 
65  token (int tv, int l = -1, int c = -1);
66  token (int tv, bool is_keyword, int l = -1, int c = -1);
67  token (int tv, const std::string& s, int l = -1, int c = -1);
68  token (int tv, double d, const std::string& s = std::string (),
69  int l = -1, int c = -1);
70  token (int tv, end_tok_type t, int l = -1, int c = -1);
71  token (int tv, symbol_table::symbol_record *s, int l = -1, int c = -1);
72  token (int tv, symbol_table::symbol_record *cls,
73  symbol_table::symbol_record *pkg, int l = -1, int c = -1);
74  token (int tv, symbol_table::symbol_record *mth,
76  symbol_table::symbol_record *pkg, int l = -1, int c = -1);
77 
78  ~token (void);
79 
80  void mark_may_be_command (void) { maybe_cmd = true; }
81  bool may_be_command (void) const { return maybe_cmd; }
82 
83  void mark_trailing_space (void) { tspc = true; }
84  bool space_follows_token (void) const { return tspc; }
85 
86  int token_value (void) const { return tok_val; }
87  bool token_value_is (int tv) const { return tv == tok_val; }
88 
89  int line (void) const { return line_num; }
90  int column (void) const { return column_num; }
91 
92  bool is_keyword (void) const
93  {
94  return type_tag == keyword_token || type_tag == ettype_token;
95  }
96 
97  bool is_symbol (void) const
98  {
99  return type_tag == sym_rec_token;
100  }
101 
102  std::string text (void) const;
103  std::string symbol_name (void) const;
104  double number (void) const;
105  token_type ttype (void) const;
106  end_tok_type ettype (void) const;
107  symbol_table::symbol_record *sym_rec (void);
108 
109  symbol_table::symbol_record *method_rec (void);
110  symbol_table::symbol_record *class_rec (void);
111  symbol_table::symbol_record *package_rec (void);
112 
113  symbol_table::symbol_record *meta_class_rec (void);
114  symbol_table::symbol_record *meta_package_rec (void);
115 
116  std::string text_rep (void);
117 
118 private:
119 
120  // No copying!
121 
122  token (const token& tok);
123 
124  token& operator = (const token& tok);
125 
126  bool maybe_cmd;
127  bool tspc;
128  int line_num;
130  int tok_val;
132  union
133  {
134  std::string *str;
135  double num;
138  struct
139  {
143  } sc;
144  struct
145  {
148  } mc;
149  };
150  std::string orig_text;
151 };
152 
153 #endif