Handle array variable declaration
This commit is contained in:
@ -91,6 +91,10 @@ namespace source
|
||||
{
|
||||
}
|
||||
|
||||
void empty_visitor::visit(array_type_expression *)
|
||||
{
|
||||
}
|
||||
|
||||
void empty_visitor::visit(variable_expression *)
|
||||
{
|
||||
}
|
||||
@ -115,7 +119,7 @@ namespace source
|
||||
{
|
||||
}
|
||||
|
||||
operand::~operand() noexcept
|
||||
operand::~operand()
|
||||
{
|
||||
}
|
||||
|
||||
@ -124,7 +128,7 @@ namespace source
|
||||
{
|
||||
}
|
||||
|
||||
std::int32_t integer_operand::value() const noexcept
|
||||
std::int32_t integer_operand::value() const
|
||||
{
|
||||
return m_value;
|
||||
}
|
||||
@ -134,7 +138,7 @@ namespace source
|
||||
{
|
||||
}
|
||||
|
||||
const std::string& variable_operand::name() const noexcept
|
||||
const std::string& variable_operand::name() const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
@ -144,7 +148,7 @@ namespace source
|
||||
{
|
||||
}
|
||||
|
||||
std::size_t temporary_variable::counter() const noexcept
|
||||
std::size_t temporary_variable::counter() const
|
||||
{
|
||||
return m_counter;
|
||||
}
|
||||
@ -154,7 +158,7 @@ namespace source
|
||||
{
|
||||
}
|
||||
|
||||
std::size_t label_operand::counter() const noexcept
|
||||
std::size_t label_operand::counter() const
|
||||
{
|
||||
return m_counter;
|
||||
}
|
||||
@ -164,7 +168,7 @@ namespace source
|
||||
{
|
||||
}
|
||||
|
||||
const struct position& node::position() const noexcept
|
||||
const struct position& node::position() const
|
||||
{
|
||||
return this->source_position;
|
||||
}
|
||||
@ -189,9 +193,14 @@ namespace source
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
array_type_expression *type_expression::is_array()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
basic_type_expression::basic_type_expression(
|
||||
const struct position position, const std::string& name)
|
||||
: type_expression(position), m_base(name)
|
||||
: type_expression(position), m_name(name)
|
||||
{
|
||||
}
|
||||
|
||||
@ -200,9 +209,9 @@ namespace source
|
||||
visitor->visit(this);
|
||||
}
|
||||
|
||||
const std::string& basic_type_expression::base() const noexcept
|
||||
const std::string& basic_type_expression::base_name()
|
||||
{
|
||||
return m_base;
|
||||
return m_name;
|
||||
}
|
||||
|
||||
basic_type_expression *basic_type_expression::is_basic()
|
||||
@ -210,6 +219,37 @@ namespace source
|
||||
return this;
|
||||
}
|
||||
|
||||
array_type_expression::array_type_expression(const struct position position, type_expression *base,
|
||||
const std::uint32_t size)
|
||||
: type_expression(position), m_base(base), size(size)
|
||||
{
|
||||
}
|
||||
|
||||
void array_type_expression::accept(parser_visitor *visitor)
|
||||
{
|
||||
visitor->visit(this);
|
||||
}
|
||||
|
||||
type_expression& array_type_expression::base()
|
||||
{
|
||||
return *m_base;
|
||||
}
|
||||
|
||||
const std::string& array_type_expression::base_name()
|
||||
{
|
||||
return base().base_name();
|
||||
}
|
||||
|
||||
array_type_expression *array_type_expression::is_array()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
array_type_expression::~array_type_expression()
|
||||
{
|
||||
delete m_base;
|
||||
}
|
||||
|
||||
declaration::declaration(const struct position position, const std::string& identifier,
|
||||
type_expression *type)
|
||||
: definition(position, identifier), m_type(type)
|
||||
@ -226,7 +266,7 @@ namespace source
|
||||
visitor->visit(this);
|
||||
}
|
||||
|
||||
type_expression& declaration::type() noexcept
|
||||
type_expression& declaration::type()
|
||||
{
|
||||
return *m_type;
|
||||
}
|
||||
@ -236,7 +276,7 @@ namespace source
|
||||
{
|
||||
}
|
||||
|
||||
std::string& definition::identifier() noexcept
|
||||
std::string& definition::identifier()
|
||||
{
|
||||
return m_identifier;
|
||||
}
|
||||
@ -278,7 +318,7 @@ namespace source
|
||||
return *m_body;
|
||||
}
|
||||
|
||||
std::vector<declaration *>& procedure_definition::parameters() noexcept
|
||||
std::vector<declaration *>& procedure_definition::parameters()
|
||||
{
|
||||
return m_parameters;
|
||||
}
|
||||
@ -310,12 +350,12 @@ namespace source
|
||||
return *m_body;
|
||||
}
|
||||
|
||||
std::vector<definition *>& block::definitions() noexcept
|
||||
std::vector<definition *>& block::definitions()
|
||||
{
|
||||
return m_definitions;
|
||||
}
|
||||
|
||||
std::vector<declaration *>& block::declarations() noexcept
|
||||
std::vector<declaration *>& block::declarations()
|
||||
{
|
||||
return m_declarations;
|
||||
}
|
||||
@ -355,7 +395,7 @@ namespace source
|
||||
visitor->visit(this);
|
||||
}
|
||||
|
||||
unsigned char char_literal::character() const noexcept
|
||||
unsigned char char_literal::character() const
|
||||
{
|
||||
return m_character;
|
||||
}
|
||||
@ -370,7 +410,7 @@ namespace source
|
||||
visitor->visit(this);
|
||||
}
|
||||
|
||||
const std::string& string_literal::string() const noexcept
|
||||
const std::string& string_literal::string() const
|
||||
{
|
||||
return m_string;
|
||||
}
|
||||
@ -385,7 +425,7 @@ namespace source
|
||||
visitor->visit(this);
|
||||
}
|
||||
|
||||
const std::string& variable_expression::name() const noexcept
|
||||
const std::string& variable_expression::name() const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
@ -446,7 +486,7 @@ namespace source
|
||||
return *m_rhs;
|
||||
}
|
||||
|
||||
binary_operator binary_expression::operation() const noexcept
|
||||
binary_operator binary_expression::operation() const
|
||||
{
|
||||
return m_operator;
|
||||
}
|
||||
@ -484,7 +524,7 @@ namespace source
|
||||
return *m_operand;
|
||||
}
|
||||
|
||||
unary_operator unary_expression::operation() const noexcept
|
||||
unary_operator unary_expression::operation() const
|
||||
{
|
||||
return this->m_operator;
|
||||
}
|
||||
@ -504,12 +544,12 @@ namespace source
|
||||
visitor->visit(this);
|
||||
}
|
||||
|
||||
std::string& call_statement::name() noexcept
|
||||
std::string& call_statement::name()
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
std::vector<expression *>& call_statement::arguments() noexcept
|
||||
std::vector<expression *>& call_statement::arguments()
|
||||
{
|
||||
return m_arguments;
|
||||
}
|
||||
@ -556,7 +596,7 @@ namespace source
|
||||
{
|
||||
}
|
||||
|
||||
std::string& assign_statement::lvalue() noexcept
|
||||
std::string& assign_statement::lvalue()
|
||||
{
|
||||
return m_lvalue;
|
||||
}
|
||||
|
@ -61,6 +61,12 @@ const {
|
||||
var {
|
||||
return yy::parser::make_VAR(this->location);
|
||||
}
|
||||
array {
|
||||
return yy::parser::make_ARRAY(this->location);
|
||||
}
|
||||
of {
|
||||
return yy::parser::make_OF(this->location);
|
||||
}
|
||||
true {
|
||||
return yy::parser::make_BOOLEAN(true, this->location);
|
||||
}
|
||||
|
@ -63,7 +63,7 @@
|
||||
%token <std::string> STRING "string"
|
||||
%token <bool> BOOLEAN
|
||||
%token IF WHILE DO
|
||||
%token CONST VAR PROCEDURE
|
||||
%token CONST VAR PROCEDURE ARRAY OF
|
||||
%token BEGIN_BLOCK END_BLOCK
|
||||
%token LEFT_PAREN RIGHT_PAREN LEFT_SQUARE RIGHT_SQUARE SEMICOLON DOT COMMA
|
||||
%token GREATER_EQUAL LESS_EQUAL LESS_THAN GREATER_THAN NOT_EQUAL EQUALS
|
||||
@ -83,7 +83,7 @@
|
||||
%type <elna::source::declaration *> variable_declaration;
|
||||
%type <std::vector<elna::source::declaration *>> variable_declarations variable_declaration_part
|
||||
formal_parameter_list;
|
||||
%type <elna::source::basic_type_expression *> type_expression;
|
||||
%type <elna::source::type_expression *> type_expression;
|
||||
%type <elna::source::expression *> expression pointer summand factor address comparand;
|
||||
%type <std::vector<elna::source::expression *>> expressions actual_parameter_list;
|
||||
%type <elna::source::variable_expression *> variable_expression;
|
||||
@ -299,7 +299,11 @@ optional_statements:
|
||||
statements { std::swap($$, $1); }
|
||||
| /* no statements */ {}
|
||||
type_expression:
|
||||
IDENTIFIER
|
||||
ARRAY INTEGER OF type_expression
|
||||
{
|
||||
$$ = new elna::source::array_type_expression(elna::source::make_position(@1), $4, $2);
|
||||
}
|
||||
| IDENTIFIER
|
||||
{
|
||||
$$ = new elna::source::basic_type_expression(elna::source::make_position(@1), $1);
|
||||
}
|
||||
|
Reference in New Issue
Block a user