// The source handler provides the language specification to the parser
// in the form of a stream of characters.  It has the secondary role of
// providing a listing of the input source.  Character lookaheads are
// provided by the line buffer which also records column positions.

class Buffer {
public:
	enum { MAXBUFFERSPACE = 255 };
private:
	char contents[MAXBUFFERSPACE+1];
	int _charPosition;
	void init() { contents[_charPosition = 0] = '\0'; }
public:
	int charPosition() { return _charPosition; }
	int empty() { return(contents[_charPosition] == '\0'); }
	int get() { return(contents[_charPosition++]); }
	char *fill() { init(); return contents; }
	Buffer() { init(); }
};

class Source : public Buffer {
public:
	enum sourceStatus { OK, CANNOTOPEN, SAWEOF };
private:
	FILE *fd;
	char *_fileName;
	int _currentLine;
	sourceStatus _status;
public:
	const char* fileName() { return _fileName; }
	int currentLine() { return _currentLine; }
	sourceStatus status() { return _status; }
	char nextChar();
	Source(const char *fn);
	~Source();
};


syntax highlighted by Code2HTML, v. 0.9.1