|
topazc
|
#include <parser.hpp>
Public Member Functions | |
| Parser (std::vector< Token > t, bool id) | |
| std::vector< AST::StmtPtr > | parse () |
| Method for parsing tokens into AST tree. | |
| void | reset () |
| Method for resetting all parameters in parser. | |
Private Member Functions | |
| AST::StmtPtr | parse_stmt (bool from_for=false) |
| Method for parsing only one statement. | |
| AST::StmtPtr | parse_var_decl_stmt () |
| Method for parsing of variable declaration. | |
| AST::StmtPtr | parse_var_asgn_stmt () |
| Method for parsing of variable assignment. | |
| AST::StmtPtr | parse_func_decl_stmt () |
| Method for parsing of functions declaration. | |
| AST::StmtPtr | parse_func_call_stmt () |
| Method for parsing of functions calling. | |
| AST::Argument | parse_argument () |
| Method for parsing of function argument. | |
| AST::StmtPtr | parse_return_stmt () |
| Method for parsing of 'return'. | |
| AST::StmtPtr | parse_if_else_stmt () |
| Method for parsing of control flow operators (aka if-else). | |
| AST::StmtPtr | parse_while_cycle_stmt () |
| Method for parsing of while cycle. | |
| AST::StmtPtr | parse_do_while_cycle_stmt () |
| Method for parsing of do-while cycle. | |
| AST::StmtPtr | parse_for_cycle_stmt () |
| Method for parsing of for cycle. | |
| AST::StmtPtr | parse_break_stmt () |
| Method for parsing of break statement. | |
| AST::StmtPtr | parse_continue_stmt () |
| Method for parsing of continue statement. | |
| AST::StmtPtr | parse_module_stmt () |
| Method for parsing of module definition. | |
| AST::StmtPtr | parse_use_module_stmt () |
| Method for parsing of import the module. | |
| AST::StmtPtr | parse_func_decl_proto_stmt () |
| Method for parsing of functions prototypes. | |
| AST::StmtPtr | parse_extern_stmt () |
| Method for parsing of declaration functions prototypes as extern. | |
| AST::ExprPtr | parse_expr () |
| Method for parsing expressions. | |
| AST::ExprPtr | parse_l_and_expr () |
| Method for parsing expression as 'logical and'. | |
| AST::ExprPtr | parse_l_or_expr () |
| Method for parsing expression as 'logical or'. | |
| AST::ExprPtr | parse_equality_expr () |
| Method for parsing expression as 'equality'. | |
| AST::ExprPtr | parse_comparation_expr () |
| Method for parsing expression as 'comparation'. | |
| AST::ExprPtr | parse_additive_expr () |
| Method for parsing expression as 'additive'. | |
| AST::ExprPtr | parse_multiplicative_expr () |
| Method for parsing expression as 'multiplicative'. | |
| AST::ExprPtr | parse_unary_expr () |
| Method for parsing expression as 'unary'. | |
| AST::ExprPtr | parse_primary_expr () |
| Method for parsing expression as 'primary'. | |
| AST::ExprPtr | parse_obj_chain_expr () |
| Method for parsing expresion as chain of objects. | |
| Token | peek (int32_t rpos=0) const |
| Method for getting token from tokens by parser pos and passed offset. | |
| bool | match (TokenType type) |
| Method for skipping the current token if its type is equal to the passed one. | |
| Token | consume (TokenType type, std::string err_msg, uint32_t line) |
| Method for verifying the type of the current token. | |
| AST::Type | consume_type () |
| Method for verifyng the Topaz type by current tokens. | |
| void | consume_semicolon () |
| Method for skipping semicolon in the end of statement. | |
| AST::TypeValue | ttype_to_tvalue (TokenType type) |
| Method for convert type of token to type of Topaz value. | |
| bool | is_compound_asgn_operator (Token token) |
| Method for checking whether the passed token is a compound assignment operator. | |
| AST::ExprPtr | create_compound_asgn_operator (std::string var_name) |
| Method for creating compound assignment operator and returns expression of assignment. | |
| AST::ExprPtr | create_inc_dec_operator (std::string var_name) |
| Method for creating increment/decrement operator and returns expression of assignment. | |
Private Attributes | |
| std::vector< Token > | tokens |
| size_t | tokens_count |
| uint32_t | pos |
| bool | is_debug |
Parser class.
Definition at line 14 of file parser.hpp.
|
inline |
Definition at line 22 of file parser.hpp.
Method for verifying the type of the current token.
This method checks whether the type of the current token is equal to the passed type. If equal, it skips and returns it, otherwise it throws an exception with the passed message
| type | Type of token for verification |
| err_msg | Error message if verification is fault |
| line | Line coordinate. For exception |
Definition at line 593 of file parser.cpp.


