1 //********************************************************** 2 // CR_ABS.HPP 3 // Coco/R C++ Support Library. 4 // Author: Frankie Arzu <farzu@uvg.edu.gt> 5 // 6 // Jun 12, 1996 Version 1.06 7 // Many fixes and suggestions thanks to 8 // Pat Terry <p.terry@.ru.ac.za> 9 // May 05, 1999 Version 1.12 10 // Added options to retrieve token info 11 // Jun 20, 2001 12 // Virtual destructor added 13 //********************************************************** 14 15 #ifndef CR_ABS 16 #define CR_ABS 17 18 #include <stdlib.h> 19 20 class AbsToken { 21 // Abstract Token 22 public: ~AbsToken()23 virtual ~AbsToken() { } 24 int Sym; // Token Number 25 int Line, Col; // line and column of current Token 26 int Len; // length of current Token 27 long Pos; // file position of current Token GetSym()28 int GetSym() 29 { return Sym; } SetSym(int sym)30 int SetSym(int sym) 31 { return Sym = sym; }; GetPos()32 long GetPos() 33 { return Pos; }; Init(int sym=0,int line=0,int col=0,long pos=0,int len=0)34 void Init(int sym = 0, int line = 0, int col = 0, long pos = 0, int len = 0) 35 { Sym = sym; Line = line; Col = col; Pos = pos; Len = len; }; 36 }; 37 38 class AbsScanner { 39 // Abstract Scanner 40 public: ~AbsScanner()41 virtual ~AbsScanner() {} 42 43 AbsToken CurrSym; // current (most recently parsed) token 44 AbsToken NextSym; // next (look ahead) token 45 46 virtual int Get() = 0; 47 // Retrieves next token 48 49 virtual void Reset() = 0; 50 // Reset the scanner 51 52 virtual unsigned char CurrentCh(long pos) = 0; 53 // Returns character at position pos in source file 54 55 virtual void GetString(AbsToken *Sym, char *Buffer, int Max) = 0; 56 // Retrieves at most Max characters from Sym into Buffer 57 58 virtual void GetString(long Pos, char *Buffer, int Max) = 0; 59 // Retrieves at most Max characters from position Pos into Buffer 60 61 virtual void GetName(AbsToken *Sym, char *Buffer, int Max) = 0; 62 // Retrieves at most Max characters from Sym into Buffer 63 // Buffer is capitalized if IGNORE CASE was specified 64 65 virtual long GetLine(long Pos, char *Line, int Max) = 0; 66 // Retrieves at most Max characters (or until next line break) 67 // from position Pos in source file into Line 68 }; 69 70 class AbsError { 71 // Abstract Error Reporting 72 public: ~AbsError()73 virtual ~AbsError() { } 74 75 virtual void Store(int nr, int line, int col, long pos) = 0; 76 // Records that error nr has been detected at specified position 77 78 virtual void StoreErr(int nr, AbsToken &Token) = 0; 79 // Associates error nr with Token 80 81 virtual void StoreWarn(int nr, AbsToken &Token) = 0; 82 // Associates warning nr with Token 83 84 virtual void SummarizeErrors() = 0; 85 // Reports on all errors recorded 86 }; 87 88 #endif // CR_ABS 89 90