2024-12-21 14:05:27 +01:00
|
|
|
# Elna programming language
|
|
|
|
|
2025-01-12 10:35:24 +01:00
|
|
|
Elna is a simple, imperative, low-level programming language.
|
|
|
|
|
|
|
|
It is intendet to accompany other languages in the areas, where a high-level
|
|
|
|
language doesn't fit well. It is also supposed to be an intermediate
|
|
|
|
representation for a such high-level hypothetical programming language.
|
2024-12-21 14:05:27 +01:00
|
|
|
|
|
|
|
## File extension
|
|
|
|
|
|
|
|
.elna
|
|
|
|
|
2025-01-12 10:35:24 +01:00
|
|
|
## Current implementation
|
|
|
|
|
|
|
|
This repository contains a GCC frontend for Elna. After finishing the frontend
|
|
|
|
I'm planning to rewrite the compiler in Elna itself with its own backend and
|
|
|
|
a hand-written parser. So GCC gives a way to have a simple bootstrap compiler
|
|
|
|
and a possbility to compile Elna programs for different platforms.
|
|
|
|
|
|
|
|
## Grammar
|
|
|
|
|
2025-01-14 23:15:27 +01:00
|
|
|
```ebnf
|
2025-01-12 10:35:24 +01:00
|
|
|
digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
|
2025-01-14 23:15:27 +01:00
|
|
|
letter = "A" | "B" | … | "Z" | "a" | "b" | … | "z";
|
2025-01-12 10:35:24 +01:00
|
|
|
|
2025-01-14 23:15:27 +01:00
|
|
|
ident = letter { letter | digit | "_" };
|
2025-01-12 10:35:24 +01:00
|
|
|
integer = digit { digit };
|
2025-01-14 23:15:27 +01:00
|
|
|
float = integer "." integer;
|
2025-01-12 10:35:24 +01:00
|
|
|
boolean = "true" | "false";
|
|
|
|
|
2025-01-15 01:48:09 +01:00
|
|
|
literal = integer | float | boolean | "'" character "'" | """ { character } """;
|
|
|
|
|
2025-01-12 10:35:24 +01:00
|
|
|
program = [ "type" type_definitions ";" ]
|
2025-01-14 23:15:27 +01:00
|
|
|
[ constant_part ]
|
2025-01-12 10:35:24 +01:00
|
|
|
{ procedure_definition }
|
2025-01-14 23:15:27 +01:00
|
|
|
[ variable_part ]
|
2025-01-17 10:11:40 +01:00
|
|
|
"begin" [ statement_list ] "end" ".";
|
2025-01-12 10:35:24 +01:00
|
|
|
|
2025-01-16 15:09:58 +01:00
|
|
|
procedure_definition = "proc" ident formal_parameter_list ";" ( block | "extern" ) ";";
|
2024-12-21 14:05:27 +01:00
|
|
|
|
2025-01-14 23:15:27 +01:00
|
|
|
block = [ constant_part ]
|
|
|
|
[ variable_part ]
|
2025-01-12 10:35:24 +01:00
|
|
|
statement;
|
2024-12-21 14:05:27 +01:00
|
|
|
|
2025-01-14 23:15:27 +01:00
|
|
|
constant_part = "const" ident "=" integer { "," ident "=" integer } ";";
|
|
|
|
variable_part = "var" variable_declarations ";";
|
2024-12-21 14:05:27 +01:00
|
|
|
|
2025-01-17 10:11:40 +01:00
|
|
|
statement = ident ":=" expression
|
2025-01-14 23:15:27 +01:00
|
|
|
| ident actual_parameter_list
|
2025-01-17 10:11:40 +01:00
|
|
|
| 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";
|
2025-01-14 23:15:27 +01:00
|
|
|
|
|
|
|
statement_list = statement {";" statement };
|
2024-12-21 14:05:27 +01:00
|
|
|
|
|
|
|
condition = "odd" expression |
|
2025-01-12 10:35:24 +01:00
|
|
|
expression ("="|"#"|"<"|"<="|">"|">=") expression;
|
2024-12-21 14:05:27 +01:00
|
|
|
|
2025-01-14 23:15:27 +01:00
|
|
|
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 };
|
2024-12-21 14:05:27 +01:00
|
|
|
|
2025-01-15 01:48:09 +01:00
|
|
|
pointer = literal
|
2025-01-14 23:15:27 +01:00
|
|
|
| designator_expression { $$ = $1; }
|
|
|
|
| "(" expression ")";
|
2025-01-12 10:35:24 +01:00
|
|
|
|
2025-01-14 23:15:27 +01:00
|
|
|
designator_expression = designator_expression "[" expression "]"
|
|
|
|
| designator_expression "." ident
|
|
|
|
| designator_expression "^"
|
|
|
|
| ident;
|
2025-01-12 10:35:24 +01:00
|
|
|
|
|
|
|
formal_parameter_list = "(" [ variable_declarations ] ")";
|
|
|
|
|
|
|
|
actual_parameter_list = "(" [ expressions ] ")";
|
|
|
|
|
|
|
|
expressions = expression { "," expression };
|
|
|
|
|
|
|
|
variable_declarations = variable_declaration { ";" variable_declaration };
|
|
|
|
|
|
|
|
variable_declaration = ident ":" type_expression;
|
2024-12-21 14:05:27 +01:00
|
|
|
|
2025-01-12 10:35:24 +01:00
|
|
|
type_expression = "array" integer "of" type_expression
|
2025-01-17 10:11:40 +01:00
|
|
|
| "pointer" "to" type_expression
|
2025-01-12 10:35:24 +01:00
|
|
|
| "record" field_list "end"
|
2025-01-17 10:11:40 +01:00
|
|
|
| "union" field_list "end"
|
2025-01-12 10:35:24 +01:00
|
|
|
| ident;
|
2024-12-21 14:05:27 +01:00
|
|
|
|
2025-01-12 10:35:24 +01:00
|
|
|
field_list = field_declaration { ";" field_declaration };
|
2024-12-21 14:05:27 +01:00
|
|
|
|
2025-01-12 10:35:24 +01:00
|
|
|
field_declaration = ident ":" type_expression;
|
2025-01-14 23:15:27 +01:00
|
|
|
```
|