NewLang Project
Yet another programm language
|
#include <parser.h>
Classes | |
struct | ParserLocation |
Public Member Functions | |
Parser (MacroPtr macro=nullptr, PostLexerType *postlex=nullptr, DiagPtr diag=nullptr, bool pragma_enable=true, RunTime *rt=nullptr) | |
virtual | ~Parser () |
parser::token_type | ExpandPredefMacro (TermPtr &term) |
bool | RegisterPredefMacro (const char *name, const char *desc) |
void | InitPredefMacro () |
bool | CheckPredefMacro (const TermPtr &term) |
void | error (const class location &l, const std::string &m) |
void | error (const std::string &m) |
void | AstAddTerm (TermPtr &term) |
TermPtr | GetAst () |
parser::token_type | GetNextToken (TermPtr *yylval, parser::location_type *yylloc) |
bool | PragmaCheck (const TermPtr &term) |
bool | PragmaEval (const TermPtr &term, BlockType &buffer, BlockType &seq) |
bool | PragmaStaticAssert (const TermPtr &term) |
TermPtr | Parse (const std::string str, bool expand_module=false) |
TermPtr | ParseFile (const std::string_view filename) |
TermPtr | CheckModuleTerm (const TermPtr &term) |
Static Public Member Functions | |
static ObjPtr | StaticEval (const TermPtr &term) |
static size_t | ParseTerm (TermPtr &term, const BlockType &buffer, const size_t skip=0, bool pragma_enable=true) |
static TermPtr | ParseTerm (const char *proto, MacroPtr macro=nullptr, bool pragma_enable=true) |
static bool | IsBracket (const std::string_view str) |
static std::string | GetCurrentDate (time_t ts=std::time(NULL)) |
static std::string | GetCurrentTime (time_t ts=std::time(NULL)) |
static std::string | GetCurrentTimeStamp (time_t ts=std::time(NULL)) |
static std::string | GetCurrentTimeStampISO (time_t ts=std::time(NULL)) |
static size_t | SkipBrackets (const BlockType &buffer, size_t offset) |
Public Attributes | |
bool | trace_scanning |
enable debug output in the flex scanner | |
bool | trace_parsing |
enable debug output in the bison parser | |
std::string | m_filename |
stream name (file or input stream) used for error messages. | |
std::string | m_name_module |
parser::location_type | m_location |
std::vector< ParserLocation > | m_loc_stack |
std::istringstream | m_stream |
std::map< std::string, std::string > | m_predef_macro |
class Scanner * | lexer |
BlockType | m_macro_analisys_buff |
Последовательность лексем для анализа на наличие макросов | |
TermPtr | m_expected |
TermPtr | m_unexpected |
TermPtr | m_finalize |
int | m_finalize_counter |
TermPtr | m_annotation |
bool | m_no_macro |
bool | m_enable_pragma |
time_t | m_timestamp |
std::string | m_file_time |
std::string | m_file_md5 |
DiagPtr | m_diag |
MacroPtr | m_macro |
bool | m_is_lexer_complete |
Static Public Attributes | |
static int | m_counter = 0 |
Private Attributes | |
TermPtr | m_ast |
bool | m_is_runing |
PostLexerType * | m_postlex |
RunTime * | m_rt |
The Driver class brings together all components. It creates an instance of the Parser and Scanner classes and connects them. Then the input stream is fed into the scanner object and the parser gets it's token sequence. Furthermore the driver object is available in the grammar rules as a parameter. Therefore the driver class contains a reference to the structure into which the parsed data is saved.
Parser::Parser | ( | MacroPtr | macro = nullptr, |
PostLexerType * | postlex = nullptr, | ||
DiagPtr | diag = nullptr, | ||
bool | pragma_enable = true, | ||
RunTime * | rt = nullptr ) |
Definition at line 14 of file parser.cpp.
References newlang::ARGS, newlang::Term::Create(), LOG_RUNTIME, m_annotation, m_ast, m_diag, m_enable_pragma, m_file_md5, m_file_time, m_filename, m_is_lexer_complete, m_is_runing, m_macro, m_no_macro, m_postlex, m_rt, and m_timestamp.
parser::token_type Parser::ExpandPredefMacro | ( | TermPtr & | term | ) |
Definition at line 673 of file parser.cpp.
References ASSERT, DATE_BUILD_STR, GetCurrentDate(), GetCurrentTime(), GetCurrentTimeStamp(), GetCurrentTimeStampISO(), GIT_SOURCE, InitPredefMacro(), newlang::INTEGER, LOG_RUNTIME, m_counter, newlang::RunTime::m_exec_dir, m_file_md5, m_file_time, m_filename, m_location, m_name_module, m_predef_macro, m_rt, m_timestamp, newlang::MACRO, newlang::MODULE, newlang::NAME, newlang::NAMESPACE, NL_PARSER, SOURCE_FULL_ID, newlang::STRWIDE, and VERSION.
Referenced by GetNextToken().
bool Parser::RegisterPredefMacro | ( | const char * | name, |
const char * | desc ) |
Definition at line 583 of file parser.cpp.
References LOG_ERROR, and m_predef_macro.
Referenced by InitPredefMacro().
void Parser::InitPredefMacro | ( | ) |
Definition at line 592 of file parser.cpp.
References m_predef_macro, RegisterPredefMacro(), and VERIFY.
Referenced by ExpandPredefMacro().
bool Parser::CheckPredefMacro | ( | const TermPtr & | term | ) |
Definition at line 636 of file parser.cpp.
References m_predef_macro, and newlang::NAME.
Referenced by PragmaCheck().
void Parser::error | ( | const class location & | l, |
const std::string & | m ) |
Error handling with associated line number. This can be modified to output the error e.g. to a dialog box.
Definition at line 110 of file parser.cpp.
void Parser::error | ( | const std::string & | m | ) |
General error handling. This can be modified to output the error e.g. to a dialog box.
Definition at line 114 of file parser.cpp.
void Parser::AstAddTerm | ( | TermPtr & | term | ) |
Reference to the calculator context filled during parsing of the expressions.
Definition at line 130 of file parser.cpp.
References ASSERT, newlang::Term::Create(), newlang::END, lexer, m_ast, newlang::SEQUENCE, and newlang::Scanner::source_string.
TermPtr Parser::GetAst | ( | ) |
Definition at line 126 of file parser.cpp.
References m_ast.
parser::token_type Parser::GetNextToken | ( | TermPtr * | yylval, |
parser::location_type * | yylloc ) |
Definition at line 1131 of file parser.cpp.
References ASSERT, newlang::Continue, newlang::Term::Create(), newlang::END, newlang::ESCAPE, ExpandPredefMacro(), newlang::ExpandTermMacro(), newlang::Goto, newlang::Scanner::lex(), lexer, m_enable_pragma, m_expected, m_is_lexer_complete, m_is_runing, newlang::Scanner::m_loc, m_location, m_macro_analisys_buff, newlang::Scanner::m_macro_body, newlang::Scanner::m_macro_count, newlang::Scanner::m_macro_del, newlang::Scanner::m_macro_iss, newlang::Scanner::m_macro_loc, m_no_macro, m_postlex, m_unexpected, newlang::MACRO_DEL, newlang::MACRO_SEQ, NL_PARSER, ParseTerm(), PragmaCheck(), PragmaEval(), result, newlang::Scanner::source_base, newlang::Scanner::source_string, and yylval.
bool Parser::PragmaCheck | ( | const TermPtr & | term | ) |
Definition at line 176 of file parser.cpp.
References CheckPredefMacro().
Referenced by GetNextToken().
Definition at line 185 of file parser.cpp.
References ASSERT, newlang::Term::Create(), newlang::Diag::error, newlang::Logger::GetLogLevel(), newlang::Diag::ignored, newlang::Logger::Instance(), newlang::INTEGER, LOG_DEBUG, LOG_INFO, LOG_LEVEL_INFO, LOG_RUNTIME, LOG_WARNING, m_annotation, m_diag, m_expected, m_filename, m_finalize, m_finalize_counter, m_loc_stack, m_location, m_no_macro, m_rt, newlang::RunTime::m_typedef_limit, m_unexpected, NL_PARSER, PragmaStaticAssert(), newlang::Logger::SetLogLevel(), newlang::Diag::toString(), and newlang::Diag::warning.
Referenced by GetNextToken().
bool Parser::PragmaStaticAssert | ( | const TermPtr & | term | ) |
Definition at line 506 of file parser.cpp.
References newlang::Context::EvalTerm(), newlang::Variable::GetValueAsBoolean(), newlang::LatterType::GetVariablePair(), NL_PARSER, and newlang::VariablePair::var.
Referenced by PragmaEval().
TermPtr Parser::Parse | ( | const std::string | str, |
bool | expand_module = false ) |
Definition at line 44 of file parser.cpp.
References newlang::Scanner::ApplyDiags(), newlang::Term::Create(), newlang::END, lexer, m_ast, m_diag, and m_stream.
Referenced by newlang::RunTime::CreateNative(), newlang::RunTime::ParseBuildin(), ParseFile(), and ParseTerm().
TermPtr Parser::ParseFile | ( | const std::string_view | filename | ) |
Definition at line 66 of file parser.cpp.
References LOG_RUNTIME, m_file_md5, m_file_time, m_filename, and Parse().
|
static |
Definition at line 895 of file parser.cpp.
References LOG_RUNTIME, NL_PARSER, ParseTerm(), result, and SkipBrackets().
Referenced by newlang::runtime::Buildin::Buildin(), newlang::JIT::CreateMacro(), newlang::runtime::Buildin::CreateMethod(), newlang::runtime::Buildin::CreateMethodNative(), GetNextToken(), newlang::Macro::MakeMacroId(), and ParseTerm().
|
static |
Definition at line 845 of file parser.cpp.
References LOG_RUNTIME, and Parse().
|
inlinestatic |
|
static |
Definition at line 649 of file parser.cpp.
Referenced by ExpandPredefMacro().
|
static |
Definition at line 655 of file parser.cpp.
Referenced by ExpandPredefMacro().
|
static |
Definition at line 661 of file parser.cpp.
References result.
Referenced by ExpandPredefMacro(), newlang::JIT::MakeCodeModule(), and newlang::JIT::MakeMainEmbed().
|
static |
Definition at line 667 of file parser.cpp.
Referenced by ExpandPredefMacro().
Definition at line 964 of file parser.cpp.
References newlang::CheckCharModuleName(), newlang::isModuleName(), and NL_PARSER.
|
static |
Definition at line 862 of file parser.cpp.
References NL_PARSER.
Referenced by newlang::Macro::IdentityMacro(), ParseTerm(), and newlang::Macro::SymbolSeparateArg_().
bool newlang::Parser::trace_scanning |
bool newlang::Parser::trace_parsing |
std::string newlang::Parser::m_filename |
stream name (file or input stream) used for error messages.
Definition at line 46 of file parser.h.
Referenced by ExpandPredefMacro(), ParseFile(), Parser(), and PragmaEval().
std::string newlang::Parser::m_name_module |
Definition at line 47 of file parser.h.
Referenced by ExpandPredefMacro().
parser::location_type newlang::Parser::m_location |
Definition at line 48 of file parser.h.
Referenced by ExpandPredefMacro(), GetNextToken(), and PragmaEval().
std::vector<ParserLocation> newlang::Parser::m_loc_stack |
Definition at line 55 of file parser.h.
Referenced by PragmaEval().
std::istringstream newlang::Parser::m_stream |
|
static |
Definition at line 62 of file parser.h.
Referenced by ExpandPredefMacro().
std::map<std::string, std::string> newlang::Parser::m_predef_macro |
Definition at line 63 of file parser.h.
Referenced by CheckPredefMacro(), ExpandPredefMacro(), InitPredefMacro(), and RegisterPredefMacro().
class Scanner* newlang::Parser::lexer |
Pointer to the current lexer instance, this is used to connect the parser to the scanner. It is used in the yylex macro.
Definition at line 83 of file parser.h.
Referenced by AstAddTerm(), newlang::ExpandTermMacro(), GetNextToken(), and Parse().
BlockType newlang::Parser::m_macro_analisys_buff |
Последовательность лексем для анализа на наличие макросов
Definition at line 91 of file parser.h.
Referenced by newlang::ExpandTermMacro(), and GetNextToken().
TermPtr newlang::Parser::m_expected |
Definition at line 93 of file parser.h.
Referenced by GetNextToken(), and PragmaEval().
TermPtr newlang::Parser::m_unexpected |
Definition at line 94 of file parser.h.
Referenced by GetNextToken(), and PragmaEval().
TermPtr newlang::Parser::m_finalize |
Definition at line 95 of file parser.h.
Referenced by PragmaEval().
int newlang::Parser::m_finalize_counter |
Definition at line 96 of file parser.h.
Referenced by PragmaEval().
TermPtr newlang::Parser::m_annotation |
Definition at line 97 of file parser.h.
Referenced by Parser(), and PragmaEval().
bool newlang::Parser::m_no_macro |
Definition at line 98 of file parser.h.
Referenced by GetNextToken(), Parser(), and PragmaEval().
bool newlang::Parser::m_enable_pragma |
Definition at line 99 of file parser.h.
Referenced by GetNextToken(), and Parser().
time_t newlang::Parser::m_timestamp |
Definition at line 133 of file parser.h.
Referenced by ExpandPredefMacro(), and Parser().
std::string newlang::Parser::m_file_time |
Definition at line 135 of file parser.h.
Referenced by ExpandPredefMacro(), ParseFile(), and Parser().
std::string newlang::Parser::m_file_md5 |
Definition at line 136 of file parser.h.
Referenced by ExpandPredefMacro(), ParseFile(), and Parser().
DiagPtr newlang::Parser::m_diag |
Definition at line 138 of file parser.h.
Referenced by Parse(), Parser(), PragmaEval(), and newlang::ProcessMacro().
MacroPtr newlang::Parser::m_macro |
Definition at line 139 of file parser.h.
Referenced by newlang::ExpandTermMacro(), Parser(), and newlang::ProcessMacro().
bool newlang::Parser::m_is_lexer_complete |
Definition at line 140 of file parser.h.
Referenced by newlang::ExpandTermMacro(), GetNextToken(), and Parser().
|
private |
|
private |
Definition at line 143 of file parser.h.
Referenced by GetNextToken(), and Parser().
|
private |
Definition at line 144 of file parser.h.
Referenced by GetNextToken(), and Parser().
|
private |
Definition at line 145 of file parser.h.
Referenced by ExpandPredefMacro(), Parser(), and PragmaEval().