AALanguage
The best language for those who have nothing to do
Loading...
Searching...
No Matches
Analyzer Class Reference

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>

Collaboration diagram for Analyzer:

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 Member Functions

void program (LexicalAnalyzer &lex)
 
void preprocessor (LexicalAnalyzer &lex)
 
void namespace_definition (LexicalAnalyzer &lex)
 
void program_body (LexicalAnalyzer &lex)
 
void var_definition (LexicalAnalyzer &lex)
 
void var_definitions (LexicalAnalyzer &lex, bool need_semicolon=true, bool is_program=false)
 
void type (LexicalAnalyzer &lex)
 
void default_type (LexicalAnalyzer &lex)
 
void function_or_var_definitions (LexicalAnalyzer &lex, bool is_program=false)
 
void function (LexicalAnalyzer &lex, bool is_struct=false)
 
void expression (LexicalAnalyzer &lex, bool is_vars=false, bool is_print=false)
 
void parameter_list (LexicalAnalyzer &lex)
 
void statement (LexicalAnalyzer &lex, bool prev_table=false)
 
void semicolon (LexicalAnalyzer &lex, bool is_important=false)
 
void may_be_semicolon (LexicalAnalyzer &lex)
 
void assignment_expression (LexicalAnalyzer &lex)
 
void logical_or_expression (LexicalAnalyzer &lex)
 
void logical_and_expression (LexicalAnalyzer &lex)
 
void bitwise_or_expression (LexicalAnalyzer &lex)
 
void bitwise_xor_expression (LexicalAnalyzer &lex)
 
void bitwise_consequence_expression (LexicalAnalyzer &lex)
 
void bitwise_and_expression (LexicalAnalyzer &lex)
 
void equality_expression (LexicalAnalyzer &lex)
 
void comparison_expression (LexicalAnalyzer &lex)
 
void bitwise_shift_expression (LexicalAnalyzer &lex)
 
void plus_expression (LexicalAnalyzer &lex)
 
void multiply_expression (LexicalAnalyzer &lex)
 
void unary_expression (LexicalAnalyzer &lex)
 
void construct_expression (LexicalAnalyzer &lex)
 
void field (LexicalAnalyzer &lex, bool only_array=false)
 
void if_statement (LexicalAnalyzer &lex)
 
void goto_statement (LexicalAnalyzer &lex)
 
void return_statement (LexicalAnalyzer &lex)
 
void while_statement (LexicalAnalyzer &lex)
 
void for_statement (LexicalAnalyzer &lex)
 
void switch_statement (LexicalAnalyzer &lex)
 
void read_statement (LexicalAnalyzer &lex)
 
void readln_statement (LexicalAnalyzer &lex)
 
void print_statement (LexicalAnalyzer &lex)
 
void exit_statement (LexicalAnalyzer &lex)
 
void convert_statement (LexicalAnalyzer &lex)
 
void rand_statement (LexicalAnalyzer &lex)
 
void strlen_statement (LexicalAnalyzer &lex)
 
void time_statement (LexicalAnalyzer &lex)
 

Private Attributes

Token current_token
 
Poliz prog
 
Semantic semantic
 
std::vector< std::string > service_types
 All built-in language types.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ Analyzer()

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.

Member Function Documentation

◆ assignment_expression()

void Analyzer::assignment_expression ( LexicalAnalyzer & lex)
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().

◆ bitwise_and_expression()

void Analyzer::bitwise_and_expression ( LexicalAnalyzer & lex)
private

◆ bitwise_consequence_expression()

void Analyzer::bitwise_consequence_expression ( LexicalAnalyzer & lex)
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().

◆ bitwise_or_expression()

void Analyzer::bitwise_or_expression ( LexicalAnalyzer & lex)
private

◆ bitwise_shift_expression()

void Analyzer::bitwise_shift_expression ( LexicalAnalyzer & lex)
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().

◆ bitwise_xor_expression()

void Analyzer::bitwise_xor_expression ( LexicalAnalyzer & lex)
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().

◆ comparison_expression()

void Analyzer::comparison_expression ( LexicalAnalyzer & lex)
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().

