Advanced Usage
Table of Contents
- OCaml Baguette# Interpreter
- REPL
- Basic Usage
- Advanced Usage
- Random Guessing Game
- Binary Turing Machine
- Binary Turing Machine Examples
Introduction
In this page we will introduce the LABELS
;
GOTOS
, and IF
and what we can do with it.
Reading the basic usage page is strongly recommended before reading this page.
The REPL do not as of now (03/09/2022) supports labels, the coding will be in a file called test.baguette
you can find a syntax highlighter extension for Baguette# on VSCode on the marketplace here or typing ext install coco33920.baguette-sharp-support
into the VSCode Command Palette
Labels
The label keyword is ICECREAM
followed by a name in a string like PARISBREST test PARISBREST
and the keywords MUFFIN/COOKIES
which are BEGIN/END
finally you need to close the block by a BAGUETTE
like exposed here
test.baguette
ICECREAM PARISBREST test PARISBREST
MUFFIN
COOKIES BAGUETTE
You can put any code you want inside, just you must not put a BAGUETTE
in any code inside it as it will interpret it as the end of the block.
The file should look like this
test.baguette
ICECREAM PARISBREST test PARISBREST
MUFFIN
CROISSANT CHOUQUETTE PARISBREST Hello World! PARISBREST CLAFOUTIS
COOKIES BAGUETTE
we can execute the file with
baguette_sharp --input test.bag
,
and we have… the following output
which is nothing.
Because we have not called it!
GOTOs
We are right after the last section. To call it we need to use the PAINVIENNOIS
keyword with the name of the label we want to call.
Let get back to our code and add the instruction.
test.baguette
ICECREAM PARISBREST test PARISBREST
MUFFIN
CROISSANT CHOUQUETTE PARISBREST Hello World! PARISBREST CLAFOUTIS
COOKIES BAGUETTE
PAINVIENNOIS PARISBREST test PARISBREST
Executing it now outputs :
Order of execution
Let modify our code a bit
test.baguette
ICECREAM PARISBREST test PARISBREST
MUFFIN
CROISSANT CHOUQUETTE PARISBREST Hello World! PARISBREST CLAFOUTIS
COOKIES BAGUETTE
CROISSANT CHOUQUETTE PARISBREST Hello ! PARISBREST CLAFOUTIS
PAINVIENNOIS PARISBREST test PARISBREST
And executing it outputs,
The order is respected
Errors
Let modify our code to generate an exception in the label. Here a Syntax Error
will be raised
test.baguette
ICECREAM PARISBREST test PARISBREST
MUFFIN
CROISSANT CHOUQUETTE PARISBREST Hello World! PARISBREST CLAFOUTIS
MADELEINE CHOUQUETTE PARISBREST test PARISBREST CLAFOUTIS
COOKIES BAGUETTE
PAINVIENNOIS PARISBREST test PARISBREST
The error line count is counting from the first line of the label (the count starts at 0, the first line is the 0th). And not from the file entirely. It counts even if you call another line before goto the label
If you try to access a label which do not exist, a standard label do not exists
line will be output.
Variables and Labels
As explained in the basics there is not a real scope system in this language. In fact every pseudo-variable are elements of a shared hash-table, as such they behave a little like static variable. The following code
test.baguette
ICECREAM PARISBREST test PARISBREST
MUFFIN
CROISSANT CHOUQUETTE PARISBREST Hello World! PARISBREST CLAFOUTIS
CROISSANT CHOUQUETTE MADELEINE CHOUQUETTE PARISBREST variable PARISBREST CLAFOUTIS CLAFOUTIS
COOKIES BAGUETTE
QUATREQUART CHOUQUETTE PARISBREST variable PARISBREST 10 CLAFOUTIS BAGUETTE
PAINVIENNOIS PARISBREST test PARISBREST
outputs
But you need to define the variable before calling the label. If not an error is raised, the same as if you tried to access a variable before its definition as seen in basics.
IFs
The language supports IF statements, which are very similar to Labels (and internally works like a conditional called Label, but this is transparent to the developer)
The keyword for IF
is SABLE
and a statement is constructed like that IF condition THEN BEGIN code END;
which in Baguette# translates to
SABLE condition FRAMBOISIER MUFFIN code COOKIES BAGUETTE
the following code prints something if CUPCAKE
is true, which it is because CUPCAKE
is the keyword for true.
if.baguette
SABLE CUPCAKE
FRAMBOISIER MUFFIN
CROISSANT CHOUQUETTE PARISBREST this is true PARISBREST CLAFOUTIS
COOKIES BAGUETTE
which outputs
The CUPCAKE
is meant to be replaced by any condition seen in basic.
That is all for the Advanced Usage, in the next page we will learn how to do a basic loop and program a
plus/minus integer game!
The code for the labels can be downloaded here and for the if here
Functions
The language supports function definition and using them as if they were native functions, the functions are read after the main one of the standard library. They are defined with this syntax.
NAME { "PARAM_1" "PARAM_2" ... "PARAM_N" } (
..code..
);
The Baguette names are CRUMBLE
for {
; SCHNECKENKUCHEN
for }
and finally the return
statements is
a function it must be called with parenthesis, RETURN
is APFELSTRUDEL
.
Furthermore, arguments must be called through the MADELEINE
function.
Finally, a function that take one argument and prints it like "Argument: <argument>"
is like this
TEST CRUMBLE PARISBREST arg1 PARISBREST SCHNECKENKUCHEN CHOUQUETTE
PAINAUCHOCOLAT CHOUQUETTE PARISBREST Argument %d PARISBREST MADELEINE CHOUQUETTE PARISBREST arg1 PARISBREST CLAFOUTIS CLAFOUTIS
CLAFOUTIS BAGUETTE
Calling it is simple, as if a TEST function existed, do not hesitate to role-play and add your own country’s or your favourite’s pastries :).
Load
You can load a B# file (containing for example functions) into another with the LOAD call (yet to be baguetified)
LOAD "path/to/file";
in B# LOAD PARISBREST path/to/file PARISBREST BAGUETTE