|
private |
Method for skipping semicolon in the end of statement.
This method checks the current token and if it is the semicolon, then skipping it, otherwise throwing exception
Definition at line 636 of file parser.cpp.


|
private |
Method for verifyng the Topaz type by current tokens.
This method checks the current keywords to collect the final Topaz type and returns it. If the tokens are in the wrong sequence or are not part of the type, an exception is thrown
Definition at line 601 of file parser.cpp.


|
private |
Method for creating compound assignment operator and returns expression of assignment.
This method checking current token and if it is compound assignment operator, then generating expression for assignment. For example 'a += 1' is equal 'a = a + 1' If current token isnt compound assignment operator, then throwing exception
| var_name | Name of variable for assignment |
Definition at line 686 of file parser.cpp.


|
private |
Method for creating increment/decrement operator and returns expression of assignment.
This method checking current token and if it is increment/decrement operator, then generating expression of assignment. For example 'a++' is equal 'a = a + 1' If current token isnt increment/decrement operator, then throwing exception
| var_name | Name of variable for assignment |
Definition at line 708 of file parser.cpp.


|
private |
Method for checking whether the passed token is a compound assignment operator.
This method checks whether the passed token is a compound assignment operator. If yes, it returns true, otherwise it returns false
| token | Token for checking |
Definition at line 673 of file parser.cpp.

|
private |
Method for skipping the current token if its type is equal to the passed one.
If type of current token is equal to the passed type, then this token will be skipped and returns 'true'. Otherwise returns 'false'
| type | Type of token wich need to skip |
Definition at line 585 of file parser.cpp.


| std::vector< AST::StmtPtr > Parser::parse | ( | ) |
Method for parsing tokens into AST tree.
This method parsing all tokens, creates AST tree and returns it
Definition at line 10 of file parser.cpp.


|
private |
Method for parsing expression as 'additive'.
This method parsing all expressions as 'additive'. If type of current token isnt TOK_OP_PLUS (aka +) or TOK_OP_MINUS (aka -), then returns created expression
Definition at line 420 of file parser.cpp.


|
private |
Method for parsing of function argument.
This method sets the syntax for defining a function argument, creates the AST element of the Argument and returns it
Definition at line 201 of file parser.cpp.


|
private |
Method for parsing of break statement.
This method sets the syntax for break statement, creates the AST element of the BreakStmt and returns it
Definition at line 285 of file parser.cpp.


|
private |
Method for parsing expression as 'comparation'.
This method parsing all expressions as 'comparation'. If type of current token isnt TOK_OP_GT (aka >) or TOK_OP_GT_EQ (aka >=) or TOK_OP_LS (aka <) or TOK_OP_LS_EQ (aka <=), then returns created expression
Definition at line 397 of file parser.cpp.


|
private |
Method for parsing of continue statement.
This method sets the syntax for continue statement, creates the AST element of the ContinueStmt and returns it
Definition at line 290 of file parser.cpp.


|
private |
Method for parsing of do-while cycle.
This method sets the syntax for do-while cycle, creates the AST element of the DoWhileCycleStmt and returns it
Definition at line 257 of file parser.cpp.


|
private |
Method for parsing expression as 'equality'.
This method parsing all expressions as 'equality'. If type of current token isnt TOK_OP_EQ_EQ (aka ==) or TOK_OP_NOT_EQ_EQ (aka !=), then returns created expression
Definition at line 380 of file parser.cpp.


|
private |
Method for parsing expressions.
This method parsing expression, creates the AST element and returns it
Definition at line 358 of file parser.cpp.


|
private |
Method for parsing of declaration functions prototypes as extern.
This method sets the syntax for extern functions declaration, creates the AST element of the ExternStmt and returns it
Definition at line 347 of file parser.cpp.


|
private |
Method for parsing of for cycle.
This method sets the syntax for for cycle, creates the AST element of the ForCycleStmt and returns it
Definition at line 269 of file parser.cpp.


