Skip to content

A "simple" compiled & interpreted multiple-paradigm language.

License

Notifications You must be signed in to change notification settings

Xemptuous/cimpl-lang

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 

Repository files navigation

cimple-lang

A "simple" compiled and interpreted multiple-paradigm language.

Currently only Interpreter is implemented; compiler to come.

Usage

run the compile.sh script to produce the a.out file, then simply run with CLI!

Interpreter CLI

The command-line interface written with ncurses offers functionality similar to Python's CLI interpreter, but with additional features to accomodate Cimpl.

The normal paradigms exist: * using Key_Up and Key_Down to move between histories * deleting and replacing chars * etc.

However, an expanded form of the indentation mechanism exists. e.g., when ending a line with an opening { l_brace, the next line will indent (4 spaces by default), and the line will dednt when a } r_brace is present as the last char. It is recommended to enter these closing braces on their own line.

Once the braces close back down to the root level, the code will be executed.

Syntax

Variable declaration

Familiar let statements are used to initialize variables.

All lines must end with semi-colons.

let x = 5;
let foo = "bar";
let abc123 = "45"

Functions

Functions are declared with the fn keyword, and use braces for the body.

fn addNums(a, b) {
    return a + b;
}

let x = 1;
let y = 4;
let z = addNums(x, y);
print(z);
// 5

Conditionals

These should be a familiar construct:

let x = 5;

if (x < 4) {
    print("too small");
}
else if (x > 6) {
    print("too big");
}
else {
    print("just right");
}

let y = false;
if (y) { print("true"); }
else { print("false"); }
// "false"

Loops

For loop

For loop ranges are start-inclusive and end-exclusive.

// 0 inclusive, 10 exclusive
for (i in 0:10) {
    print(i);
}
// 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

Optional step parameter is allowed

// step by 2
for (i in 0:10:2) {
    print(i);
}
// 0, 2, 4, 6, 8

Multiple variables can be declared inline as well

for (i, j in 0:10) { ... }
While loop

While loops will look quite familiar:

let x = 0;
while (x < 10) {
    print(x);
    x++;
}
Do While
let x = 0;
do {
    print(x);
    x += 1;
} while (x < 10);

Arithmetic Operations

Numbers can be operated upon and modified in various syntaxes:

let x = 5;
x++;
x--;
x += 1;
x -= 1;
x *= 3;
x /= 2;

Arrays and Dicts

Arrays can be assigned and indexed in a fashion similar to python:

let arr = [1, 2, 3, 4, 5];
print(arr[0]) // 1
print(arr[-1]) // 5 - reverse indexing

Strings can also be accessed by index:

let str = "foobar";
print(x[-3]); // b

Dictionaries can be declared and accessed in a pythonic manner:

let d = {
    "a": 10,
    "b": 20,
    "c": 30
};
print(d["b"]);
// 20

Array slicing to come! Syntax will be similar to python

Type Conversions

By default, types will attempt to be cast to strings.

E.g., when doing a statement like:

print("a" + 1);

the "1" will be coerced into a string, resulting in "a1"

About

A "simple" compiled & interpreted multiple-paradigm language.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published