GNU Octave  4.0.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-2015 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  };
45 
47  {
62  };
63 
64  token (int tv, int l = -1, int c = -1);
65  token (int tv, bool is_keyword, int l = -1, int c = -1);
66  token (int tv, const char *s, 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, const std::string& mth, const std::string& cls,
73  int l = -1, int c = -1);
74 
75  ~token (void);
76 
77  void mark_may_be_command (void) { maybe_cmd = true; }
78  bool may_be_command (void) const { return maybe_cmd; }
79 
80  void mark_trailing_space (void) { tspc = true; }
81  bool space_follows_token (void) const { return tspc; }
82 
83  int token_value (void) const { return tok_val; }
84  bool token_value_is (int tv) const { return tv == tok_val; }
85 
86  int line (void) const { return line_num; }
87  int column (void) const { return column_num; }
88 
89  bool is_keyword (void) const
90  {
91  return type_tag == keyword_token || type_tag == ettype_token;
92  }
93 
94  bool is_symbol (void) const
95  {
96  return type_tag == sym_rec_token;
97  }
98 
99  std::string text (void) const;
100  std::string symbol_name (void) const;
101  double number (void) const;
102  token_type ttype (void) const;
103  end_tok_type ettype (void) const;
104  symbol_table::symbol_record *sym_rec (void);
105 
106  std::string superclass_method_name (void);
107  std::string superclass_class_name (void);
108 
109  std::string text_rep (void);
110 
111 private:
112 
113  // No copying!
114 
115  token (const token& tok);
116 
117  token& operator = (const token& tok);
118 
119  bool maybe_cmd;
120  bool tspc;
121  int line_num;
123  int tok_val;
125  union
126  {
127  std::string *str;
128  double num;
131  struct
132  {
133  std::string *method_nm;
134  std::string *class_nm;
135  } sc;
136  };
137  std::string orig_text;
138 };
139 
140 #endif
bool token_value_is(int tv) const
Definition: token.h:84
int line_num
Definition: token.h:121
bool space_follows_token(void) const
Definition: token.h:81
token_type type_tag
Definition: token.h:124
int column(void) const
Definition: token.h:87
std::string orig_text
Definition: token.h:137
bool may_be_command(void) const
Definition: token.h:78
void mark_may_be_command(void)
Definition: token.h:77
int tok_val
Definition: token.h:123
int line(void) const
Definition: token.h:86
bool is_keyword(const std::string &s)
Definition: lex.cc:4522
double num
Definition: token.h:128
F77_RET_T const double const double double * d
end_tok_type
Definition: token.h:46
bool is_symbol(void) const
Definition: token.h:94
std::string * class_nm
Definition: token.h:134
bool is_keyword(void) const
Definition: token.h:89
std::string * method_nm
Definition: token.h:133
int column_num
Definition: token.h:122
symbol_table::symbol_record * sr
Definition: token.h:130
void mark_trailing_space(void)
Definition: token.h:80
token_type
Definition: token.h:35
int token_value(void) const
Definition: token.h:83
bool tspc
Definition: token.h:120
std::string * str
Definition: token.h:127
bool maybe_cmd
Definition: token.h:119
end_tok_type et
Definition: token.h:129
tree_walker & operator=(const tree_walker &)
Definition: token.h:30