home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / B-C / C++Source Code Fmtr Folder / Src / Syntactic.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-27  |  2.7 KB  |  133 lines  |  [TEXT/MPS ]

  1. #ifndef __SYNTACTIC__
  2. #define __SYNTACTIC__    1
  3.  
  4. #ifndef __TYPES__
  5. #include <types.h>
  6. #endif
  7.  
  8.  
  9. #pragma segment Syntactic
  10.  
  11.  
  12. /*
  13. ** Define the basic types that the abstract Syntactic class knows about
  14. */
  15. enum {
  16.     kSErr = -1                                    // Error token
  17.     , kSLex = 0                                    // Base enum for scanner generated tokens
  18.     , kSPrs = 1000                                // Base class for parser generated items
  19. };
  20.  
  21.  
  22. /*µ class Syntactic
  23. **    This class represents the basic syntactic items used by the scanner and the
  24. ** parser.  It is the abstract base class for all derived tokens
  25. */
  26.  
  27. class Formatting;                                // Class defining the format options
  28. class Syntactic : SingleObject {
  29. public:
  30.     Syntactic(int aType, int aMinorType = 0);
  31.  
  32.     short Type() const;
  33.     short MinorType() const;
  34.     // Return the type of the syntactic item.  We have type fields as
  35.     // subclassing is not the right thing to do.
  36.  
  37.     Boolean IsLex() const;
  38.     Boolean IsPrs() const;
  39.     // Predicates returning the category of the Syntactic.
  40.  
  41.     virtual Boolean IsSeparator() const = 0;
  42.     /*
  43.     ** Return true if the syntactic item is whitespace or a comment
  44.     */
  45.  
  46.     virtual const Syntactic *SaveCopy() const = 0;
  47.     /*
  48.     ** Return a copy of the object if the object is subject to
  49.     ** modification by various operations.  If the object cannot
  50.     ** be modified by any of its methods, return itself.
  51.     */
  52.  
  53.     virtual Boolean Display(Formatting *aFormat) = 0;
  54.     /*
  55.     ** Format and display this syntactic item.  The format to use when
  56.     ** displaying is passed in as its only argument.  The function
  57.     ** returns true if the token did write to the output stream,
  58.     ** false if the token did not affect the output stream.
  59.     */
  60.  
  61.  
  62.     void SexChange(int aNewType);
  63.     void MinorSexChange(int aNewType);
  64.     // Changes the type of the syntactic item to the new type.
  65.  
  66. private:
  67.     short fType;
  68.     short fMinorType;
  69. };
  70.  
  71.  
  72.  
  73. //µ   Syntactic::Syntactic
  74. #pragma segment Syntactic
  75. inline Syntactic::Syntactic(int aType, int aMinorType)
  76.     : fType(aType),
  77.       fMinorType(aMinorType)
  78.     {
  79.     }
  80.  
  81.  
  82. //µ   Syntactic::Type
  83. #pragma segment Syntactic
  84. inline short Syntactic::Type() const
  85. {
  86.     return (fType);
  87. }
  88.  
  89.  
  90. //µ   Syntactic::MinorType
  91. #pragma segment Syntactic
  92. inline short Syntactic::MinorType() const
  93. {
  94.     return (fMinorType);
  95. }
  96.  
  97.  
  98. //µ   Syntactic::IsLex
  99. #pragma segment Syntactic
  100. inline Boolean Syntactic::IsLex() const
  101. {
  102.     return (fType >= kSLex && fType < kSPrs);
  103. }
  104.  
  105.  
  106. //µ   Syntactic::IsPrs
  107. #pragma segment Syntactic
  108. inline Boolean Syntactic::IsPrs() const
  109. {
  110.     return (fType >= kSPrs);
  111. }
  112.  
  113.  
  114. //µ   Syntactic::SexChange
  115. #pragma segment Syntactic
  116. inline void Syntactic::SexChange(int aNewType)
  117. {
  118.     fType = aNewType;
  119. }
  120.  
  121.  
  122. //µ   Syntactic::MinorSexChange
  123. #pragma segment Syntactic
  124. inline void Syntactic::MinorSexChange(int aNewType)
  125. {
  126.     fMinorType = aNewType;
  127. }
  128.  
  129.  
  130. #endif
  131.  
  132.  
  133.