home *** CD-ROM | disk | FTP | other *** search
- #ifndef __SYNTACTIC__
- #define __SYNTACTIC__ 1
-
- #ifndef __TYPES__
- #include <types.h>
- #endif
-
-
- #pragma segment Syntactic
-
-
- /*
- ** Define the basic types that the abstract Syntactic class knows about
- */
- enum {
- kSErr = -1 // Error token
- , kSLex = 0 // Base enum for scanner generated tokens
- , kSPrs = 1000 // Base class for parser generated items
- };
-
-
- /*µ class Syntactic
- ** This class represents the basic syntactic items used by the scanner and the
- ** parser. It is the abstract base class for all derived tokens
- */
-
- class Formatting; // Class defining the format options
- class Syntactic : SingleObject {
- public:
- Syntactic(int aType, int aMinorType = 0);
-
- short Type() const;
- short MinorType() const;
- // Return the type of the syntactic item. We have type fields as
- // subclassing is not the right thing to do.
-
- Boolean IsLex() const;
- Boolean IsPrs() const;
- // Predicates returning the category of the Syntactic.
-
- virtual Boolean IsSeparator() const = 0;
- /*
- ** Return true if the syntactic item is whitespace or a comment
- */
-
- virtual const Syntactic *SaveCopy() const = 0;
- /*
- ** Return a copy of the object if the object is subject to
- ** modification by various operations. If the object cannot
- ** be modified by any of its methods, return itself.
- */
-
- virtual Boolean Display(Formatting *aFormat) = 0;
- /*
- ** Format and display this syntactic item. The format to use when
- ** displaying is passed in as its only argument. The function
- ** returns true if the token did write to the output stream,
- ** false if the token did not affect the output stream.
- */
-
-
- void SexChange(int aNewType);
- void MinorSexChange(int aNewType);
- // Changes the type of the syntactic item to the new type.
-
- private:
- short fType;
- short fMinorType;
- };
-
-
-
- //µ Syntactic::Syntactic
- #pragma segment Syntactic
- inline Syntactic::Syntactic(int aType, int aMinorType)
- : fType(aType),
- fMinorType(aMinorType)
- {
- }
-
-
- //µ Syntactic::Type
- #pragma segment Syntactic
- inline short Syntactic::Type() const
- {
- return (fType);
- }
-
-
- //µ Syntactic::MinorType
- #pragma segment Syntactic
- inline short Syntactic::MinorType() const
- {
- return (fMinorType);
- }
-
-
- //µ Syntactic::IsLex
- #pragma segment Syntactic
- inline Boolean Syntactic::IsLex() const
- {
- return (fType >= kSLex && fType < kSPrs);
- }
-
-
- //µ Syntactic::IsPrs
- #pragma segment Syntactic
- inline Boolean Syntactic::IsPrs() const
- {
- return (fType >= kSPrs);
- }
-
-
- //µ Syntactic::SexChange
- #pragma segment Syntactic
- inline void Syntactic::SexChange(int aNewType)
- {
- fType = aNewType;
- }
-
-
- //µ Syntactic::MinorSexChange
- #pragma segment Syntactic
- inline void Syntactic::MinorSexChange(int aNewType)
- {
- fMinorType = aNewType;
- }
-
-
- #endif
-
-
-