Move type definitions to the program node
This commit is contained in:
74
README
74
README
@ -1,37 +1,73 @@
|
||||
# Elna programming language
|
||||
|
||||
Elna compiles simple mathematical operations to machine code.
|
||||
The compiled program returns the result of the operation.
|
||||
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
|
||||
|
||||
## Grammar PL/0
|
||||
## Current implementation
|
||||
|
||||
program = block "." ;
|
||||
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.
|
||||
|
||||
block = [ "const" ident "=" number {"," ident "=" number} ";"]
|
||||
[ "var" ident {"," ident} ";"]
|
||||
{ "procedure" ident ";" block ";" } statement ;
|
||||
## Grammar
|
||||
|
||||
statement = [ ident ":=" expression | "call" ident
|
||||
| "?" ident | "!" expression
|
||||
| "begin" statement {";" statement } "end"
|
||||
| "if" condition "then" statement
|
||||
| "while" condition "do" statement ];
|
||||
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 ("="|"#"|"<"|"<="|">"|">=") expression;
|
||||
|
||||
expression = [ "+"|"-"] term { ("+"|"-") term};
|
||||
|
||||
term = factor {("*"|"/") factor};
|
||||
term = factor { ("*"|"/") factor };
|
||||
|
||||
factor = ident | number | "(" expression ")";
|
||||
factor = ident | integer | "(" expression ")";
|
||||
|
||||
## Operations
|
||||
formal_parameter_list = "(" [ variable_declarations ] ")";
|
||||
|
||||
"!" - Write a line.
|
||||
"?" - Read user input.
|
||||
"odd" - The only function, returns whether a number is odd.
|
||||
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;
|
||||
|
Reference in New Issue
Block a user