Make type_expression abstract
This commit is contained in:
@ -87,7 +87,7 @@ namespace source
|
||||
expression->operand().accept(this);
|
||||
}
|
||||
|
||||
void empty_visitor::visit(type_expression *)
|
||||
void empty_visitor::visit(basic_type_expression *)
|
||||
{
|
||||
}
|
||||
|
||||
@ -179,24 +179,35 @@ namespace source
|
||||
{
|
||||
}
|
||||
|
||||
type_expression::type_expression(const struct position position, const std::string& name, const bool is_pointer)
|
||||
: node(position), m_base(name), m_pointer(is_pointer)
|
||||
type_expression::type_expression(const struct position position)
|
||||
: node(position)
|
||||
{
|
||||
}
|
||||
|
||||
void type_expression::accept(parser_visitor *visitor)
|
||||
basic_type_expression *type_expression::is_basic()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
basic_type_expression::basic_type_expression(
|
||||
const struct position position, const std::string& name)
|
||||
: type_expression(position), m_base(name)
|
||||
{
|
||||
}
|
||||
|
||||
void basic_type_expression::accept(parser_visitor *visitor)
|
||||
{
|
||||
visitor->visit(this);
|
||||
}
|
||||
|
||||
const std::string& type_expression::base() const noexcept
|
||||
const std::string& basic_type_expression::base() const noexcept
|
||||
{
|
||||
return m_base;
|
||||
}
|
||||
|
||||
bool type_expression::is_pointer() const noexcept
|
||||
basic_type_expression *basic_type_expression::is_basic()
|
||||
{
|
||||
return m_pointer;
|
||||
return this;
|
||||
}
|
||||
|
||||
declaration::declaration(const struct position position, const std::string& identifier,
|
||||
|
@ -90,6 +90,12 @@ false {
|
||||
\) {
|
||||
return yy::parser::make_RIGHT_PAREN(this->location);
|
||||
}
|
||||
\[ {
|
||||
return yy::parser::make_LEFT_SQUARE(this->location);
|
||||
}
|
||||
\] {
|
||||
return yy::parser::make_RIGHT_SQUARE(this->location);
|
||||
}
|
||||
\>= {
|
||||
return yy::parser::make_GREATER_EQUAL(this->location);
|
||||
}
|
||||
|
@ -65,7 +65,7 @@
|
||||
%token IF WHILE DO
|
||||
%token CONST VAR PROCEDURE
|
||||
%token BEGIN_BLOCK END_BLOCK
|
||||
%token LEFT_PAREN RIGHT_PAREN SEMICOLON DOT COMMA
|
||||
%token LEFT_PAREN RIGHT_PAREN LEFT_SQUARE RIGHT_SQUARE SEMICOLON DOT COMMA
|
||||
%token GREATER_EQUAL LESS_EQUAL LESS_THAN GREATER_THAN NOT_EQUAL EQUALS
|
||||
%token PLUS MINUS MULTIPLICATION DIVISION
|
||||
%token ASSIGNMENT COLON HAT AT
|
||||
@ -83,7 +83,7 @@
|
||||
%type <std::unique_ptr<elna::source::declaration>> variable_declaration;
|
||||
%type <std::vector<std::unique_ptr<elna::source::declaration>>> variable_declarations variable_declaration_part
|
||||
formal_parameter_list;
|
||||
%type <std::unique_ptr<elna::source::type_expression>> type_expression;
|
||||
%type <std::unique_ptr<elna::source::basic_type_expression>> type_expression;
|
||||
%type <std::unique_ptr<elna::source::expression>> expression pointer summand factor address comparand;
|
||||
%type <std::vector<std::unique_ptr<elna::source::expression>>> expressions actual_parameter_list;
|
||||
%type <std::unique_ptr<elna::source::variable_expression>> variable_expression;
|
||||
@ -299,13 +299,9 @@ optional_statements:
|
||||
statements { std::swap($$, $1); }
|
||||
| /* no statements */ {}
|
||||
type_expression:
|
||||
HAT IDENTIFIER
|
||||
IDENTIFIER
|
||||
{
|
||||
$$ = std::make_unique<elna::source::type_expression>(elna::source::make_position(@1), $2, true);
|
||||
}
|
||||
| IDENTIFIER
|
||||
{
|
||||
$$ = std::make_unique<elna::source::type_expression>(elna::source::make_position(@1), $1, false);
|
||||
$$ = std::make_unique<elna::source::basic_type_expression>(elna::source::make_position(@1), $1);
|
||||
}
|
||||
variable_declaration: IDENTIFIER COLON type_expression
|
||||
{
|
||||
|
Reference in New Issue
Block a user