00001 //======================================================================== 00002 // 00003 // Lexer.h 00004 // 00005 // Copyright 1996-2002 Glyph & Cog, LLC 00006 // 00007 //======================================================================== 00008 00009 #ifndef LEXER_H 00010 #define LEXER_H 00011 00012 #ifdef __GNUC__ 00013 #pragma interface 00014 #endif 00015 00016 #include "Object.h" 00017 #include "Stream.h" 00018 00019 class XRef; 00020 00021 #define tokBufSize 128 // size of token buffer 00022 00023 //------------------------------------------------------------------------ 00024 // Lexer 00025 //------------------------------------------------------------------------ 00026 00027 class Lexer { 00028 public: 00029 00030 // Construct a lexer for a single stream. Deletes the stream when 00031 // lexer is deleted. 00032 Lexer(XRef *xref, Stream *str); 00033 00034 // Construct a lexer for a stream or array of streams (assumes obj 00035 // is either a stream or array of streams). 00036 Lexer(XRef *xref, Object *obj); 00037 00038 // Destructor. 00039 ~Lexer(); 00040 00041 // Get the next object from the input stream. 00042 Object *getObj(Object *obj); 00043 00044 // Skip to the beginning of the next line in the input stream. 00045 void skipToNextLine(); 00046 00047 // Skip over one character. 00048 void skipChar() { getChar(); } 00049 00050 // Get stream. 00051 Stream *getStream() 00052 { return curStr.isNone() ? (Stream *)NULL : curStr.getStream(); } 00053 00054 // Get current position in file. This is only used for error 00055 // messages, so it returns an int instead of a Guint. 00056 int getPos() 00057 { return curStr.isNone() ? -1 : (int)curStr.streamGetPos(); } 00058 00059 // Set position in file. 00060 void setPos(Guint pos, int dir = 0) 00061 { if (!curStr.isNone()) curStr.streamSetPos(pos, dir); } 00062 00063 private: 00064 00065 int getChar(); 00066 int lookChar(); 00067 00068 Array *streams; // array of input streams 00069 int strPtr; // index of current stream 00070 Object curStr; // current stream 00071 GBool freeArray; // should lexer free the streams array? 00072 char tokBuf[tokBufSize]; // temporary token buffer 00073 }; 00074 00075 #endif
1.4.2