-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Yet is a functional language, virtual environment, and virtual machine language that has a notation similar to mathematical expressions.
In Yet, functions can be defined almost in the same way as formulas, and are highly compatible.
In addition, the Yet language is converted to the Yet virtual machine language by the compiler, and the Yet virtual machine language can be executed on the Yet virtual environment.
Furthermore, by adding the -L
option to the compiler, you can transpile to Lisp language.
Yet is aimed at beginners in programming to learn a functional language and a low-level language at the same time.
- How to run Yet
- Simple calculations
- Function
- Input/Output
- Conditional branching and repetition
- Macros, includes, and operator definitions
The Yet is a compiled language, so it must first be compiled into a virtual machine language and then run in a virtual environment. Compilation can be done in the terminal. The compilation command is as follows.
yetc -o VIRTUALMACHINELANGUAGEFILENAME.ye PROGRAMFILENAME.yet
If you want to output the assembly
yetc -p -o VIRTUALMACHINELANGUAGEFILENAME.ye PROGRAMFILENAME.yet
The virtual machine language file can be executed with the following command.
yet VIRTUALMACHINELANGUAGEFILENAME.ye
Yet is written in infix notation. Operators, calculations, and the order of operations are as shown in the table below.
Operators | Calculations | Order of operations | which calculate from the left or from the right? |
---|---|---|---|
= | Assignment | 1 | right |
? ... : | conditional operator | 2 | left |
== | equal | 3 | left |
!= | equal | 3 | left |
< | more | 3 | left |
> | less | 3 | left |
<= | more or equal | 3 | left |
>= | less or equal | 3 | left |
+ | addition | 4 | left |
- | subtraction | 4 | left |
* | multiplication | 5 | left |
/ | division | 5 | left |
% | remainder | 5 | left |
^ | exponentiation | 6 | right |
@ | array reference | 7 | left |
$ | Assignment to array | 7 | left |
Comments are enclosed in '.
Example:
3 + 5; '-> 8'
a = 3 + 3 == 6 ? 1 : 0; '-> a = 1'
a2 = (a + 1) ^ 2 ^ 3; '-> a2 = 64'
Define the function as below.
FUNCNAME(ARG1, ARG2, ...) = EXPRESSION;
or
FUNCNAME(ARG1, ARG2, ...) = {
EXPRESSION1;
EXPRESSION2;
...
};
In this case, the value is returned by the return function, and local variables are defined by passing all local variable names using the declare function in the first expression.
Call the function as below
FUNCNAME(ARG1, ARG2, ...)
Example:
f(x) = 3 * x;
f(5); '-> 15'
g(x, y) = {
declare(a);
a = x + y;
return(a);
};
g(10, 15); '-> 25'
Use the write function to write to the console, and the read function to read. The write function passes the expression to be written as an argument. The read function returns the read value as a return value.
Example:
Program
write(3 + 5);
a = read();
write(a + 1);
write(read() * read());
Execution result
$ yet VIRTUALMACHINELANGUAGEFILENAME.ye
> 8
< 5
> 6
< 4
< 6
> 24
Conditional branching is performed using conditional operators or if functions.
The format of the ternary operator is as follows.
CONDITIONALEXPRESSION ? THENEXPRESSION : FALSEEXPRESSION
The if function can be called as follows.
if(CONDITIONALEXPRESSION, THENBLOCK, FALSEBLOCK)
Iteration is done by recursion.
Example:
Program
f(x) = {
if(x == 0, {return(0);}, {write(x); f(x - 1);});
};
f(10);
Execution result
$ yet VIRTUALMACHINELANGUAGEFILENAME.ye
> 10
> 9
> 8
> 7
> 6
> 5
> 4
> 3
> 2
> 1