Evalyte

First try - The Ciel Programming Language

Context

I’m making the Ciel programming language, the goal is not to make something revolutionary but something with a defined purpose for the learning experience, the syntax will be similar to languages like C++ and Rust.

I have been programming for more than 10 years and tried multiple languages, I started with C, then C++ which has been and still is my most prefered language with a hate/love relationship, I’ve used Lua, Java and C# for modding, and I use Javascript/Typescript professionally everyday now.

I like to understand how things work and make things from scratch, I don’t really care to reinvent the wheel when doing hobby projects and learning.

Goals

I put some goals and constraints for my language based on my preferences:

  • The syntax must be friendly
  • Strongly typed
  • The language must be explicit and have no ambiguity when reading the code, for example the caller of a function must know without LSP or other tools if the variables passed to a function can or can’t be modified.

Features

I need to keep the scope simple so I plan to implement only the basics:

  • Variables: typed, imutable by default.
  • Functions: no forward declaration needed.
  • Conditions: “if”, “else” and “if else” statements.
  • Loops: “while” form only, no “for” loop for now.
  • Arithmetics: add, sub, mul and div operations only for now.

But there is also needs outside of the language itself like:

  • Error reporting
  • Pretty printing of the program structure (AST style)
  • Running the program with an interpreter
  • Converting the program to another language (thinking of C or CPP)

Examples

Here is a little snippet of what I image it could look like:

func main() {
	let width: i32 = 12; // explicit type
	let height = 50; // deduced type

	
	let surface = calc_surface(width, height);
	
	if surface < 100 {
		println("The surface is {}, ok", surface);
	} else {
		println("The surface is {}, too big", surface);
	}
	
	return 0;
}

func calc_surface(w: i32, h: i32): i32 {
	return w * h;
}

I know it look like a mix of multiple languages but keep in mind that this is for learning purpose.

Plan

The first step is to build a lexer then a parser to make an Abstract Syntax Tree that I can pretty print to have a view of how the parser behave.

The second step is checking variable scopes and types, making friendly error reporting, I plan to abort early at the first error found for now.

The third and last step is executing (or interpreting) the program!

I’m almost certain to have forgotten some steps that might be obvious to compiler veterans, I guess I’m gonna learn the hard way :)