A few months as I was learning about compiler design, I came up with the project Rook.
Rook Is a very simple programming language I am making for fun.
- I am not a professional in programming language design. I barely know anything about programming languages.
- The language is barely tested, therefore its possible that there are tonnes of errors unearthed. For example the error reporter is drunk.
- Unary operators are not supported yet.
- I know the compiler is written in C#.
//Print is an inbuilt function used to print to the console.
Before we dive deep into Rook, A few points are worth noting.
- Variable names can only contain alphabets and an underscore (_) (for now).
- Only decimal numbers are supported (for now).
- Everything in Rook is an object.
- EVERY STATEMENT in Rook returns a value. I mean EVERY STATEMENT even an assingment. An assignment statement returns the currently assigned value
The language has very few basic data types. These are:
Numbers are, well numbers. All numbers in Rook are in double precision.
let number := 10;
let numberTwo := 0.453;
let numberThree := 45.034;
let another := 34 + 45 / 456 * 2; //Expressions are also supported
Numbers contain a few methods:
Since unary operators are not supported yet, Numbers have a
Negate property that returns a negated new number.
let negatedOne := 10.Negate; //-10
let negatedTwo := negatedOne.Negate; //10
let sqrt := 10.Sqrt; //Square root
let sqr := 10.Sqr; //Square
let exponential := 10.Exp; //Exponential
let absolute := 10.Abs; //Absolute
let cosine := 10.Cos; //Cosine
let sine := 10.Sin; //Sine
let power := 10.Power(2); //10 Power 2 => 100
let log := 10.Log(10); //Log base 10 of 10
Strings are textual data.
" is used to surround string data.
\ can be used to excape characters but special characters E.g
\t and others are not supported yet.
let string := "Hello world!";
Strings contain a few methods:
Concat method can be used to concatnate strings.
let string := "Hello" + " world!";
//A + can be used to concatnate strings
let stringTwo := string.Concat("again");
let stringThree := "Another".Concat(" string");
//Using Concat method.
ToNumber property which converts a string to a Number.
let s := "200";
s.ToNumber; // Returns 200 as a number
"200".ToNumber; // is also valid
A boolean is a simpe true/false value.
let trueValue := True;
let falseValue := False;