elna/README.md

102 lines
3.0 KiB
Markdown
Raw Permalink Normal View History

2024-12-21 14:05:27 +01:00
# Elna programming language
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
## 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
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-14 23:15:27 +01:00
ident = letter { letter | digit | "_" };
integer = digit { digit };
2025-01-14 23:15:27 +01:00
float = integer "." integer;
boolean = "true" | "false";
2025-01-15 01:48:09 +01:00
literal = integer | float | boolean | "'" character "'" | """ { character } """;
program = [ "type" type_definitions ";" ]
2025-01-14 23:15:27 +01:00
[ constant_part ]
{ procedure_definition }
2025-01-14 23:15:27 +01:00
[ variable_part ]
"begin" [ statement_list ] "end" ".";
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 ]
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
statement = ident ":=" expression
2025-01-14 23:15:27 +01:00
| 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";
2025-01-14 23:15:27 +01:00
statement_list = statement {";" statement };
2024-12-21 14:05:27 +01:00
condition = "odd" expression |
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-14 23:15:27 +01:00
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;
2024-12-21 14:05:27 +01:00
type_expression = "array" integer "of" type_expression
| "pointer" "to" type_expression
| "record" field_list "end"
| "union" field_list "end"
| ident;
2024-12-21 14:05:27 +01:00
field_list = field_declaration { ";" field_declaration };
2024-12-21 14:05:27 +01:00
field_declaration = ident ":" type_expression;
2025-01-14 23:15:27 +01:00
```