|
private |
Method for parsing of functions calling.
This method sets the syntax for calling a function, creates the AST element of the FuncCallStmt and returns it
Definition at line 185 of file parser.cpp.


|
private |
Method for parsing of functions prototypes.
This method sets the syntax for function prototype declaration, creates the AST element of the FuncDeclStmt without body and returns it
Definition at line 320 of file parser.cpp.


|
private |
Method for parsing of functions declaration.
This method sets the syntax for defining a function, creates the AST element of the FuncDeclStmt and returns it
Definition at line 152 of file parser.cpp.


|
private |
Method for parsing of control flow operators (aka if-else).
This method sets the syntax for control flow operators, creates the AST element of the IfElseStmt and returns it
Definition at line 224 of file parser.cpp.


|
private |
Method for parsing expression as 'logical and'.
This method parsing all expressions as 'logical and'. If type of current token isnt TOK_OP_L_AND (aka &&), then returns created expression
Definition at line 362 of file parser.cpp.


|
private |
Method for parsing expression as 'logical or'.
This method parsing all expressions as 'logical or'. If type of current token isnt TOK_OP_L_OR (aka ||), then returns created expression
Definition at line 371 of file parser.cpp.


|
private |
Method for parsing of module definition.
This method sets the syntax for module definition, creates the AST element of the ModuleStmt and returns it
Definition at line 295 of file parser.cpp.


|
private |
Method for parsing expression as 'multiplicative'.
This method parsing all expressions as 'multiplicative'. If type of current token isnt TOK_OP_MULT (aka *) or TOK_OP_DIV (aka /) or TOK_OP_MODULO (aka %), then returns created expression
Definition at line 437 of file parser.cpp.


|
private |
Method for parsing expresion as chain of objects.
This method parsing all expressions as chain of objects. Elements of chain separated of '.' (for example: obj1.obj2)
Definition at line 548 of file parser.cpp.


|
private |
Method for parsing expression as 'primary'.
This method parsing all expressions as 'primary'. If type of current token isnt literal or identifier, then throwing exception
Definition at line 479 of file parser.cpp.


|
private |
Method for parsing of 'return'.
This method sets the syntax for 'return' statement, creates the AST element of the ReturnStmt and returns it
Definition at line 215 of file parser.cpp.


|
private |
Method for parsing only one statement.
This method parsing one statement and returns it
| from_for | Flag that indicates that the method is being called to process the for loop. If true, then processing for the for loop, otherwise not |
Definition at line 26 of file parser.cpp.


|
private |
Method for parsing expression as 'unary'.
This method parsing all expressions as 'unary'. If type of current token isnt TOK_OP_L_NOT (aka !) or TOK_OP_MINUS (aka -), then returns created expression
Definition at line 457 of file parser.cpp.


|
private |
Method for parsing of import the module.
This method sets the syntax for import the module, creates the AST element of the UseModuleStmt and returns it
Definition at line 309 of file parser.cpp.


|
private |
Method for parsing of variable assignment.
This method sets the syntax for assignment a variable, creates the AST element of the VarAsgnStmt and returns it
Definition at line 131 of file parser.cpp.


|
private |
Method for parsing of variable declaration.
This method sets the syntax for defining a variable, creates the AST element of the VarDeclStmt and returns it
Definition at line 117 of file parser.cpp.


|
private |
Method for parsing of while cycle.
This method sets the syntax for while cycle, creates the AST element of the WhileCycleStmt and returns it
Definition at line 246 of file parser.cpp.


|
private |
Method for getting token from tokens by parser pos and passed offset.
This method getting getting token from tokens by parser pos and passed offset If pos + offset out of bounds of range tokens, then throwing exception
| rpos | Offset |
Definition at line 576 of file parser.cpp.


| void Parser::reset | ( | ) |
Method for resetting all parameters in parser.
Definition at line 20 of file parser.cpp.

|
private |
Method for convert type of token to type of Topaz value.
This method converts the passed token type to the Topaz value type. If the conversion fails, an exception is thrown
| type | Type of token for convertion |
Definition at line 648 of file parser.cpp.


|
private |
Flag for debug exception
Definition at line 19 of file parser.hpp.
|
private |
Current position in tokens
Definition at line 18 of file parser.hpp.
|
private |
Tokens (from Lexer)
Definition at line 16 of file parser.hpp.
|
private |
Count of tokens
Definition at line 17 of file parser.hpp.