Pol  Revision:3cfda13
Pol::Bscript::SmartParser Class Referenceabstract

#include <parser.h>

+ Inheritance diagram for Pol::Bscript::SmartParser:

Public Member Functions

 SmartParser ()
 
virtual ~SmartParser ()
 
bool callingMethod (CompilerContext &ctx)
 
int getArgs (Expression &expr, CompilerContext &ctx)
 
virtual int getArrayElements (Expression &expr, CompilerContext &ctx)=0
 
virtual int getDictionaryMembers (Expression &expr, CompilerContext &ctx)=0
 
virtual int getFunctionPArgument (Expression &expr, CompilerContext &ctx, Token *tok)=0
 
virtual int getMethodArguments (Expression &expr, CompilerContext &ctx, int &nargs)=0
 
virtual int getNewArrayElements (Expression &expr, CompilerContext &ctx)=0
 
virtual int getStructMembers (Expression &expr, CompilerContext &ctx)=0
 
virtual int getToken (CompilerContext &ctx, Token &token, Expression *expr=NULL) POL_OVERRIDE
 
virtual int getUserArgs (Expression &expr, CompilerContext &ctx, bool inject_jsr=true)=0
 
int IIP (Expression &expr, CompilerContext &ctx, unsigned expr_flags)
 
int IP (Expression &expr, char *s)
 
int IP (Expression &expr, CompilerContext &ctx)
 
virtual int isFunc (Token &tok, ModuleFunction **v)=0
 
virtual int isLegal (Token &tok)
 
virtual int isOkay (const Token &token, BTokenType last_type)
 
virtual int isUserFunc (Token &tok, UserFunction **userfunc)
 
SmartParseroperator= (const SmartParser &)
 
virtual int parseToken (CompilerContext &ctx, Expression &expr, Token *) POL_OVERRIDE
 
- Public Member Functions inherited from Pol::Bscript::Parser
 Parser ()
 
virtual ~Parser ()
 
int IP (Expression &expr, char *s)
 
Parseroperator= (const Parser &)
 
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 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)
 

Protected Member Functions

virtual int tryLiteral (Token &tok, CompilerContext &ctx) POL_OVERRIDE
 

Protected Attributes

class ModuleFunctionmodfunc_
 
UserFunctionuserfunc_
 

Additional Inherited Members

- Static Public Member Functions inherited from Pol::Bscript::Parser
static void write_words (std::ostream &os)
 
- Public Attributes inherited from Pol::Bscript::Parser
char buffer [51]
 
bool contains_tabs
 
ParseError err
 
char ext_err [50]
 
int quiet
 

Detailed Description

Definition at line 150 of file parser.h.

Constructor & Destructor Documentation

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

Definition at line 153 of file parser.h.

References POL_OVERRIDE.

Pol::Bscript::SmartParser::SmartParser ( )
inline

Definition at line 162 of file parser.h.

Member Function Documentation

virtual int Pol::Bscript::SmartParser::getArrayElements ( Expression expr,
CompilerContext ctx 
)
pure virtual

Implemented in Pol::Bscript::Compiler.

virtual int Pol::Bscript::SmartParser::getDictionaryMembers ( Expression expr,
CompilerContext ctx 
)
pure virtual

Implemented in Pol::Bscript::Compiler.

virtual int Pol::Bscript::SmartParser::getFunctionPArgument ( Expression expr,
CompilerContext ctx,
Token tok 
)
pure virtual

Implemented in Pol::Bscript::Compiler.

virtual int Pol::Bscript::SmartParser::getMethodArguments ( Expression expr,
CompilerContext ctx,
int &  nargs 
)
pure virtual

Implemented in Pol::Bscript::Compiler.

virtual int Pol::Bscript::SmartParser::getNewArrayElements ( Expression expr,
CompilerContext ctx 
)
pure virtual

Implemented in Pol::Bscript::Compiler.

virtual int Pol::Bscript::SmartParser::getStructMembers ( Expression expr,
CompilerContext ctx 
)
pure virtual

Implemented in Pol::Bscript::Compiler.

int Pol::Bscript::SmartParser::getToken ( CompilerContext ctx,
Token token,
Expression pexpr = NULL 
)
virtual

Some identifiers are functions (user-defined or module-defined) these are recognized here. HOWEVER, in some cases these should be ignored - particularly, after the "." operator and its ilk. For example, if the LEN function is defined, "print a.len;" should still be valid (assuming A is a variable with a 'len' member). In these cases, the operator in question will be at the top of the TX stack. So, if we find this operator there, we won't check for functions. This is also the perfect opportunity to morph would-be identifiers into strings, or "member names" if that turns out the way to go. (Normally, we would emit TOK_IDENT(left) TOK_IDENT(right) TOK_MEMBER. The problem here is that TOK_IDENT(left) is seen as a variable (quite rightly), but so is TOK_IDENT(right), which is wrong. We used to transform this in addToken, but this is better I think.)

