4.0 KiB
Emil's Fever Dream Language (EFDL)
Basic
EFDL is case sensitive, but I recommend you use lower case and snake_case.
Statements, declarations, functions and loops are terminated with semicolons:
for int i; < 10; print i + 1;;
formatted over many lines...
for < 10;
print i;
;
Comments and Whitespace:
Whitespace is discarded and is only useful for separating tokens.
# ... EOL
## ranged comment ##
Variables, Initializations & Declarations:
Initializations & Declarations will only be ran once within a given scope.
Examples
int x; # Uninitialized declaration
int x 2 + 2; # Initialized declaration to the value of 2 + 2.
# declares x & i, initializes x to i, after initializing i to 2
int x (int i 2);
# declares x with 2 and i with 3
int x 2 i 3;
# You can NOT do
float x int y; (this is a function now!)
Paren
Parens () are evaled FIRST.
parens, when used, delineate a freestanding statement. The following two lines are equivalent in result:
int x 2; x add x, 1; + 1; # 2 + 1 + 1
int x 2; x add (x + 1), 1;; # (2 + 1) + 1 = 3 + 1
parens, when started with first with an operator or function will evaluate as non-freestanding and will not assign anything.
()'s can contain multible statements and return the last statement within them.
(int i 2; i 2;)
Arith
Arithmetic operators and functions are evaled SECOND, LTR (Left-To-Right).
i 2;
i + 2; # adds 2 to i, which in this case is 2 + 2 = 4
# The last two statements are equivalent to
i 2 + 2;
(2 + i) is equivalent in operation to (i + 2) but i is added to 2. Meaningful comparison: (i - 2) and (2 - i) respectively if i is 10 then i is mutated to: 8, -8
1 + 2 * 3 / 10;
add add 2 3; 4;
Logical
Logical operators are handled LAST and LAST-1
1 = 2;
FALSE
Functions declarations:
int func int a int b; a + b;;
Functions implementations have at least one statement.
Default arguments:
int func -1 int a 5;
if a > 0;; # returns the default value here
else a;; # returns a
end func;
explicit version
int func -1 int a 5;
if a > 0;
return;;
else
return a;;
end func;
calling int func3 int a 1 int b int c 3:
func3 .b 2; # specify .b
Arrays
Arrays are addressed starting at 0, meaning offset 0. Arrays are apart of the type, and may be specified implicitly or explicitly.
int [3]i 1 2 3;
With Arith, Use whitespace to make code readable, as opposed to not:
int [6]i 1 + 1 1 + 2 1 + 3 1 + 4 1 + 5 1 + 6; # worst
int [6]i 1+1 1+2 1+3 1+4 1+5 1+6; # better
int [6]i 1 + 1 1 + 2
1 + 3 1 + 4
1 + 5 1 + 6; # better, ration to your needs
Arbitrary scopes & Goto:
LABEL:
int x; x 2;
;
to make scopes easier to read, there's an optional token that visualizes this,
label:
int x;
x
func
2 3 4
end func;
end x;
# x is available
end label;
# x is not available
goto can be used against labels. goto is restricted to scope.
Loops
for (int i 2; i + 1;) < 4;
print i;
end while;
This is an example of a "short" forloop. Here, we use ()'s to initialize i to 2, and then add 1 to it at each step. This loop will print 3 4.
A "long" forloop and "short" forloop would be defined as:
for <initialization> ; <conditional> ; <leading-statement> ; <statement>; ... ;
for <conditional> ; <statement> ; ... ;
hence a "long" forloop:
for int i 5; i > 0; i - 1; print i;;
# prints: 5 4 3 2 1
If
if x; print x;;
if x: a else b;;
if a;
if b; a + b;
else a;;
else 0;;
if a; if b; a + b; else a;; else 0;;
in C:
if (a) {
if (b) {
return a + b;
} else {
return a;
}
}
else {
return 0;
}
compacted:
if (a)
if (b) return a + b;
else return a;
else return 0;
if (a) if (b) return a + b; else return a; else return 0;