Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

Lexer.h

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

Generated on Wed Nov 3 12:58:59 2004 for Lemur Toolkit by doxygen1.2.18