Don't append return to void procedures

This commit is contained in:
2025-01-13 11:55:19 +01:00
parent b45b00a3f6
commit 3bd4c3af6f
7 changed files with 138 additions and 46 deletions

View File

@ -672,6 +672,12 @@ namespace source
case 'g':
this->m_operator = binary_operator::greater_equal;
break;
case 'o':
this->m_operator = binary_operator::disjunction;
break;
case 'a':
this->m_operator = binary_operator::conjunction;
break;
default:
__builtin_unreachable();
}
@ -712,6 +718,9 @@ namespace source
case '@':
this->m_operator = unary_operator::reference;
break;
case '!':
this->m_operator = unary_operator::negation;
break;
default:
__builtin_unreachable();
}
@ -923,6 +932,10 @@ namespace source
return ">";
case binary_operator::greater_equal:
return ">=";
case binary_operator::conjunction:
return "and";
case binary_operator::disjunction:
return "or";
}
__builtin_unreachable();
};

View File

@ -79,6 +79,15 @@ true {
false {
return yy::parser::make_BOOLEAN(false, this->location);
}
and {
return yy::parser::make_AND(this->location);
}
or {
return yy::parser::make_OR(this->location);
}
not {
return yy::parser::make_NOT(this->location);
}
[A-Za-z_][A-Za-z0-9_]* {
return yy::parser::make_IDENTIFIER(yytext, this->location);
}

View File

@ -66,6 +66,7 @@
%token CONST VAR PROCEDURE ARRAY OF TYPE RECORD
%token BEGIN_BLOCK END_BLOCK
%token LEFT_PAREN RIGHT_PAREN LEFT_SQUARE RIGHT_SQUARE SEMICOLON DOT COMMA
%token AND OR NOT
%token GREATER_EQUAL LESS_EQUAL LESS_THAN GREATER_THAN NOT_EQUAL EQUALS
%token PLUS MINUS MULTIPLICATION DIVISION
%token ASSIGNMENT COLON HAT AT
@ -84,7 +85,7 @@
%type <std::vector<elna::source::variable_declaration *>> variable_declarations variable_part
formal_parameter_list;
%type <elna::source::type_expression *> type_expression;
%type <elna::source::expression *> expression pointer summand factor comparand;
%type <elna::source::expression *> expression pointer summand factor comparand logical_operand;
%type <std::vector<elna::source::expression *>> expressions actual_parameter_list;
%type <elna::source::designator_expression *> designator_expression;
%type <elna::source::compound_statement *> compound_statement;
@ -239,6 +240,10 @@ factor:
{
$$ = new elna::source::unary_expression(elna::source::make_position(@1), $2, '@');
}
| NOT pointer
{
$$ = new elna::source::unary_expression(elna::source::make_position(@1), $2, '!');
}
| pointer { $$ = $1; }
comparand:
summand PLUS summand
@ -250,7 +255,7 @@ comparand:
$$ = new elna::source::binary_expression(elna::source::make_position(@1), $1, $3, '-');
}
| summand { $$ = std::move($1); }
expression:
logical_operand:
comparand EQUALS comparand
{
$$ = new elna::source::binary_expression(elna::source::make_position(@1), $1, $3, '=');
@ -265,20 +270,27 @@ expression:
}
| comparand GREATER_THAN comparand
{
$$ = new elna::source::binary_expression(elna::source::make_position(@1),
$1, $3, '>');
$$ = new elna::source::binary_expression(elna::source::make_position(@1), $1, $3, '>');
}
| comparand LESS_EQUAL comparand
{
$$ = new elna::source::binary_expression(elna::source::make_position(@1),
$1, $3, '<');
$$ = new elna::source::binary_expression(elna::source::make_position(@1), $1, $3, '<');
}
| comparand GREATER_EQUAL comparand
{
$$ = new elna::source::binary_expression(elna::source::make_position(@1),
$1, $3, '>');
$$ = new elna::source::binary_expression(elna::source::make_position(@1), $1, $3, '>');
}
| comparand { $$ = std::move($1); }
| comparand { $$ = $1; }
expression:
logical_operand AND logical_operand
{
$$ = new elna::source::binary_expression(elna::source::make_position(@1), $1, $3, 'a');
}
| logical_operand OR logical_operand
{
$$ = new elna::source::binary_expression(elna::source::make_position(@1), $1, $3, 'o');
}
| logical_operand { $$ = $1; }
expressions:
expression COMMA expressions
{