Skip to content

milesbarr/programming-language-x

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Programming Language X

Programming Language X is a compiler written in C.

Current State

The compiler implements parsing, name resolution, type checking, and code generation for a limited number of programming language features and includes two backends: LLVM IR and WebAssembly.

Building

In order to build the compiler from source, CMake and a C compiler such as Clang or GCC is required. First, ensure these dependencies are installed on your system. Next, clone this repository and open a shell in the directory. Lastly, build the compiler by running the following commands:

mkdir build cd build cmake .. cmake --build .

Syntax

Definitions

Define a constant.

const foo = 1;

Define a variable.

var foo = 1;

Declare a variable.

var foo: s32;

Define a function.

func foo(bar: s32) -> s32 { return bar; }

Types

Integer types:

s8 s16 s32 s64 u8 u16 u32 u64

Floating point types:

f32 f64

Boolean type:

bool

Function types:

func (s32) -> s32

Array types:

[8]s32

Slice types:

[]s32

Examples

Add two integers.

func add(a: s32, b: s32) -> s32 { return a + b; }

Fibonacci sequence.

func fib(n: s32) -> s32 { if n == 0 { return 0; } else if n == 1 or n == 2 { return 1; } else { return fib(n - 1) + fib(n - 2); } }