elna/README

74 lines
2.2 KiB
Plaintext

# 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";
integer = digit { digit };
boolean = "true" | "false";
program = [ "type" type_definitions ";" ]
[ "const" ident "=" integer { "," ident "=" integer } ";"]
{ procedure_definition }
[ "var" variable_declarations ";" ]
compound_statement ".";
procedure_definition = "procedure" ident formal_parameter_list ";" block ";";
block = [ "const" ident "=" integer { "," ident "=" integer } ";" ]
[ "var" variable_declarations ";" ]
statement;
statement = [ ident ":=" expression
| ident actual_parameter_list
| compound_statement
| "if" condition "then" statement
| "while" condition "do" statement ];
compound_statement = "begin" statement {";" statement } "end" ;
condition = "odd" expression |
expression ("="|"#"|"<"|"<="|">"|">=") expression;
expression = [ "+"|"-"] term { ("+"|"-") term};
term = factor { ("*"|"/") factor };
factor = ident | integer | "(" expression ")";
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
| "^" type_expression
| "record" field_list "end"
| ident;
field_list = field_declaration { ";" field_declaration };
field_declaration = ident ":" type_expression;