◆ construct_expression()

void Analyzer::construct_expression ( LexicalAnalyzer & lex)
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().

◆ convert_statement()

void Analyzer::convert_statement ( LexicalAnalyzer & lex)
private

◆ default_type()

void Analyzer::default_type ( LexicalAnalyzer & lex)
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().

◆ equality_expression()

void Analyzer::equality_expression ( LexicalAnalyzer & lex)
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().

◆ execute()

void Analyzer::execute ( std::string path,
std::string lib_path )

A function that starts full analysis and generation of a file with specified parameters.

Parameters
pathPath to the AALanguage program
lib_pathPath 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().

◆ exit_statement()

void Analyzer::exit_statement ( LexicalAnalyzer & lex)
private

◆ expression()

void Analyzer::expression ( LexicalAnalyzer & lex,
bool is_vars = false,
bool is_print = false )
private

◆ field()

◆ for_statement()

◆ function()

◆ function_or_var_definitions()

void Analyzer::function_or_var_definitions ( LexicalAnalyzer & lex,
bool is_program = false )
private

◆ goto_statement()

void Analyzer::goto_statement ( LexicalAnalyzer & lex)
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().

◆ if_statement()

void Analyzer::if_statement ( LexicalAnalyzer & lex)
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().

◆ logical_and_expression()

void Analyzer::logical_and_expression ( LexicalAnalyzer & lex)
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().

◆ logical_or_expression()

void Analyzer::logical_or_expression ( LexicalAnalyzer & lex)
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().

◆ may_be_semicolon()

void Analyzer::may_be_semicolon ( LexicalAnalyzer & lex)
private

◆ multiply_expression()

void Analyzer::multiply_expression ( LexicalAnalyzer & lex)
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().

◆ namespace_definition()

void Analyzer::namespace_definition ( LexicalAnalyzer & lex)
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().

◆ parameter_list()

void Analyzer::parameter_list ( LexicalAnalyzer & lex)
private

◆ plus_expression()

void Analyzer::plus_expression ( LexicalAnalyzer & lex)
private

◆ preprocessor()

void Analyzer::preprocessor ( LexicalAnalyzer & lex)
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().

◆ print_statement()

void Analyzer::print_statement ( LexicalAnalyzer & lex)
private

◆ program()

void Analyzer::program ( LexicalAnalyzer & lex)
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().

◆ program_body()

void Analyzer::program_body ( LexicalAnalyzer & lex)
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().

◆ rand_statement()

void Analyzer::rand_statement ( LexicalAnalyzer & lex)
private

◆ read_statement()

void Analyzer::read_statement ( LexicalAnalyzer & lex)
private

◆ readln_statement()

void Analyzer::readln_statement ( LexicalAnalyzer & lex)
private

◆ return_statement()

void Analyzer::return_statement ( LexicalAnalyzer & lex)
private

◆ semicolon()

void Analyzer::semicolon ( LexicalAnalyzer & lex,
bool is_important = false )
private

◆ statement()

◆ strlen_statement()

void Analyzer::strlen_statement ( LexicalAnalyzer & lex)
private

◆ switch_statement()

void Analyzer::switch_statement ( LexicalAnalyzer & lex)
private

◆ time_statement()

void Analyzer::time_statement ( LexicalAnalyzer & lex)
private

◆ type()

void Analyzer::type ( LexicalAnalyzer & lex)
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().

◆ unary_expression()

void Analyzer::unary_expression ( LexicalAnalyzer & lex)
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().

◆ var_definition()

◆ var_definitions()

◆ while_statement()

void Analyzer::while_statement ( LexicalAnalyzer & lex)
private

Member Data Documentation

◆ current_token

◆ prog

◆ semantic

◆ service_types

std::vector<std::string> Analyzer::service_types
private
Initial value:
= { "bool", "char", "byte", "double", "udouble", "float", "ufloat", "int", "uint", "long",
"ulong", "short", "ushort", "string", "large" }

All built-in language types.

Definition at line 35 of file Analyzer.h.

Referenced by default_type(), for_statement(), and statement().


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