AALanguage
The best language for those who have nothing to do
|
The main class that implements syntactic analysis of the program by array of tokens. During its execution other components of the interpreter are called. More...
#include <Analyzer.h>
Public Member Functions | |
Analyzer () | |
Default constructor, which initializes the POLIZ generator and the semantic analyzer. | |
void | execute (std::string path, std::string lib_path) |
A function that starts full analysis and generation of a file with specified parameters. | |
Private Attributes | |
Token | current_token |
Poliz | prog |
Semantic | semantic |
std::vector< std::string > | service_types |
All built-in language types. | |
The main class that implements syntactic analysis of the program by array of tokens. During its execution other components of the interpreter are called.
Definition at line 19 of file Analyzer.h.
Analyzer::Analyzer | ( | ) |
Default constructor, which initializes the POLIZ generator and the semantic analyzer.
Definition at line 3 of file Analyzer.cpp.
References Semantic::current_function, prog, and semantic.
|
private |
<assignment-expression> ::= <logical-or-expression>{("=" | "+=" | "-=" | "*=" | "/=" | "%=" | ">>=" | "<<=" | "&=" | "^=" | "|=" | "->=" | "~=")<logical-or-expression>}
Definition at line 385 of file Analyzer.cpp.
References Poliz::ASSIGN, Semantic::calc_expr_type(), Semantic::check_operation(), current_token, Semantic::exprs, LexicalAnalyzer::get_token(), logical_or_expression(), prog, Poliz::put_lex(), semantic, Semantic::type_to_string(), and Token::value.
Referenced by expression().
|
private |
<bitwise-and-expression> ::= <equality-expression>{"&" <equality-expression>}
Definition at line 499 of file Analyzer.cpp.
References Poliz::BITWISE_AND, Semantic::calc_expr_type(), Semantic::check_operation(), current_token, equality_expression(), Semantic::exprs, LexicalAnalyzer::get_token(), prog, Poliz::put_lex(), semantic, Semantic::type_to_string(), and Token::value.
Referenced by bitwise_consequence_expression().
|
private |
<bitwise-consequence-expression> ::= <bitwise-and-expression>{"->" <bitwise-and-expression>}
Definition at line 483 of file Analyzer.cpp.
References bitwise_and_expression(), Poliz::BITWISE_CONS, Semantic::calc_expr_type(), Semantic::check_operation(), current_token, Semantic::exprs, LexicalAnalyzer::get_token(), prog, Poliz::put_lex(), semantic, Semantic::type_to_string(), and Token::value.
Referenced by bitwise_xor_expression().
|
private |
<bitwise-or-expression> ::= <bitwise-xor-expression>{"|" <bitwise-xor-expression>}
Definition at line 451 of file Analyzer.cpp.
References Poliz::BITWISE_OR, bitwise_xor_expression(), Semantic::calc_expr_type(), Semantic::check_operation(), current_token, Semantic::exprs, LexicalAnalyzer::get_token(), prog, Poliz::put_lex(), semantic, Semantic::type_to_string(), and Token::value.
Referenced by logical_and_expression().
|
private |
<bitwise-shift-expression> ::= <plus-expression>{(">>" | "<<") <plus-expression>}
Definition at line 551 of file Analyzer.cpp.
References Poliz::BITWISE_SHIFT, Semantic::calc_expr_type(), Semantic::check_operation(), current_token, Semantic::exprs, LexicalAnalyzer::get_token(), plus_expression(), prog, Poliz::put_lex(), semantic, Semantic::type_to_string(), and Token::value.
Referenced by comparison_expression().
|
private |
<bitwise-xor-expression> ::= <bitwise-consequence-expression>{"^" <bitwise-consequence-expression>}
Definition at line 467 of file Analyzer.cpp.
References bitwise_consequence_expression(), Poliz::BITWISE_XOR, Semantic::calc_expr_type(), Semantic::check_operation(), current_token, Semantic::exprs, LexicalAnalyzer::get_token(), prog, Poliz::put_lex(), semantic, Semantic::type_to_string(), and Token::value.
Referenced by bitwise_or_expression().
|
private |
<comparison-expression> ::= <bitwise-shift-expression>{(">" | ">=" | "<" | "<=") <bitwise-shift-expression>}
Definition at line 533 of file Analyzer.cpp.
References bitwise_shift_expression(), Bool, Semantic::check_operation(), Poliz::CMP, current_token, Semantic::exprs, LexicalAnalyzer::get_token(), prog, Poliz::put_lex(), semantic, Semantic::type_to_string(), and Token::value.
Referenced by equality_expression().
|
private |
<construct-expression> ::= <identifier> | <literal> | <field> | "("<expression>")"
Definition at line 644 of file Analyzer.cpp.
References current_token, expression(), Semantic::exprs, field(), LexicalAnalyzer::get_token(), LexicalAnalyzer::literal, Poliz::LITERAL, Semantic::literal_to_type(), prog, Poliz::put_lex(), semantic, Token::type, and Token::value.
Referenced by unary_expression().
|
private |
Definition at line 1279 of file Analyzer.cpp.
References Poliz::CONVERT, current_token, default_type(), expression(), Semantic::exprs, LexicalAnalyzer::get_token(), prog, Poliz::put_lex(), semantic, Semantic::string_to_type(), and Token::value.
Referenced by field(), and statement().
|
private |
<default-type> ::= <identifier>
Definition at line 257 of file Analyzer.cpp.
References current_token, LexicalAnalyzer::get_token(), service_types, and Token::value.
Referenced by convert_statement(), function(), function_or_var_definitions(), and type().
|
private |
<equality-expression> ::= <comparison-expression>{("!=" | "==") <comparison-expression>}
Definition at line 515 of file Analyzer.cpp.
References Bool, Semantic::check_operation(), comparison_expression(), current_token, Poliz::EQUALITY, Semantic::exprs, LexicalAnalyzer::get_token(), prog, Poliz::put_lex(), semantic, Semantic::type_to_string(), and Token::value.
Referenced by bitwise_and_expression().
void Analyzer::execute | ( | std::string | path, |
std::string | lib_path ) |
A function that starts full analysis and generation of a file with specified parameters.
path | Path to the AALanguage program |
lib_path | Path to the directory with built-in libraries |
Definition at line 7 of file Analyzer.cpp.
References Poliz::convert(), current_token, Poliz::execute(), Semantic::get_function(), LexicalAnalyzer::get_token(), Token::line, main(), prog, program(), semantic, and Poliz::STRING_LITERAL.
Referenced by main().
|
private |
Definition at line 1251 of file Analyzer.cpp.
References current_token, Poliz::EXIT, expression(), LexicalAnalyzer::get_token(), prog, Poliz::put_lex(), and Token::value.
Referenced by statement().
|
private |
<expression> ::= <assignment-expression>{"," <assignment-expression>}
Definition at line 369 of file Analyzer.cpp.
References assignment_expression(), Poliz::COMMA, current_token, Semantic::exprs, LexicalAnalyzer::get_token(), Poliz::PRINT, prog, Poliz::put_lex(), semantic, and Token::value.
Referenced by construct_expression(), convert_statement(), exit_statement(), field(), for_statement(), if_statement(), print_statement(), return_statement(), statement(), strlen_statement(), switch_statement(), var_definition(), var_definitions(), and while_statement().
|
private |
<field> ::= <identifier>{("."<identifier> | "["<expression>"]" | "("[<expression>{","<expression>}]")")}
Definition at line 662 of file Analyzer.cpp.
References Poliz::ADDRESS, Poliz::CALL, Char, convert_statement(), current_token, Type::expr_type, expression(), Semantic::exprs, Semantic::get_function(), Semantic::get_identifier(), LexicalAnalyzer::get_token(), Poliz::GETARR, Poliz::GETSTR, LexicalAnalyzer::identifier, Type::is_array, Semantic::is_convertible(), Long, prog, Poliz::put_lex(), rand_statement(), semantic, LexicalAnalyzer::service, String, strlen_statement(), time_statement(), Token::type, Identifier::type, and Token::value.
Referenced by construct_expression(), read_statement(), and readln_statement().
|
private |
<for-statement> ::= "for" "("[<expression>]";"[<expression>]";"[<expression>]")"<statement>
Definition at line 935 of file Analyzer.cpp.
References Poliz::blank(), Bool, Semantic::break_ptr, Semantic::continue_ptr, Semantic::create_table(), current_token, expression(), Semantic::exprs, Poliz::FGO, Poliz::get_size(), LexicalAnalyzer::get_token(), Poliz::GO, LexicalAnalyzer::identifier, Poliz::POINTER, LexicalAnalyzer::prev_token(), prog, Poliz::put_lex(), semantic, semicolon(), LexicalAnalyzer::service, service_types, statement(), Token::type, Semantic::type_to_string(), Token::value, and var_definitions().
Referenced by statement().
|
private |
<function> ::= <type> <identifier>"("[parameter-list]")" "{" {<statement>} "}"
Definition at line 267 of file Analyzer.cpp.
References Type::array_size, Semantic::create_function(), Semantic::create_table(), Semantic::current_function, current_token, default_type(), Type::expr_type, Semantic::function_params_init, Semantic::function_params_pref, Poliz::get_size(), LexicalAnalyzer::get_token(), LexicalAnalyzer::identifier, LexicalAnalyzer::integer, Type::is_array, LexicalAnalyzer::is_literal(), Poliz::LABEL, Token::line, may_be_semicolon(), Poliz::NORET, parameter_list(), Semantic::params_ptrs, prog, Poliz::put_lex(), semantic, statement(), Semantic::string_to_type(), Token::type, Token::value, and Void.
Referenced by function_or_var_definitions().
|
private |
Definition at line 334 of file Analyzer.cpp.
References current_token, default_type(), function(), LexicalAnalyzer::get_token(), LexicalAnalyzer::identifier, LexicalAnalyzer::prev_token(), Token::type, Token::value, and var_definitions().
Referenced by program_body().
|
private |
<goto-statement> ::= ("goto" <identifier> | "break" | "continue")";"
Definition at line 861 of file Analyzer.cpp.
References Semantic::break_ptr, Semantic::continue_ptr, current_token, LexicalAnalyzer::get_token(), Poliz::GO, Poliz::POINTER, prog, Poliz::put_lex(), semantic, and Token::value.
Referenced by statement().
|
private |
<if-statement> ::= "if("<expression>")" <statement> {"elif("<expression")" <statement>} ["else" <statement>]
Definition at line 805 of file Analyzer.cpp.
References Poliz::blank(), Bool, current_token, expression(), Semantic::exprs, Poliz::FGO, Poliz::get_size(), LexicalAnalyzer::get_token(), Poliz::GO, Poliz::POINTER, prog, Poliz::put_lex(), semantic, statement(), Semantic::type_to_string(), and Token::value.
Referenced by statement().
|
private |
<logical-and-expression> ::= <bitwise-or-expression>{"&&" <bitwise-or-expression>}
Definition at line 435 of file Analyzer.cpp.
References bitwise_or_expression(), Bool, Semantic::check_operation(), current_token, Semantic::exprs, LexicalAnalyzer::get_token(), Poliz::LOGICAL_AND, prog, Poliz::put_lex(), semantic, Semantic::type_to_string(), and Token::value.
Referenced by logical_or_expression().
|
private |
<logical-or-expression> ::= <logical-and-expression>{"||" <logical-and-expression>}
Definition at line 419 of file Analyzer.cpp.
References Bool, Semantic::check_operation(), current_token, Semantic::exprs, LexicalAnalyzer::get_token(), logical_and_expression(), Poliz::LOGICAL_OR, prog, Poliz::put_lex(), semantic, Semantic::type_to_string(), and Token::value.
Referenced by assignment_expression().
|
private |
Definition at line 59 of file Analyzer.cpp.
References current_token, LexicalAnalyzer::get_token(), prog, Poliz::put_lex(), Poliz::SEMICOLON, and Token::value.
Referenced by function(), preprocessor(), program(), program_body(), semicolon(), statement(), and var_definitions().
|
private |
<multiply-expression> ::= <unary-expression>{("*" | "/" | "%") <unary-expression>}
Definition at line 587 of file Analyzer.cpp.
References Semantic::calc_expr_type(), Semantic::check_operation(), current_token, Semantic::exprs, LexicalAnalyzer::get_token(), Poliz::MULT, prog, Poliz::put_lex(), semantic, Semantic::type_to_string(), unary_expression(), and Token::value.
Referenced by plus_expression().
|
private |
<namespace-definiton> ::= <identifier> | <identifier>"."<namespace-definiton>
Definition at line 83 of file Analyzer.cpp.
References current_token, LexicalAnalyzer::get_token(), LexicalAnalyzer::identifier, prog, Poliz::put_lex(), Token::type, Poliz::USING, and Token::value.
Referenced by preprocessor().
|
private |
<parameter-list> ::= <var-definition> {","<var-definition>}
Definition at line 787 of file Analyzer.cpp.
References Poliz::blank(), current_token, Semantic::function_params_init, Semantic::function_params_pref, Poliz::get_size(), LexicalAnalyzer::get_token(), Semantic::is_in_function_header, prog, semantic, Token::value, var_definition(), and Semantic::was_function_assign.
Referenced by function().
|
private |
<plus-expression> ::= <multiply-expression>{("+" | "-") <multiply-expression>}
Definition at line 569 of file Analyzer.cpp.
References Semantic::calc_expr_type(), Semantic::check_operation(), current_token, Semantic::exprs, LexicalAnalyzer::get_token(), multiply_expression(), Poliz::PLUS, prog, Poliz::put_lex(), semantic, Semantic::type_to_string(), and Token::value.
Referenced by bitwise_shift_expression().
|
private |
<preprocessor> ::= {"using" <namespace-definiton>";"}
Definition at line 73 of file Analyzer.cpp.
References current_token, LexicalAnalyzer::get_token(), may_be_semicolon(), namespace_definition(), semicolon(), and Token::value.
Referenced by program().
|
private |
Definition at line 1087 of file Analyzer.cpp.
References current_token, expression(), Semantic::exprs, LexicalAnalyzer::get_token(), semantic, and Token::value.
Referenced by statement().
|
private |
<program> ::= <preprocessor> <program-body>
Definition at line 66 of file Analyzer.cpp.
References current_token, Token::line, may_be_semicolon(), preprocessor(), and program_body().
Referenced by execute().
|
private |
<program-body> ::= [<function>|<var-definitons>|<struct-statement>]{<program-body>}
Definition at line 100 of file Analyzer.cpp.
References current_token, function_or_var_definitions(), Token::line, may_be_semicolon(), and program_body().
Referenced by program(), and program_body().
|
private |
Definition at line 1298 of file Analyzer.cpp.
References current_token, Semantic::exprs, LexicalAnalyzer::get_token(), Int, prog, Poliz::put_lex(), Poliz::RAND, semantic, and Token::value.
Referenced by field().
|
private |
Definition at line 1101 of file Analyzer.cpp.
References current_token, Semantic::exprs, field(), LexicalAnalyzer::get_token(), prog, Poliz::put_lex(), Poliz::READ, semantic, and Token::value.
Referenced by statement().
|
private |
Definition at line 1122 of file Analyzer.cpp.
References current_token, Semantic::exprs, field(), LexicalAnalyzer::get_token(), prog, Poliz::put_lex(), Poliz::READLN, semantic, String, type(), and Token::value.
Referenced by statement().
|
private |
<return-statement> ::= "return" [<expression>]";"
Definition at line 883 of file Analyzer.cpp.
References Semantic::current_function, current_token, expression(), Semantic::exprs, LexicalAnalyzer::get_token(), Semantic::is_convertible(), Poliz::NORET, prog, Poliz::put_lex(), Poliz::RET, semantic, type(), Semantic::type_to_string(), Token::value, and Void.
Referenced by statement().
|
private |
Definition at line 40 of file Analyzer.cpp.
References current_token, LexicalAnalyzer::get_token(), Token::line, may_be_semicolon(), LexicalAnalyzer::prev_token(), prog, Poliz::put_lex(), Poliz::SEMICOLON, and Token::value.
Referenced by for_statement(), preprocessor(), statement(), and var_definitions().
|
private |
<statement> ::= "{"{<statement>}"}" | <var-definitions> | <expression-statement> | <if-statement> | <goto-statement>| <return-statement> | <while-statement> | <for-statement> | <switch-statement>
Definition at line 1140 of file Analyzer.cpp.
References convert_statement(), Semantic::create_table(), current_token, Semantic::del_table(), exit_statement(), expression(), Semantic::exprs, for_statement(), LexicalAnalyzer::get_token(), goto_statement(), LexicalAnalyzer::identifier, if_statement(), Token::line, may_be_semicolon(), LexicalAnalyzer::prev_token(), print_statement(), read_statement(), readln_statement(), return_statement(), semantic, semicolon(), LexicalAnalyzer::service, service_types, statement(), switch_statement(), Token::type, Token::value, var_definitions(), and while_statement().
Referenced by for_statement(), function(), if_statement(), statement(), switch_statement(), and while_statement().
|
private |
Definition at line 1263 of file Analyzer.cpp.
References current_token, expression(), Semantic::exprs, LexicalAnalyzer::get_token(), Int, prog, Poliz::put_lex(), semantic, String, Poliz::STRLEN, and Token::value.
Referenced by field().
|
private |
<switch-statement> ::= "switch" "("<expression>"){"[<switch-block>]["default" ":"<statement>]"}"
<switch-block> ::= "case" <expression>":"<statement>
Definition at line 1013 of file Analyzer.cpp.
References Poliz::blank(), Semantic::break_ptr, current_token, Type::expr_type, expression(), Semantic::exprs, Poliz::FGO, Poliz::get_size(), LexicalAnalyzer::get_token(), Semantic::is_convertible(), LexicalAnalyzer::literal, Poliz::LITERAL, Semantic::literal_to_type(), Poliz::POINTER, prog, Poliz::put_lex(), semantic, Poliz::STACK_PLUG, statement(), Poliz::SWITCH_CMP, Poliz::SWITCH_POP, Token::type, Semantic::type_to_string(), and Token::value.
Referenced by statement().
|
private |
Definition at line 1310 of file Analyzer.cpp.
References current_token, Semantic::exprs, LexicalAnalyzer::get_token(), Long, prog, Poliz::put_lex(), semantic, Poliz::TIME, and Token::value.
Referenced by field().
|
private |
<type> ::= <const-type> | <default-type>
<const-type> ::= "const" <default-type>
Definition at line 251 of file Analyzer.cpp.
References current_token, default_type(), LexicalAnalyzer::get_token(), and Token::value.
Referenced by readln_statement(), return_statement(), var_definition(), and var_definitions().
|
private |
<unary-expression> ::= <construct-expression>{("+" | "-" | "!" | "~" | "++" | "--") <construct-expression>}
Definition at line 605 of file Analyzer.cpp.
References Bool, construct_expression(), current_token, Semantic::exprs, LexicalAnalyzer::get_token(), prog, Poliz::put_lex(), semantic, String, Semantic::type_to_string(), Poliz::UNARY, Unknown, Token::value, and Void.
Referenced by multiply_expression().
|
private |
<var-definition> ::= <type> (<identifier> | <identifier>"="<expression>)
Definition at line 107 of file Analyzer.cpp.
References Semantic::add_identifier(), Poliz::ADDRESS, Poliz::ASSIGN, current_token, expression(), Semantic::exprs, Semantic::function_params_pref, LexicalAnalyzer::get_token(), LexicalAnalyzer::identifier, Semantic::init_array(), LexicalAnalyzer::integer, Semantic::is_convertible(), Semantic::is_in_function_header, LexicalAnalyzer::is_literal(), Identifier::name, LexicalAnalyzer::prev_token(), prog, Poliz::put_lex(), semantic, Semantic::string_to_type(), type(), Token::type, Identifier::type, Semantic::type_to_string(), Token::value, Identifier::value, and Semantic::was_function_assign.
Referenced by parameter_list().
|
private |
<var-definitions> ::= <type> (<identifier> | <identifier>"="<expression>){"," <identifier> | <identifier>"="<expression>}";"
Definition at line 164 of file Analyzer.cpp.
References Semantic::add_identifier(), Poliz::ADDRESS, Poliz::ASSIGN, current_token, expression(), Semantic::exprs, LexicalAnalyzer::get_token(), LexicalAnalyzer::identifier, Semantic::init_array(), LexicalAnalyzer::integer, Semantic::is_convertible(), LexicalAnalyzer::is_literal(), may_be_semicolon(), Identifier::name, LexicalAnalyzer::prev_token(), prog, Poliz::put_lex(), semantic, semicolon(), Semantic::string_to_type(), type(), Token::type, Identifier::type, Semantic::type_to_string(), Token::value, and Identifier::value.
Referenced by for_statement(), function_or_var_definitions(), and statement().
|
private |
<while-statement> ::= "while" "("<expression>")" (<statement> | ";")
Definition at line 901 of file Analyzer.cpp.
References Poliz::blank(), Bool, Semantic::break_ptr, Semantic::continue_ptr, current_token, expression(), Semantic::exprs, Poliz::FGO, Poliz::get_size(), LexicalAnalyzer::get_token(), Poliz::GO, Poliz::POINTER, prog, Poliz::put_lex(), semantic, statement(), Semantic::type_to_string(), and Token::value.
Referenced by statement().
|
private |
Definition at line 31 of file Analyzer.h.
Referenced by assignment_expression(), bitwise_and_expression(), bitwise_consequence_expression(), bitwise_or_expression(), bitwise_shift_expression(), bitwise_xor_expression(), comparison_expression(), construct_expression(), convert_statement(), default_type(), equality_expression(), execute(), exit_statement(), expression(), field(), for_statement(), function(), function_or_var_definitions(), goto_statement(), if_statement(), logical_and_expression(), logical_or_expression(), may_be_semicolon(), multiply_expression(), namespace_definition(), parameter_list(), plus_expression(), preprocessor(), print_statement(), program(), program_body(), rand_statement(), read_statement(), readln_statement(), return_statement(), semicolon(), statement(), strlen_statement(), switch_statement(), time_statement(), type(), unary_expression(), var_definition(), var_definitions(), and while_statement().
|
private |
Definition at line 32 of file Analyzer.h.
Referenced by Analyzer(), assignment_expression(), bitwise_and_expression(), bitwise_consequence_expression(), bitwise_or_expression(), bitwise_shift_expression(), bitwise_xor_expression(), comparison_expression(), construct_expression(), convert_statement(), equality_expression(), execute(), exit_statement(), expression(), field(), for_statement(), function(), goto_statement(), if_statement(), logical_and_expression(), logical_or_expression(), may_be_semicolon(), multiply_expression(), namespace_definition(), parameter_list(), plus_expression(), rand_statement(), read_statement(), readln_statement(), return_statement(), semicolon(), strlen_statement(), switch_statement(), time_statement(), unary_expression(), var_definition(), var_definitions(), and while_statement().
|
private |
Definition at line 33 of file Analyzer.h.
Referenced by Analyzer(), assignment_expression(), bitwise_and_expression(), bitwise_consequence_expression(), bitwise_or_expression(), bitwise_shift_expression(), bitwise_xor_expression(), comparison_expression(), construct_expression(), convert_statement(), equality_expression(), execute(), expression(), field(), for_statement(), function(), goto_statement(), if_statement(), logical_and_expression(), logical_or_expression(), multiply_expression(), parameter_list(), plus_expression(), print_statement(), rand_statement(), read_statement(), readln_statement(), return_statement(), statement(), strlen_statement(), switch_statement(), time_statement(), unary_expression(), var_definition(), var_definitions(), and while_statement().
|
private |
All built-in language types.
Definition at line 35 of file Analyzer.h.
Referenced by default_type(), for_statement(), and statement().