Note
let's suppose.. an overridden getToken is really smart, and figures out if IDENTS are variable names, verbs, functions, or labels. To this end it pulls out the ':' if necessary. TYP_OPERAND, TOK_VARNAME TYP_FUNC, TOK_MID, <– TYP_OPERAND for purposes of legality TYP_PROC, TOK_PRINT, TYP_LABEL, (don't care)

IP still does the same thing only it no longer looks for isVerb. have the new getToken put, say, the verb number in lval, so we now have an array element number.

See also
Parser::getToken( CompilerContext& ctx, Token& token )

Reimplemented from Pol::Bscript::Parser.

Definition at line 1922 of file parser.cpp.

References Pol::Bscript::Parser::getToken(), Pol::Bscript::Token::id, Pol::Bscript::TOK_ADDMEMBER, Pol::Bscript::TOK_CHKMEMBER, Pol::Bscript::TOK_DELMEMBER, Pol::Bscript::TOK_IDENT, Pol::Bscript::TOK_MEMBER, Pol::Bscript::TOK_STRING, and Pol::Bscript::Expression::TX.

Referenced by Pol::Bscript::Compiler::_getStatement(), Pol::Bscript::Compiler::eatToken(), Pol::Bscript::Compiler::forward_read_function(), Pol::Bscript::Compiler::getArrayElements(), Pol::Bscript::Compiler::getDictionaryMembers(), Pol::Bscript::Compiler::getExprInParens(), Pol::Bscript::Compiler::getFunctionPArgument(), Pol::Bscript::Compiler::getMethodArguments(), Pol::Bscript::Compiler::getNewArrayElements(), Pol::Bscript::Compiler::getStructMembers(), Pol::Bscript::Compiler::getUserArgs(), Pol::Bscript::Compiler::handleBlock(), Pol::Bscript::Compiler::handleBracketedFor_basic(), Pol::Bscript::Compiler::handleBracketedFor_c(), Pol::Bscript::Compiler::handleBracketedFunction2(), Pol::Bscript::Compiler::handleBracketedIf(), Pol::Bscript::Compiler::handleBreak(), Pol::Bscript::Compiler::handleConstDeclare(), Pol::Bscript::Compiler::handleContinue(), Pol::Bscript::Compiler::handleDeclare(), Pol::Bscript::Compiler::handleEnumDeclare(), Pol::Bscript::Compiler::handleExit(), Pol::Bscript::Compiler::handleFor_c(), Pol::Bscript::Compiler::handleForEach(), Pol::Bscript::Compiler::handleFunction(), Pol::Bscript::Compiler::handleIf(), Pol::Bscript::Compiler::handleInclude(), Pol::Bscript::Compiler::handleProgram(), Pol::Bscript::Compiler::handleProgram2(), Pol::Bscript::Compiler::handleReturn(), Pol::Bscript::Compiler::handleSwitch(), Pol::Bscript::Compiler::handleUse(), Pol::Bscript::Compiler::handleVarDeclare(), Pol::Bscript::Compiler::inner_read_function_declarations(), Pol::Bscript::Compiler::readblock(), Pol::Bscript::Compiler::readFunctionDeclaration(), and Pol::Bscript::Compiler::useModule().

virtual int Pol::Bscript::SmartParser::getUserArgs ( Expression expr,
CompilerContext ctx,
bool  inject_jsr = true 
)
pure virtual

Implemented in Pol::Bscript::Compiler.

int Pol::Bscript::SmartParser::IIP ( Expression expr,
CompilerContext ctx,
unsigned  flags 
)

if comma terminator is allowed, (reading args, or declaring variables) leaves the terminator/comma. if comma term not allowed, eats the semicolon. if right paren allowed, leaves the right paren.

