NewLang Project
Yet another programm language
Loading...
Searching...
No Matches
newlang::Parser Class Reference

#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< ParserLocationm_loc_stack
 
std::istringstream m_stream
 
std::map< std::string, std::string > m_predef_macro
 
class Scannerlexer
 
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
 
PostLexerTypem_postlex
 
RunTimem_rt
 

Detailed Description

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.

Definition at line 32 of file parser.h.

Constructor & Destructor Documentation

◆ Parser()

Parser::Parser ( MacroPtr macro = nullptr,
PostLexerType * postlex = nullptr,
DiagPtr diag = nullptr,
bool pragma_enable = true,
RunTime * rt = nullptr )

◆ ~Parser()

virtual newlang::Parser::~Parser ( )
inlinevirtual

Definition at line 37 of file parser.h.

Member Function Documentation

◆ ExpandPredefMacro()

◆ RegisterPredefMacro()

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().

◆ InitPredefMacro()

void Parser::InitPredefMacro ( )

Definition at line 592 of file parser.cpp.

References m_predef_macro, RegisterPredefMacro(), and VERIFY.

Referenced by ExpandPredefMacro().

◆ CheckPredefMacro()

bool Parser::CheckPredefMacro ( const TermPtr & term)

Definition at line 636 of file parser.cpp.

References m_predef_macro, and newlang::NAME.

Referenced by PragmaCheck().

◆ error() [1/2]

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.

◆ error() [2/2]

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.

◆ AstAddTerm()

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.

◆ GetAst()

TermPtr Parser::GetAst ( )

Definition at line 126 of file parser.cpp.

References m_ast.

◆ GetNextToken()

◆ PragmaCheck()

bool Parser::PragmaCheck ( const TermPtr & term)

Definition at line 176 of file parser.cpp.

References CheckPredefMacro().

Referenced by GetNextToken().

◆ PragmaEval()

◆ PragmaStaticAssert()

bool Parser::PragmaStaticAssert ( const TermPtr & term)

◆ StaticEval()

static ObjPtr newlang::Parser::StaticEval ( const TermPtr & term)
static

◆ Parse()

TermPtr Parser::Parse ( const std::string str,
bool expand_module = false )

◆ ParseFile()

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().

◆ ParseTerm() [1/2]

size_t Parser::ParseTerm ( TermPtr & term,
const BlockType & buffer,
const size_t skip = 0,
bool pragma_enable = true )
static

◆ ParseTerm() [2/2]

TermPtr Parser::ParseTerm ( const char * proto,
MacroPtr macro = nullptr,
bool pragma_enable = true )
static

Definition at line 845 of file parser.cpp.

References LOG_RUNTIME, and Parse().

◆ IsBracket()

static bool newlang::Parser::IsBracket ( const std::string_view str)
inlinestatic

Definition at line 119 of file parser.h.

◆ GetCurrentDate()

std::string Parser::GetCurrentDate ( time_t ts = std::time(NULL))
static

Definition at line 649 of file parser.cpp.

Referenced by ExpandPredefMacro().

◆ GetCurrentTime()

std::string Parser::GetCurrentTime ( time_t ts = std::time(NULL))
static

Definition at line 655 of file parser.cpp.

Referenced by ExpandPredefMacro().

◆ GetCurrentTimeStamp()

std::string Parser::GetCurrentTimeStamp ( time_t ts = std::time(NULL))
static

Definition at line 661 of file parser.cpp.

References result.

Referenced by ExpandPredefMacro(), newlang::JIT::MakeCodeModule(), and newlang::JIT::MakeMainEmbed().

◆ GetCurrentTimeStampISO()

std::string Parser::GetCurrentTimeStampISO ( time_t ts = std::time(NULL))
static

Definition at line 667 of file parser.cpp.

Referenced by ExpandPredefMacro().

◆ CheckModuleTerm()

TermPtr Parser::CheckModuleTerm ( const TermPtr & term)

Definition at line 964 of file parser.cpp.

References newlang::CheckCharModuleName(), newlang::isModuleName(), and NL_PARSER.

◆ SkipBrackets()

size_t Parser::SkipBrackets ( const BlockType & buffer,
size_t offset )
static

Definition at line 862 of file parser.cpp.

References NL_PARSER.

Referenced by newlang::Macro::IdentityMacro(), ParseTerm(), and newlang::Macro::SymbolSeparateArg_().

Member Data Documentation

