home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pccts.zip / pccts / h / AToken.h < prev    next >
C/C++ Source or Header  |  1994-03-31  |  3KB  |  103 lines

  1. /* AToken.h
  2.  *
  3.  * SOFTWARE RIGHTS
  4.  *
  5.  * We reserve no LEGAL rights to the Purdue Compiler Construction Tool
  6.  * Set (PCCTS) -- PCCTS is in the public domain.  An individual or
  7.  * company may do whatever they wish with source code distributed with
  8.  * PCCTS or the code generated by PCCTS, including the incorporation of
  9.  * PCCTS, or its output, into commerical software.
  10.  * 
  11.  * We encourage users to develop software with PCCTS.  However, we do ask
  12.  * that credit is given to us for developing PCCTS.  By "credit",
  13.  * we mean that if you incorporate our source code into one of your
  14.  * programs (commercial product, research project, or otherwise) that you
  15.  * acknowledge this fact somewhere in the documentation, research report,
  16.  * etc...  If you like PCCTS and have developed a nice tool with the
  17.  * output, please mention that you developed it using PCCTS.  In
  18.  * addition, we ask that this header remain intact in our source code.
  19.  * As long as these guidelines are kept, we expect to continue enhancing
  20.  * this system and expect to make other tools available as they are
  21.  * completed.
  22.  *
  23.  * ANTLR 1.20
  24.  * Terence Parr
  25.  * Purdue University
  26.  * With AHPCRC, University of Minnesota
  27.  * 1989-1994
  28.  */
  29.  
  30. #ifndef ATOKEN_H
  31. #define ATOKEN_H
  32.  
  33. #include <string.h>
  34.  
  35. #ifndef ANTLRCommonTokenTEXTSIZE
  36. #define ANTLRCommonTokenTEXTSIZE    100
  37. #endif
  38.  
  39. /* must define what a char looks like; can make this a class too */
  40. typedef char ANTLRChar;
  41.  
  42. // What does an ANTLR Token look like?
  43. // Must not have virtual functions so that min token size can be sizeof('int').
  44. // This could an abstract class, but we don't want the vtable pointers
  45. class ANTLRTokenBase {
  46. protected:
  47.     TokenType _type;
  48. public:
  49.     TokenType getType() { return _type; }
  50.     void setType(TokenType t) { _type = t; }
  51.  
  52.     /* Define to satisfy ANTLR error mechanism */
  53.     ANTLRChar *getText() { return ""; }
  54. };
  55.  
  56. // if you are using DLG, your token def must derive from this class
  57. // min Token size is sizeof(TokenType) + space for virtual function table.
  58. class DLGBasedToken : public ANTLRTokenBase {
  59. public:
  60.     DLGBasedToken(TokenType t) { setType(t); }
  61.     DLGBasedToken() {;}
  62.     virtual void setText(ANTLRChar *s) = 0;
  63.     virtual ANTLRChar *getText() = 0;
  64.     /* must define makeToken() so that DLG knows how to fill in a token;
  65.      * you can redefine it to do whatever you want
  66.      */
  67.     virtual void makeToken(TokenType t, ANTLRChar *s)
  68.     {
  69.         setType(t); setText(s);
  70.     }
  71. };
  72.  
  73. class ANTLRCommonToken : public DLGBasedToken {
  74. protected:
  75.     ANTLRChar _text[ANTLRCommonTokenTEXTSIZE+1];
  76. public:
  77.     ANTLRCommonToken(TokenType t, ANTLRChar *s) : DLGBasedToken(t)
  78.             { setText(s); }
  79.     ANTLRCommonToken() {;}
  80.     ANTLRChar *getText() { return _text; }
  81.     void setText(ANTLRChar *s) { strncpy(_text, s, ANTLRCommonTokenTEXTSIZE); }
  82. };
  83.  
  84. /* Example of creation of ANTLRToken:
  85.    ANTLRToken must have constructor kinda like old zzcr_attr().  The args
  86.    to the constructor must be exactly as shown below (number/type).
  87.    The destructor (if any) can do what it wants.
  88.  
  89.    The type 'ANTLRToken' must be defined for ANTLR.  This class can
  90.    be anything you want if you use "typedef mytokenclass ANTLRToken;".
  91.  
  92. class ANTLRToken : public DLGBasedToken {
  93.     int muck;
  94. public:
  95.     ANTLRToken(TokenType t, ANTLRChar *s) : ANTLRBasedToken(t,s)
  96.         { muck = atoi(s); }
  97.     ANTLRToken() { muck = 0; }
  98. };
  99.  
  100. */
  101.  
  102. #endif
  103.