elna/README.md

3.0 KiB

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.

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

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;