◆ trace_scanning

bool newlang::Parser::trace_scanning

enable debug output in the flex scanner

Definition at line 40 of file parser.h.

◆ trace_parsing

bool newlang::Parser::trace_parsing

enable debug output in the bison parser

Definition at line 43 of file parser.h.

◆ m_filename

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().

◆ m_name_module

std::string newlang::Parser::m_name_module

Definition at line 47 of file parser.h.

Referenced by ExpandPredefMacro().

◆ m_location

parser::location_type newlang::Parser::m_location

Definition at line 48 of file parser.h.

Referenced by ExpandPredefMacro(), GetNextToken(), and PragmaEval().

◆ m_loc_stack

std::vector<ParserLocation> newlang::Parser::m_loc_stack

Definition at line 55 of file parser.h.

Referenced by PragmaEval().

◆ m_stream

std::istringstream newlang::Parser::m_stream

Definition at line 57 of file parser.h.

Referenced by Parse().

◆ m_counter

int Parser::m_counter = 0
static

Definition at line 62 of file parser.h.

Referenced by ExpandPredefMacro().

◆ m_predef_macro

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().

◆ lexer

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().

◆ m_macro_analisys_buff

BlockType newlang::Parser::m_macro_analisys_buff

Последовательность лексем для анализа на наличие макросов

Definition at line 91 of file parser.h.

Referenced by newlang::ExpandTermMacro(), and GetNextToken().

◆ m_expected

TermPtr newlang::Parser::m_expected

Definition at line 93 of file parser.h.

Referenced by GetNextToken(), and PragmaEval().

◆ m_unexpected

TermPtr newlang::Parser::m_unexpected

Definition at line 94 of file parser.h.

Referenced by GetNextToken(), and PragmaEval().

◆ m_finalize

TermPtr newlang::Parser::m_finalize

Definition at line 95 of file parser.h.

Referenced by PragmaEval().

◆ m_finalize_counter

int newlang::Parser::m_finalize_counter

Definition at line 96 of file parser.h.

Referenced by PragmaEval().

◆ m_annotation

TermPtr newlang::Parser::m_annotation

Definition at line 97 of file parser.h.

Referenced by Parser(), and PragmaEval().

◆ m_no_macro

bool newlang::Parser::m_no_macro

Definition at line 98 of file parser.h.

Referenced by GetNextToken(), Parser(), and PragmaEval().

◆ m_enable_pragma

bool newlang::Parser::m_enable_pragma

Definition at line 99 of file parser.h.

Referenced by GetNextToken(), and Parser().

◆ m_timestamp

time_t newlang::Parser::m_timestamp

Definition at line 133 of file parser.h.

Referenced by ExpandPredefMacro(), and Parser().

◆ m_file_time

std::string newlang::Parser::m_file_time

Definition at line 135 of file parser.h.

Referenced by ExpandPredefMacro(), ParseFile(), and Parser().

◆ m_file_md5

std::string newlang::Parser::m_file_md5

Definition at line 136 of file parser.h.

Referenced by ExpandPredefMacro(), ParseFile(), and Parser().

◆ m_diag

DiagPtr newlang::Parser::m_diag

Definition at line 138 of file parser.h.

Referenced by Parse(), Parser(), PragmaEval(), and newlang::ProcessMacro().

◆ m_macro

MacroPtr newlang::Parser::m_macro

Definition at line 139 of file parser.h.

Referenced by newlang::ExpandTermMacro(), Parser(), and newlang::ProcessMacro().

◆ m_is_lexer_complete

bool newlang::Parser::m_is_lexer_complete

Definition at line 140 of file parser.h.

Referenced by newlang::ExpandTermMacro(), GetNextToken(), and Parser().

◆ m_ast

TermPtr newlang::Parser::m_ast
private

Definition at line 142 of file parser.h.

Referenced by AstAddTerm(), GetAst(), Parse(), and Parser().

◆ m_is_runing

bool newlang::Parser::m_is_runing
private

Definition at line 143 of file parser.h.

Referenced by GetNextToken(), and Parser().

◆ m_postlex

PostLexerType* newlang::Parser::m_postlex
private

Definition at line 144 of file parser.h.

Referenced by GetNextToken(), and Parser().

◆ m_rt

RunTime* newlang::Parser::m_rt
private

Definition at line 145 of file parser.h.

Referenced by ExpandPredefMacro(), Parser(), and PragmaEval().


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