AndroMeta  2.0.0
Public Member Functions
Meta::MParser Class Reference

Parser base class. Provides methods that are useful to parser subclasses irrespective of how they implemented. More...

#include <MParser.h>

Inheritance diagram for Meta::MParser:
Meta::MEmitter Meta::MMLParser Meta::MPLParser

List of all members.

Public Member Functions

 MParser (size_t historySize=50)
virtual ~MParser ()
bool readLine (const mstr &prompt, mstr &line)
mnode error (mnode n, const mstr &msg, bool warn=false, const mstr &type="")
mnode func (const mstr &name) const
mnode sym (const mstr &name) const
mnode node (const mvar &v) const
int & status ()
const mstrfileName () const
void setFileName (const mstr &fileName)
size_t & lineNumber ()
size_t & character ()
int & tokenId ()
bool reportErrors () const
void setReportErrors (bool flag)
void submitError (const mvar &error)
const mvecerrors () const
void clearErrors ()
void setErrorStream (std::ostream &estr)

Detailed Description

Parser base class. Provides methods that are useful to parser subclasses irrespective of how they implemented.

Parser implementations are specific to each language, however this class defines a general interface that parser subclasses may find useful and should utilize when possible. Many of the parsing details are left to the implementation, however the general design flow is that an MParser instance parses code from a target language and constructs and emits M code in the form of MNode's.


Constructor & Destructor Documentation

Meta::MParser::MParser ( size_t  historySize = 50)

Constructor.

Parameters:
historySizeFor interactive mode, the number of lines of history to maintain.
virtual Meta::MParser::~MParser ( ) [virtual]

Destructor.


Member Function Documentation

Get/modify the current character index of the parser.

Clear errors.

mnode Meta::MParser::error ( mnode  n,
const mstr msg,
bool  warn = false,
const mstr type = "" 
)

Display an error or warning with filename and line number.

Parameters:
nThe node from which to extract filename and line number.
msgError/warning message.
warntrue if this is a warning message and not an error. An error sets status to non-zero while a warning does not.

type A type string, e.g: "parse", "semantic", can be anything, and if non-empty an error message is inserted into the errors vec.

Returns:
The mnode that to be emitted at the error location.
const mvec& Meta::MParser::errors ( ) const

Return errors.

const mstr& Meta::MParser::fileName ( ) const

Get the current filename of the parser.

mnode Meta::MParser::func ( const mstr name) const

Construct a function, setting the parse info to contain the current filename and line number.

Get/modify the current line number of the parser.

mnode Meta::MParser::node ( const mvar v) const

Construct a non-symbolic node, setting the parse info to contain the current filename and line number.

bool Meta::MParser::readLine ( const mstr prompt,
mstr line 
)

For interactive parsing, this method reads a line from stdin.

Parameters:
promptThe line prompt, e.g: ">>>"
lineOn output, the line as read.
Returns:
true on success, false on EOF.
Returns:
true if error reporting is enabled.
void Meta::MParser::setErrorStream ( std::ostream &  estr)

Set the output stream to be used when reporting errors. Default is std::cerr.

void Meta::MParser::setFileName ( const mstr fileName)

Set the current filename of the parser.

void Meta::MParser::setReportErrors ( bool  flag)

Set whether to report errors. The default is true.

Get/modify the current status of the parser.

void Meta::MParser::submitError ( const mvar error)

Submit an error.

mnode Meta::MParser::sym ( const mstr name) const

Construct a symbol, setting the parse info to contain the current filename and line number.

Get/modify the current token id of the parser.


The documentation for this class was generated from the following file: