|
Pol
Revision:cb584c9
|
#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) |
| Parser & | operator= (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 |
| Pol::Bscript::Parser::Parser | ( | ) |
Definition at line 75 of file parser.cpp.
References buffer, ext_err, and Pol::Bscript::init_tables().
|
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!)
| tok | Token&: The token to store the found literal into |
| ctx | CompilerContext&: The context to look into |
| expr | unused |
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 | ||
| ) |
|
pure virtual |
Implemented in Pol::Bscript::SmartParser.
Referenced by Pol::Bscript::SmartParser::IIP().
|
virtual |
Reads next token from given context, but without modifying the context
Definition at line 1562 of file parser.cpp.
References getToken().
Referenced by Pol::Bscript::Compiler::_getStatement(), Pol::Bscript::SmartParser::getArgs(), Pol::Bscript::Compiler::getArrayElements(), Pol::Bscript::Compiler::getDictionaryMembers(), Pol::Bscript::Compiler::getMethodArguments(), Pol::Bscript::Compiler::getNewArrayElements(), Pol::Bscript::Compiler::getSimpleExpr(), Pol::Bscript::Compiler::getStructMembers(), Pol::Bscript::Compiler::getUserArgs(), Pol::Bscript::Compiler::handleBlock(), Pol::Bscript::Compiler::handleBracketedIf(), Pol::Bscript::Compiler::handleDeclare(), Pol::Bscript::Compiler::handleEnumDeclare(), Pol::Bscript::Compiler::handleFor(), Pol::Bscript::Compiler::handleIf(), Pol::Bscript::Compiler::handleProgram2(), Pol::Bscript::Compiler::handleReturn(), Pol::Bscript::Compiler::handleSwitch(), Pol::Bscript::SmartParser::IIP(), Pol::Bscript::Compiler::readblock(), Pol::Bscript::Compiler::readFunctionDeclaration(), and Pol::Bscript::Compiler::useModule().
|
virtual |
Definition at line 1382 of file parser.cpp.
References recognize_binary(), and recognize_unary().
|
virtual |
Definition at line 1323 of file parser.cpp.
References Pol::Bscript::Token::id, Pol::Bscript::Operator::id, Pol::Bscript::Mod_Basic, Pol::Bscript::Token::module, Pol::Bscript::n_operators, Pol::Bscript::Operator::precedence, Pol::Bscript::Token::precedence, Pol::Bscript::Token::setStr(), Pol::Bscript::Token::type, and Pol::Bscript::Operator::type.
Referenced by recognize().
|
virtual |
Definition at line 1390 of file parser.cpp.
References Pol::Bscript::Token::deprecated, Pol::Bscript::ReservedWord::deprecated, Pol::Bscript::Token::id, Pol::Bscript::ReservedWord::id, Pol::Bscript::Mod_Basic, Pol::Bscript::Token::module, Pol::Bscript::Token::precedence, Pol::Bscript::ReservedWord::precedence, Pol::Bscript::Token::setStr(), Pol::Bscript::TOK_IDENT, Pol::Bscript::Token::type, Pol::Bscript::ReservedWord::type, and Pol::Bscript::ReservedWord::word.
Referenced by getToken(), and write_words().
|
virtual |
Definition at line 1363 of file parser.cpp.
References Pol::Bscript::Token::id, Pol::Bscript::Operator::id, Pol::Bscript::Mod_Basic, Pol::Bscript::Token::module, Pol::Bscript::n_unary, Pol::Bscript::Operator::precedence, Pol::Bscript::Token::precedence, Pol::Bscript::Token::setStr(), Pol::Bscript::Token::type, and Pol::Bscript::Operator::type.
Referenced by Pol::Bscript::SmartParser::IIP(), and recognize().
| void Pol::Bscript::Parser::reinit | ( | Expression & | ex | ) |
Definition at line 1432 of file parser.cpp.
References Pol::Bscript::Expression::CA, err, ext_err, Pol::Bscript::PERR_NONE, and Pol::Bscript::Expression::TX.
Referenced by Pol::Bscript::SmartParser::IP(), and Pol::Bscript::Compiler::readexpr().
|
inline |
Definition at line 146 of file parser.h.
Referenced by Pol::ECompile::compile_file(), Pol::ECompile::compile_inc(), and Pol::Bscript::Compiler::Compiler().
|
virtual |
Tries to read a binary operator from context
| tok | Token&: The token to store the found literal into |
| ctx | CompilerContext&: The context to look into |
Definition at line 1123 of file parser.cpp.
References Pol::Bscript::CompilerContext::s, and tryOperator().
Referenced by getToken().
|
virtual |
Tries to read a literal (string/variable name) from context
| tok | Token&: The token to store the found literal into |
| ctx | CompilerContext&: The context to look into |
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().
|
virtual |
Tries to read a numeric value from context
| tok | Token&: The token to store the found literal into |
| ctx | CompilerContext&: The context to look into |
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().
|
virtual |
Tries to read a an operator from context
| tok | Token&: The token to store the found literal into |
| opList | The list of possible operators to look for, as Operator[] |
| n_ops | Number of operators in the list |
| t | todo |
| s | todo |
| opbuf | todo |
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().
|
virtual |
Tries to read an unary operator from context
| tok | Token&: The token to store the found literal into |
| ctx | CompilerContext&: The context to look into |
Definition at line 1140 of file parser.cpp.
References Pol::Bscript::CompilerContext::s, and tryOperator().
Referenced by getToken().
|
static |
Definition at line 926 of file parser.cpp.
References Pol::Bscript::Operator::code, Pol::Bscript::ObjMethod::code, Pol::Bscript::ObjMember::code, Pol::Bscript::Operator::deprecated, Pol::Bscript::ReservedWord::deprecated, err, Pol::Bscript::ObjMethod::id, Pol::Bscript::ObjMember::id, Pol::Bscript::n_objmembers, Pol::Bscript::n_objmethods, Pol::Bscript::n_operators, Pol::Bscript::n_reserved, Pol::Bscript::n_unary, Pol::Bscript::Token::nulStr(), Pol::Bscript::PERR_BADOPER, Pol::Bscript::PERR_BADTOKEN, recognize_reserved_word(), and Pol::Bscript::ReservedWord::word.
Referenced by Pol::ECompile::generate_wordlist().
| char Pol::Bscript::Parser::buffer[51] |
| ParseError Pol::Bscript::Parser::err |
Definition at line 114 of file parser.h.
Referenced by Pol::Bscript::Compiler::compileContext(), Pol::Bscript::Compiler::Compiler(), Pol::Bscript::SmartParser::getArgs(), Pol::Bscript::Compiler::getExprInParens(), getToken(), Pol::Bscript::Compiler::getUserArgs(), Pol::Bscript::Compiler::handleDeclare(), Pol::Bscript::Compiler::handleExit(), Pol::Bscript::SmartParser::IIP(), Pol::Bscript::SmartParser::parseToken(), reinit(), tryLiteral(), tryOperator(), and write_words().
| char Pol::Bscript::Parser::ext_err[50] |
Definition at line 116 of file parser.h.
Referenced by Pol::Bscript::Compiler::compileContext(), Parser(), and reinit().
| int Pol::Bscript::Parser::quiet |
Definition at line 113 of file parser.h.
Referenced by Pol::Bscript::Compiler::_getStatement(), Pol::Bscript::Compiler::handleBlock(), Pol::Bscript::Compiler::handleBracketedIf(), Pol::Bscript::Compiler::handleBracketedWhile(), Pol::Bscript::Compiler::handleDoClause(), Pol::Bscript::Compiler::handleIf(), Pol::Bscript::Compiler::handleRepeatUntil(), Pol::Bscript::SmartParser::IIP(), Pol::Bscript::SmartParser::isOkay(), and Pol::Bscript::SmartParser::parseToken().