Pol  Revision:cb584c9
Pol::Bscript::Parser Class Referenceabstract

#include <parser.h>

+ Inheritance diagram for Pol::Bscript::Parser:

Public Member Functions

 Parser ()
 
virtual ~Parser ()
 
virtual int getToken (CompilerContext &ctx, Token &token, Expression *expr=NULL)
 
int IP (Expression &expr, char *s)
 
Parseroperator= (const Parser &)
 
virtual int parseToken (CompilerContext &ctx, Expression &expr, Token *token)=0
 
virtual int peekToken (const CompilerContext &ctx, Token &token, Expression *expr=NULL)
 
virtual int recognize (Token &tok, const char *buf, const char **s)
 
virtual int recognize_binary (Token &tok, const char *buf, const char **s)
 
virtual bool recognize_reserved_word (Token &tok, const char *buf)
 
virtual int recognize_unary (Token &tok, const char *buf)
 
void reinit (Expression &ex)
 
void setQuiet (int x)
 
virtual int tryBinaryOperator (Token &tok, CompilerContext &ctx)
 
virtual int tryLiteral (Token &tok, CompilerContext &ctx)
 
virtual int tryNumeric (Token &tok, CompilerContext &ctx)
 
virtual int tryOperator (Token &tok, const char *buf, const char **s, Operator *opList, int n_ops, char *opbuf)
 
virtual int tryUnaryOperator (Token &tok, CompilerContext &ctx)
 

Static Public Member Functions

static void write_words (std::ostream &os)
 

Public Attributes

char buffer [51]
 
bool contains_tabs
 
ParseError err
 
char ext_err [50]
 
int quiet
 

Detailed Description

Definition at line 107 of file parser.h.

Constructor & Destructor Documentation

Pol::Bscript::Parser::Parser ( )

Definition at line 75 of file parser.cpp.

References buffer, ext_err, and Pol::Bscript::init_tables().

virtual Pol::Bscript::Parser::~Parser ( )
inlinevirtual

Definition at line 111 of file parser.h.

Member Function Documentation

int Pol::Bscript::Parser::getToken ( CompilerContext ctx,
Token tok,
Expression expr = NULL 
)
virtual

Reads next token from given context

what is a token? a set of homogeneous characters a Label: begins with [A-Za-z_], followed by [A-Za-z0-9]

A character literal: begins with '"', ends with '"'. anything goes in between.

a Number: begins with [0-9] (note: not plus or minus, these get eaten as unary ops) can be either a float (stored as double), or a long. 0xABC is hex, which is read okay. So is 0.5e+17. I let strtod do most of the work. basically whichever of strtod or strtol can do more with it (endptr arg is greater on exit), that's what i decide that it is.

an operator: any collection of the operator characters [ ( ) * / + - < = > ,] not separated by whitespace, digits, or alphas note a collection of more than one is considered a SINGLE operator. So if you put 6*-7, *- is the operator. nasty I know, but what am I supposed to do? (Maximal munch, is what is actually done!)

Parameters
tokToken&: The token to store the found literal into
ctxCompilerContext&: The context to look into
exprunused
Returns
0 when no matching text is found, 1 on success, -1 on error (also sets err)

Reimplemented in Pol::Bscript::SmartParser.

Definition at line 1483 of file parser.cpp.

References Pol::Bscript::Token::dbg_filenum, Pol::Bscript::CompilerContext::dbg_filenum, Pol::Bscript::Token::dbg_linenum, err, Pol::Bscript::Token::id, INFO_PRINT, Pol::Bscript::CompilerContext::line, Pol::Bscript::Mod_Basic, Pol::Bscript::Token::module, Pol::Bscript::PERR_WAAH, recognize_reserved_word(), Pol::Bscript::RSV_COLON, Pol::Bscript::CompilerContext::s, Pol::Bscript::Token::setStr(), Pol::Bscript::CompilerContext::skipcomments(), Pol::Bscript::TOK_SEMICOLON, Pol::Bscript::Token::tokval(), tryBinaryOperator(), tryLiteral(), tryNumeric(), tryUnaryOperator(), Pol::Bscript::TYP_DELIMITER, Pol::Bscript::TYP_RESERVED, and Pol::Bscript::Token::type.

Referenced by Pol::Bscript::SmartParser::callingMethod(), Pol::Bscript::SmartParser::getArgs(), Pol::Bscript::Compiler::getStructMembers(), Pol::Bscript::SmartParser::getToken(), Pol::Bscript::SmartParser::IIP(), and peekToken().

int Pol::Bscript::Parser::IP ( Expression expr,
char *  s 
)
Parser& Pol::Bscript::Parser::operator= ( const Parser )
inline

Definition at line 112 of file parser.h.

