token.h

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 1993-2012 John W. Eaton
00004 
00005 This file is part of Octave.
00006 
00007 Octave is free software; you can redistribute it and/or modify it
00008 under the terms of the GNU General Public License as published by the
00009 Free Software Foundation; either version 3 of the License, or (at your
00010 option) any later version.
00011 
00012 Octave is distributed in the hope that it will be useful, but WITHOUT
00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00015 for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Octave; see the file COPYING.  If not, see
00019 <http://www.gnu.org/licenses/>.
00020 
00021 */
00022 
00023 #if !defined (octave_token_h)
00024 #define octave_token_h 1
00025 
00026 #include <string>
00027 
00028 class
00029 token
00030 {
00031 public:
00032 
00033   enum token_type
00034     {
00035       generic_token,
00036       string_token,
00037       double_token,
00038       ettype_token,
00039       sym_rec_token,
00040       scls_rec_token,
00041       meta_rec_token
00042     };
00043 
00044   enum end_tok_type
00045     {
00046       simple_end,
00047       classdef_end,
00048       enumeration_end,
00049       events_end,
00050       for_end,
00051       function_end,
00052       if_end,
00053       methods_end,
00054       parfor_end,
00055       properties_end,
00056       switch_end,
00057       while_end,
00058       try_catch_end,
00059       unwind_protect_end
00060     };
00061 
00062   token (int l = -1, int c = -1);
00063   token (const std::string& s, int l = -1, int c = -1);
00064   token (double d, const std::string& s = std::string (),
00065          int l = -1, int c = -1);
00066   token (end_tok_type t, int l = -1, int c = -1);
00067   token (symbol_table::symbol_record *s, int l = -1, int c = -1);
00068   token (symbol_table::symbol_record *cls,
00069          symbol_table::symbol_record *pkg, int l = -1, int c = -1);
00070   token (symbol_table::symbol_record *mth,
00071          symbol_table::symbol_record *cls,
00072          symbol_table::symbol_record *pkg, int l = -1, int c = -1);
00073 
00074   ~token (void);
00075 
00076   int line (void) { return line_num; }
00077   int column (void) { return column_num; }
00078 
00079   std::string text (void);
00080   double number (void);
00081   end_tok_type ettype (void);
00082   symbol_table::symbol_record *sym_rec (void);
00083 
00084   symbol_table::symbol_record *method_rec (void);
00085   symbol_table::symbol_record *class_rec (void);
00086   symbol_table::symbol_record *package_rec (void);
00087 
00088   symbol_table::symbol_record *meta_class_rec (void);
00089   symbol_table::symbol_record *meta_package_rec (void);
00090 
00091   std::string text_rep (void);
00092 
00093 private:
00094 
00095   // No copying!
00096 
00097   token (const token& tok);
00098 
00099   token& operator = (const token& tok);
00100 
00101   int line_num;
00102   int column_num;
00103   token_type type_tag;
00104   union
00105     {
00106       std::string *str;
00107       double num;
00108       end_tok_type et;
00109       symbol_table::symbol_record *sr;
00110       struct
00111         {
00112           symbol_table::symbol_record *mr;
00113           symbol_table::symbol_record *cr;
00114           symbol_table::symbol_record *pr;
00115         } sc;
00116       struct
00117         {
00118           symbol_table::symbol_record *cr;
00119           symbol_table::symbol_record *pr;
00120         } mc;
00121     };
00122   std::string orig_text;
00123 };
00124 
00125 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines