The LAP library: ParserBin

Derived from: Parser

Declared in: ParserBin.h


Overview

The ParserBin object is meant to parse... binary files. This object really doesn't do much. It mainly consists in a public interface to a LexerBin object. Still, it is pretty handy.

Note that, as part of the implementation of a binary parser, the class ParserBin has nothing to do with lexemes and "lookahead symbols".


Constructor and D estructor


ParserBin()

 
      ParserBin(bool Verbose) 

Creates a ParserBin object with the verbose mode set to Verbose Note that the lexer object is not allocated. Indeed, ParserBin is an abstract class, because its ParserBin::Parse() method is declared as pure virtual. Hence, you have to derive a MyParserBin class and declare and define a MyParserBin::Parse() method to have a usable binary parser.


~ParserBin()

 
      ~ParserBin(void) 

Nothing much happens in here.


Member Functions


SearchSymbol()

 
      Symbol* SearchSymbol(char* Name)

Calls and returns the result of Lexer::SearchSymbol()

This method is not declared in the Parser class, because no Lexer object is defined.


PrintSymbol()

 
      void PrintSymbol(Symbol* S)

Calls Lexer::PrintSymbol()

This method is not declared in the Parser class, because no Lexer object is defined.


SetInput()

 
      bool SetInput(entry_ref&  Ref, tEndian FileEndianness)

This method sets the input of the lexer. It defines both the file and the endianness of the file, so that the lexer can determine whether bytes are to be reversed or not.

Then, the Parser::CheckType() is called to check that the type of the file is the one the lexer can handle. The verbose mode of the parser is ignored, every message output with the _PRINT or PRINT functions won't be displayed.

The verbose mode is then set back to its original settings, and the lexer reset to point back to the beginning of the file. Then the indentation stuff is initialized so that a simple call to Parse() is needed.


Terminate()

 
      virtual void Terminate()

Calls Lexer::Terminate()


DetachLexeme()

 
      char* DetachLexeme(char* Lexeme)

Calls and returns the output of Lexer::DetachLexeme()

This method is not declared in the Parser class, because no Lexer object is defined.


DeleteLexeme()

 
      void DeleteLexeme(char* Lexeme)

Calls Lexer::DeleteLexeme()

This method is not declared in the Parser class, because no Lexer object is defined.


EndOfFile()

 
      bool EndOfFile()

Calls and returns the output of Lexer::Eof()

This method is not declared in the Parser class, because no Lexer object is defined.


SearchSymbol()

 
      Symbol* SearchSymbol(char* Name)

Calls and returns the output of Lexer::SearchSymbol()

This method is not declared in the Parser class, because no Lexer object is defined.


PrintSymbol()

 
      void PrintSymbol(Symbol* Symbl)

Calls Lexer::PrintSymbol()


ReadData()

 
      bool ReadInt8(uint8& Value)
      bool ReadInt16(uint16& Value)
      bool ReadInt32(uint32& Value)
      bool ReadFloat(float& Value)
      bool ReadDouble(double& Value)
      bool ReadBytes(uint32 NbBytes, char* Out)
      bool ReadString(uint32 MaxLen, char* Out)
      bool SkipBytes(uint32 NbBytes)
      bool LexString(uint32 NbBytes, char*& Out)
Calls the corresponding method in the LexerBin class:

    LexerBin::ReadInt8()
LexerBin::ReadInt16()
LexerBin::ReadInt32()
LexerBin::ReadFloat()
LexerBin::ReadDouble()
LexerBin::ReadBytes()
LexerBin::ReadString()
LexerBin::SkipBytes()
LexerBin::LexString()


Macro Definitions


PRINT(...)

 
      PRINT0(s)
      PRINT1(s, a)
      PRINT2(s, a, b)
      PRINT3(s, a, b, c)
      PRINT4(s, a, b, c, d)
      PRINT5(s, a, b, c, d, e)
      PRINT6(s, a, b, c, d, e, f)
      PRINT7(s, a, b, c, d, e, f, g)

These are macros to output information on screen using the underlying printf function. The PRINTi macro prints out i arguments, only if the ParserBin was constructed in a verbose mode. These messages ARE indented, contrary to the macros Parser::_PRINT.


The LAP library, V0.7, November 3rd 1997, First public release