home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / octave-1.1.1p1-base.tgz / octave-1.1.1p1-base.tar / fsf / octave / src / token.cc < prev    next >
C/C++ Source or Header  |  1995-01-03  |  3KB  |  153 lines

  1. // token.cc                                              -*- C++ -*-
  2. /*
  3.  
  4. Copyright (C) 1992, 1993, 1994, 1995 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 HAVE_CONFIG_H
  25. #include "config.h"
  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, int c)
  35. {
  36.   line_num = l;
  37.   column_num = c;
  38.   type_tag = generic_token;
  39.   orig_text = 0;
  40. }
  41.  
  42. token::token (char *s, int l, int c)
  43. {
  44.   line_num = l;
  45.   column_num = c;
  46.   type_tag = string_token;
  47.   str = strsave (s);
  48.   orig_text = 0;
  49. }
  50.  
  51. token::token (double d, char *s, int l, int c)
  52. {
  53.   line_num = l;
  54.   column_num = c;
  55.   type_tag = double_token;
  56.   num = d;
  57.   orig_text = strsave (s);
  58. }
  59.  
  60. token::token (end_tok_type t, int l, int c)
  61. {
  62.   line_num = l;
  63.   column_num = c;
  64.   type_tag = ettype_token;
  65.   et = t;
  66.   orig_text = 0;
  67. }
  68.  
  69. token::token (plot_tok_type t, int l, int c)
  70. {
  71.   line_num = l;
  72.   column_num = c;
  73.   type_tag = pttype_token;
  74.   pt = t;
  75.   orig_text = 0;
  76. }
  77.  
  78. token::token (symbol_record *s, int l, int c)
  79. {
  80.   line_num = l;
  81.   column_num = c;
  82.   type_tag = sym_rec_token;
  83.   sr = s;
  84.   orig_text = 0;
  85. }
  86.  
  87. token::~token (void)
  88. {
  89.   if (type_tag == string_token)
  90.     delete [] str;
  91.   delete [] orig_text;
  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.  
  141. char *
  142. token::text_rep (void)
  143. {
  144.   return orig_text;
  145. }
  146.  
  147. /*
  148. ;;; Local Variables: ***
  149. ;;; mode: C++ ***
  150. ;;; page-delimiter: "^/\\*" ***
  151. ;;; End: ***
  152. */
  153.