virtual int Pol::Bscript::Parser::parseToken ( CompilerContext ctx,
Expression expr,
Token token 
)
pure virtual
int Pol::Bscript::Parser::recognize ( Token tok,
const char *  buf,
const char **  s 
)
virtual

Definition at line 1382 of file parser.cpp.

References recognize_binary(), and recognize_unary().

void Pol::Bscript::Parser::reinit ( Expression ex)
void Pol::Bscript::Parser::setQuiet ( int  x)
inline
int Pol::Bscript::Parser::tryBinaryOperator ( Token tok,
CompilerContext ctx 
)
virtual

Tries to read a binary operator from context

Parameters
tokToken&: The token to store the found literal into
ctxCompilerContext&: The context to look into
Returns
0 when no matching text is found, 1 on success, -1 on error (also sets err)

Definition at line 1123 of file parser.cpp.

References Pol::Bscript::CompilerContext::s, and tryOperator().

Referenced by getToken().

int Pol::Bscript::Parser::tryLiteral ( Token tok,
CompilerContext ctx 
)
virtual

Tries to read a literal (string/variable name) from context

Parameters
tokToken&: The token to store the found literal into
ctxCompilerContext&: The context to look into
Returns
0 when no matching text is found, 1 on success, -1 on error (also sets err)

Reimplemented in Pol::Bscript::SmartParser.

Definition at line 1215 of file parser.cpp.

References Pol::Bscript::Token::copyStr(), err, Pol::Bscript::Token::id, passert_always_r, Pol::Bscript::PERR_INVESCAPE, Pol::Bscript::PERR_UNTERMSTRING, Pol::Bscript::CompilerContext::s, Pol::Bscript::TOK_IDENT, Pol::Bscript::TOK_STRING, Pol::Bscript::TYP_OPERAND, and Pol::Bscript::Token::type.

Referenced by getToken(), and Pol::Bscript::SmartParser::tryLiteral().

int Pol::Bscript::Parser::tryNumeric ( Token tok,
CompilerContext ctx 
)
virtual

Tries to read a numeric value from context

Parameters
tokToken&: The token to store the found literal into
ctxCompilerContext&: The context to look into
Returns
0 when no matching text is found, 1 on success, -1 on error (also sets err)

Definition at line 1157 of file parser.cpp.

References Pol::Bscript::Token::dval, Pol::Bscript::Token::id, Pol::Bscript::Token::lval, Pol::Bscript::CompilerContext::s, Pol::Bscript::TOK_DOUBLE, Pol::Bscript::TOK_LONG, Pol::Bscript::TYP_OPERAND, and Pol::Bscript::Token::type.

Referenced by getToken().

int Pol::Bscript::Parser::tryOperator ( Token tok,
const char *  t,
const char **  s,
Operator opList,
int  n_ops,
char *  opbuf 
)
virtual

Tries to read a an operator from context

Parameters
tokToken&: The token to store the found literal into
opListThe list of possible operators to look for, as Operator[]
n_opsNumber of operators in the list
ttodo
stodo
opbuftodo
Returns
0 when no matching text is found, 1 on success, -1 on error (also sets err)

Definition at line 1048 of file parser.cpp.

References Pol::Bscript::Operator::code, Pol::Bscript::Operator::deprecated, Pol::Bscript::Token::deprecated, err, Pol::Bscript::Token::id, Pol::Bscript::Operator::id, Pol::Bscript::matchOperators(), Pol::Bscript::Mod_Basic, Pol::Bscript::Token::module, Pol::Bscript::PERR_BADTOKEN, Pol::Bscript::Operator::precedence, Pol::Bscript::Token::precedence, Pol::Bscript::Token::setStr(), Pol::Bscript::Token::type, and Pol::Bscript::Operator::type.

Referenced by tryBinaryOperator(), and tryUnaryOperator().

int Pol::Bscript::Parser::tryUnaryOperator ( Token tok,
CompilerContext ctx 
)
virtual

Tries to read an unary operator from context

Parameters
tokToken&: The token to store the found literal into
ctxCompilerContext&: The context to look into
Returns
0 when no matching text is found, 1 on success, -1 on error (also sets err)

Definition at line 1140 of file parser.cpp.

References Pol::Bscript::CompilerContext::s, and tryOperator().

Referenced by getToken().

Member Data Documentation

char Pol::Bscript::Parser::buffer[51]

Definition at line 117 of file parser.h.

Referenced by Parser().

bool Pol::Bscript::Parser::contains_tabs

Definition at line 119 of file parser.h.

char Pol::Bscript::Parser::ext_err[50]

Definition at line 116 of file parser.h.

Referenced by Pol::Bscript::Compiler::compileContext(), Parser(), and reinit().


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