Allow assigning nil to any pointer
This commit is contained in:
parent
aab16e4941
commit
8abeff0095
82
README.md
82
README.md
@ -19,83 +19,5 @@ and a possbility to compile Elna programs for different platforms.
|
||||
|
||||
## Grammar
|
||||
|
||||
```ebnf
|
||||
digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
|
||||
letter = "A" | "B" | … | "Z" | "a" | "b" | … | "z";
|
||||
|
||||
ident = letter { letter | digit | "_" };
|
||||
integer = digit { digit };
|
||||
float = integer "." integer;
|
||||
boolean = "true" | "false";
|
||||
|
||||
literal = integer | float | boolean | "'" character "'" | """ { character } """;
|
||||
|
||||
program = [ "type" type_definitions ";" ]
|
||||
[ constant_part ]
|
||||
{ procedure_definition }
|
||||
[ variable_part ]
|
||||
"begin" [ statement_list ] "end" ".";
|
||||
|
||||
procedure_definition = "proc" ident formal_parameter_list ";" ( block | "extern" ) ";";
|
||||
|
||||
block = [ constant_part ]
|
||||
[ variable_part ]
|
||||
statement;
|
||||
|
||||
constant_part = "const" ident "=" integer { "," ident "=" integer } ";";
|
||||
variable_part = "var" variable_declarations ";";
|
||||
|
||||
statement = ident ":=" expression
|
||||
| ident actual_parameter_list
|
||||
| while_do
|
||||
| if_then_else;
|
||||
|
||||
|
||||
while_do = "while" condition "do" [ statement_list ] "end";
|
||||
if_then_else = "if" expression
|
||||
"then" [ statement_list ]
|
||||
[ else statement_list ] "end";
|
||||
|
||||
statement_list = statement {";" statement };
|
||||
|
||||
condition = "odd" expression |
|
||||
expression ("="|"#"|"<"|"<="|">"|">=") expression;
|
||||
|
||||
comparison_operator = "=", "<>", "<", ">", "<=", ">=";
|
||||
unary_prefix = "not", "@";
|
||||
|
||||
expression = logical_operand { ("and" | "or") logical_operand };
|
||||
logical_operand = comparand { comparison_operator comparand };
|
||||
comparand = summand { ("+" | "-") summand };
|
||||
summand = factor { ("*" | "/") factor };
|
||||
factor = pointer { unary_prefix pointer };
|
||||
|
||||
pointer = literal
|
||||
| designator_expression { $$ = $1; }
|
||||
| "(" expression ")";
|
||||
|
||||
designator_expression = designator_expression "[" expression "]"
|
||||
| designator_expression "." ident
|
||||
| designator_expression "^"
|
||||
| ident;
|
||||
|
||||
formal_parameter_list = "(" [ variable_declarations ] ")";
|
||||
|
||||
actual_parameter_list = "(" [ expressions ] ")";
|
||||
|
||||
expressions = expression { "," expression };
|
||||
|
||||
variable_declarations = variable_declaration { ";" variable_declaration };
|
||||
|
||||
variable_declaration = ident ":" type_expression;
|
||||
|
||||
type_expression = "array" integer "of" type_expression
|
||||
| "pointer" "to" type_expression
|
||||
| "record" field_list "end"
|
||||
| "union" field_list "end"
|
||||
| ident;
|
||||
|
||||
field_list = field_declaration { ";" field_declaration };
|
||||
|
||||
field_declaration = ident ":" type_expression;
|
||||
```
|
||||
Flex and bison grammar specifications, `lexer.ll` and `parser.yy`, can be found
|
||||
in the `boot/` directory.
|
||||
|
@ -699,20 +699,23 @@ namespace gcc
|
||||
this->current_expression = error_mark_node;
|
||||
return;
|
||||
}
|
||||
if (TREE_TYPE(this->current_expression) != TREE_TYPE(lvalue))
|
||||
if (TREE_TYPE(this->current_expression) == TREE_TYPE(lvalue)
|
||||
|| (is_pointer_type(TREE_TYPE(lvalue)) && this->current_expression == null_pointer_node))
|
||||
{
|
||||
tree assignment = build2_loc(statement_location, MODIFY_EXPR,
|
||||
void_type_node, lvalue, this->current_expression);
|
||||
|
||||
append_to_statement_list(assignment, &this->current_statements);
|
||||
this->current_expression = NULL_TREE;
|
||||
}
|
||||
else
|
||||
{
|
||||
error_at(statement_location,
|
||||
"cannot assign value of type %s to variable of type %s",
|
||||
print_type(TREE_TYPE(this->current_expression)),
|
||||
print_type(TREE_TYPE(lvalue)));
|
||||
this->current_expression = error_mark_node;
|
||||
return;
|
||||
}
|
||||
auto assignment = build2_loc(statement_location, MODIFY_EXPR,
|
||||
void_type_node, lvalue, this->current_expression);
|
||||
|
||||
append_to_statement_list(assignment, &this->current_statements);
|
||||
this->current_expression = NULL_TREE;
|
||||
}
|
||||
|
||||
void generic_visitor::visit(boot::if_statement *statement)
|
||||
|
Loading…
x
Reference in New Issue
Block a user