Note
(obviously, this function's behavior needs some work!)

Definition at line 2076 of file parser.cpp.

References Pol::Bscript::Expression::CA, Pol::Bscript::compilercfg, Pol::Bscript::Token::copyStr(), Pol::Bscript::Token::dbg_filenum, Pol::Bscript::Token::dbg_linenum, Pol::Bscript::CompilerConfig::DisplayWarnings, Pol::Bscript::Token::dval, Pol::Bscript::Parser::err, Pol::Bscript::CompilerConfig::ErrorOnWarning, Pol::Bscript::EXPR_FLAG_AUTO_TERM_ALLOWED, Pol::Bscript::EXPR_FLAG_COMMA_TERM_ALLOWED, Pol::Bscript::EXPR_FLAG_DICTKEY_TERM_ALLOWED, Pol::Bscript::EXPR_FLAG_ENDENUM_TERM_ALLOWED, Pol::Bscript::EXPR_FLAG_RIGHTBRACE_TERM_ALLOWED, Pol::Bscript::EXPR_FLAG_RIGHTPAREN_TERM_ALLOWED, Pol::Bscript::EXPR_FLAG_SEMICOLON_TERM_ALLOWED, Pol::Bscript::EXPR_FLAG_SINGLE_ELEMENT, Pol::Bscript::EXPR_FLAG_TO_TERM_ALLOWED, Pol::Bscript::getKnownObjMethod(), Pol::Bscript::Parser::getToken(), Pol::Bscript::Token::id, Pol::Bscript::ObjMethod::id, INFO_PRINT, Pol::Bscript::INS_CALL_METHOD, Pol::Bscript::INS_CALL_METHOD_ID, Pol::Bscript::Token::lval, Pol::Clib::mklower(), Pol::Bscript::CompilerConfig::OptimizeObjectMembers, Pol::Bscript::CompilerConfig::ParanoiaWarnings, Pol::Bscript::Parser::parseToken(), Pol::Bscript::Parser::peekToken(), Pol::Bscript::PERR_ILLEGALCONS, Pol::Bscript::PERR_NONE, Pol::Bscript::PERR_NOTLEGALHERE, Pol::Bscript::PERR_UNEXRPAREN, Pol::Bscript::Parser::quiet, Pol::Bscript::Parser::recognize_unary(), Pol::Bscript::RSV_ENDENUM, Pol::Bscript::RSV_TO, Pol::Bscript::CompilerContext::s, Pol::Clib::stracpy(), Pol::Bscript::TOK_ARRAY, Pol::Bscript::TOK_COMMA, Pol::Bscript::TOK_DICTIONARY, Pol::Bscript::TOK_DICTKEY, Pol::Bscript::TOK_ERROR, Pol::Bscript::TOK_FUNCREF, Pol::Bscript::TOK_LBRACE, Pol::Bscript::TOK_LBRACKET, Pol::Bscript::TOK_LPAREN, Pol::Bscript::TOK_MEMBER, Pol::Bscript::TOK_RBRACE, Pol::Bscript::TOK_RBRACKET, Pol::Bscript::TOK_SEMICOLON, Pol::Bscript::TOK_STRUCT, Pol::Bscript::Token::tokval(), Pol::Bscript::Expression::TX, Pol::Bscript::TYP_FUNC, Pol::Bscript::TYP_LEFTBRACE, Pol::Bscript::TYP_LEFTBRACKET, Pol::Bscript::TYP_LEFTPAREN, Pol::Bscript::TYP_METHOD, Pol::Bscript::TYP_OPERAND, Pol::Bscript::TYP_OPERATOR, Pol::Bscript::TYP_RIGHTBRACKET, Pol::Bscript::TYP_RIGHTPAREN, Pol::Bscript::TYP_SEPARATOR, Pol::Bscript::TYP_TERMINATOR, Pol::Bscript::TYP_UNARY_OPERATOR, Pol::Bscript::TYP_USERFUNC, and Pol::Bscript::Token::type.

Referenced by Pol::Bscript::Compiler::getUserArgs(), and Pol::Bscript::Compiler::readexpr().

int Pol::Bscript::SmartParser::IP ( Expression expr,
char *  s 
)
int Pol::Bscript::SmartParser::IP ( Expression expr,
CompilerContext ctx 
)
virtual int Pol::Bscript::SmartParser::isFunc ( Token tok,
ModuleFunction **  v 
)
pure virtual

Implemented in Pol::Bscript::Compiler.

int Pol::Bscript::SmartParser::isLegal ( Token tok)
inlinevirtual

Reimplemented in Pol::Bscript::Compiler.

Definition at line 190 of file parser.h.

int Pol::Bscript::SmartParser::isUserFunc ( Token tok,
UserFunction **  userfunc 
)
inlinevirtual

Reimplemented in Pol::Bscript::Compiler.

Definition at line 194 of file parser.h.

SmartParser& Pol::Bscript::SmartParser::operator= ( const SmartParser )
inline

Definition at line 163 of file parser.h.

References POL_OVERRIDE.

int Pol::Bscript::SmartParser::tryLiteral ( Token tok,
CompilerContext ctx 
)
protectedvirtual

Like Parser::tryLiteral, with extra elements supported

Labels. A label is an ident operand, followed by a colon, followed by either whitespace or end-of-file. Note, this definition just happens to exclude ':=' and '::', which is important.

See also
Parser::tryLiteral( Token& tok, CompilerContext& ctx )

Reimplemented from Pol::Bscript::Parser.

Definition at line 1641 of file parser.cpp.

References Pol::Bscript::CTRL_LABEL, Pol::Bscript::Token::id, Pol::Bscript::CompilerContext::s, Pol::Bscript::TOK_IDENT, Pol::Bscript::Parser::tryLiteral(), Pol::Bscript::TYP_LABEL, and Pol::Bscript::Token::type.

Member Data Documentation

class ModuleFunction* Pol::Bscript::SmartParser::modfunc_
protected

Definition at line 158 of file parser.h.

UserFunction* Pol::Bscript::SmartParser::userfunc_
protected

Definition at line 159 of file parser.h.

Referenced by Pol::Bscript::Compiler::getUserArgs().


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