frr
stands for FRench interpreteR.
No binary is released for now, please see the BUILD section below.
No binary is released for now, please see the BUILD section below.
Running frr
will give you the usage instructions.
$ frr
Utilisation: frr <destination/fichier/script.fr>
You can find examples in the examples
directory.
Since this language is based on pseudocode, and pseudocode doesn't have any specification, we have to make sure we all use the same syntax.
Here, I used the syntax my school uses but yours may be different. If it slightly differs (like a builtin function name is named differently) you can open an issue and explain what's different to help me implement aliases.
Let's start with a summary of the syntax. When it's checked in front of it means it's implemented.
To write a comment, use the #
character.
It'll make the rest of the line a comment.
# This is a comment.
afficher "Hello World" # This is also a comment.
This is the only way to make a comment.
There's no way to make a comment like /* ... */
.
So multi-line comments should be written like this:
# Start to write your comment on a line
# then start a write another comment
# to continue your comment.
When you define a variable, you have to define its type. Here are the available types.
Those types are case sensitive, so always in lowercase.
Type | Alias in C (or Python) |
---|---|
entier |
int |
réel |
float |
caractère (alias: car ) |
char |
chaîne |
str in Python |
booléen |
bool in Python |
When you're writing a function, a procedure or a program you must declare any variable you're going to use.
This is happening right after the début
keyword. To initiate a "variable declaration block" using the avec
keyword.
programme Déclarations
début
# You can declare a variable on the same line as `avec`.
avec in_line: entier
a : entier
# By the way, spacing is not important.
b : réel
# And indentation is not important either.
c : chaîne # Works
d : chaîne # Also works
e : booléen
f, g, h : caractère # You can also declare multiple variables on the same line.
# Same as above -> f, g, h : car
fin Déclarations
Note that if you're not using any variable in your program, you don't need to declare any. And so, you don't need to use the avec
keyword and you can just start writing your code.
To print something in the console, use the afficher
keyword.
Note that there's no newline at the end of the printed text. So if you want to print a newline, you have to do it manually.
# This is the "official" way to do it.
afficher "Hello, World!\n"
# Otherwise, those also work.
afficher("Hello, World!")
afficher ("Hello, World!")
You can pass multiple arguments to afficher
.
Each argument will be printed with a space between them.
afficher "Hello", "World!" # >>> Hello World!
You can also pass variables, expressions.
username <- "Vexcited"
afficher "Hello " + username # >>> Hello Vexcited
afficher "Réponse:", 21 * 2 # >>> Réponse: 42
Passing a boolean will print vrai
or faux
.
afficher vrai # >>> vrai
afficher faux # >>> faux
# So you can print conditions like this:
afficher "Yes ?", vrai = vrai # >>> Yes ? vrai
To get user input, use the saisir
keyword.
avec username : chaîne
saisir username
saisir
will always cast the input to the type of the variable you're assigning it to.
If the input can't be casted to the type of the variable, the interpreter will throw an error.
avec age : entier
saisir age
# If you enter "21", `age` will be equal to 21.
# If you enter "21.5", `age` will be equal to 21.
# If you enter "Hello", the interpreter will throw an error.
avec x : réel
saisir x
# If you enter "21", `x` will be equal to 21.0.
# If you enter "21.5", `x` will be equal to 21.5.
# If you enter "Hello", the interpreter will throw an error.
frr
is made with Zig.
The version of Zig used in this project is 0.12.0-dev.2858+7230b68b3
.
# Clone the project if not already done.
git clone https://github.com/Vexcited/frr
cd frr
# Build and run the binary directly.
zig build run -- ./examples/hello-world.fr
# Or you can simply build...
zig build
# ...then execute the binary manually.
./zig-out/bin/frr ./examples/hello-world.fs
- Build a simple interpreter :
frr
was written in TypeScript before using this guide as reference to understand how a language is made using AST ; - Crafting Interpreters : a guide I used as reference to build the current version of
frr
where I learned how bytecode interpreters were made ; jwmerrill/zig-lox
: an implementation of the Lox programming language (from Crafting Interpreters) in Zig. Very helpful to use as reference since I am learning Zig at the same time as writing this language ;- Algorithm Lessons from
cril.univ-artois.fr
to know a bit more about how other universities are understanding pseudocode in their lessons.