cheese-lang (or Linguaggio Formaggio in Italian) is a statically typed, interpreted language with a runtime written in go.
This is obviously not meant to be a serious language, is an exercise to learn mora about GO and language design.
This dose not mean that is useless, it is a fully functional Touring complete language that you can use to write simple console application.
inside the folder examples you are albe to find a few basic program that use all the features of the language.
To run an example you can use:
go run cmd/cheese-lang/main.go examples/string_search.cl
there are only 5 types in cheese-lang, that are named after famous Italian cheeses:
Parmesan
(equivalent to int)Gorgonzola
(equivalent to float)Mozzarella
(equivalent to string)Milk
(equivalent to bool, can have ywo values:fresh
andspoiled
that are equivalent totrue
andfalse
)Ricotta
(equivalent to void)
variables names must start with a letter and can contain letters, numbers and underscores. variables names are also case sensitive, and are invalid if they are a keyword of the language.
the variables are declared with the following syntax:
<Type> <name> = <value>;
example:
Parmesan a = 5;
Gorgonzola b = 5.5;
Mozzarella c = "hello";
Milk d = fresh;
note that is not possible to declare a variable and leave it uninitialized
//
(single line comment)
taste
(if)taste <condition>{ <block> }
recipe
(function)// declaration recipe <name>(<type param 1> <name param 1>, <type param 2> <name param 2>, ...) { <block> prepare <return value>; } // call <return 1> ,<return 2>, ... = <name>(<param 1>, <param 2>, ...);
curdle
(loop)curdle { <block> taste <condition> { drain // break; } }
In a cheese lang program there are 2 different contexts: Global
and Local
contexts.
In a Global
context you will only be able to declare variables and functions, but you won't be able
to perform operations on variables.
On a Local
context you are able to do everything except declaring function.
In cheese lang there is one important function named Fondue
that will be called as entry of your program (equivalent of the main function)
Parmesan SUM_COUNTER = 0;
// Not allowed since we are in global context
// SUM_COUNTER = SUM_COUNTER + 1
recipe Sum(Parmesan a, Parmesan b) -> Parmesan{
SUM_COUNTER = SUM_COUNTER + 1;
prepare a + b;
};
// main function
recipe Fondue(){
Parmesan x = Sum(43,26);
// Not allowed since we are in local context
// recipe MySum(Parmesan a, Parmesan b) -> Parmesan {...}
prepare;
};
-
Parmesan
:+
(addition)-
(subtraction)*
(multiplication)/
(division)%
(modulo)==
(equality)!=
(inequality)>
(greater than)<
(less than)>=
(greater than or equal to)<=
(less than or equal to)
-
Gorgonzola
:+
(addition)-
(subtraction)*
(multiplication)/
(division)==
(equality)!=
(inequality)>
(greater than)<
(less than)>=
(greater than or equal to)<=
(less than or equal to)
-
Mozzarella
:+
(concatenation)==
(equality)!=
(inequality)
-
Ricotta
:==
(equality)!=
(inequality)!
(negation)&&
(and)||
(or)^
(exor)
There is no operator priority in cheese lang, but you could use parenthesis to achieve the desired order
If no parenthesis are used the language will evaluate expressions from left to right. For example:
a+b*c-d/e
will become
a+(b*(c-(d/e)))
p_to_g(Parmesan p) -> Gorgonzola
(converts aParmesan
to aGorgonzola
)p_to_m(Parmesan p) -> Mozzarella
(converts aParmesan
to aMozzarella
)g_to_p(Gorgonzola g) -> Parmesan
(converts aGorgonzola
to aParmesan
)g_to_m(Gorgonzola g) -> Mozzarella
(converts aGorgonzola
to aMozzarella
)m_to_p(Mozzarella m) -> Parmesan, Milk
(converts aMozzarella
to aParmesan
, and return a milk to represent if the conversion was successful)m_to_g(Mozzarella m) -> Gorgonzola, Milk
(converts aMozzarella
to aGorgonzola
, and return a milk to represent if the conversion was successful)
eat() -> Mozzarella
(reads a line from the standard input)serve(Mozzarella m)
(prints a string to the standard output)
weight(Mozzarella m) -> Parmesan
(returns the length of a string)slice(Mozzarella m, Parmesan start, Parmesan end) -> Mozzarella
(returns a substring of a string, fromstart
toend
(inclusive))