Evalyte

Basic functionnalities - The Cely Programming Language

In the last devlog, I put a code snippet that worked, but it was really all I had working, but now it works far better and I can already make some small and simple programs.

Here is the breakdown of the current functionnalities

Types

For now, only 32 bits integer i32, boolean bool and string str types are supported.

Variables

The variables are declared with the keyword let, the type is infered from the expression or can optionaly be specified:

let value = 2; // infered as i32
let other: i32 = 3; // specified as i32

Functions

Functions are declared with the keyword func, they can have arguments and their type must be specified, same for the return type:

func do_something(value: i32): i32 {
	return value + 1;
}

Conditions

Conditions can be used with the if statement followed by the condition expression then the block to execute if the condition is true:

if value < 2 {
	do_something();
}

Loops

Loop can be used with the while statement followed by the condition expression then the block to execute continuously while the condition is true:

while value < 2 {
	do_something();
	value = value + 1;
}

Builtin functions

For the interpreter, I made builtin functions to do I/O operations, for now there is only a small amount of them:

std.println - Print a line to stdout
std.read_input - Wait for user input

There is also utility functions:

std.to_string - Convert i32 to str
std.to_i32 - Convert str to i32
std.random_i32 - Generate a random i32 number, min and max arguments can be specified

First working program: number guessing game

A basic game where the goal is to guess the number, each time we enter a wrong number we get a hint if it’s lower or greater.

let target = std.random_i32(0, 100);
let guess = -1;

std.println("Guess a number");
while guess != target {
	guess = std.to_i32(std.read_input());
	if guess < target {
		std.println("Greater");
	}
	if guess > target {
		std.println("Lower");
	}
}
std.println("Good job");

return 0;

output:

Guess a number
50
Greater
75
Lower
63
Good job

NOTE

There is no else or else if statements for now and wrong inputs are not handled correctly.