Skip to content

NuriAmari/Lara

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lara

An interpretted language I'm working on with the help of my language tools. Still very much a work in progress, but most fundamental structures have been implemented:

Variables

Currently, the only literal values support are integers.

Declaration

let a = 1;
let b = a;
let c = 2;

Mutation

a = 5;
b = 15;
c = b - 5;

Expressions

All the basic mathematic operators are supported, including parenthesis for controlling precedence. Exponents (**) are recognized by the lexer, but not in the parser / evaluator yet. Since the only supported type is an integer, division is integer division.

let a = 1 + 2;
let b = a - 5;
let c = a * 2 + 4;
let d = a * (2 + 4);
let e = a / 5;

Functions

Declaration

func add(a,b) {
    return a + b;
}

Invocation

add(1,1);

Closures

func outer(a, b) {
    let c = 1;
    func inner(a,b) {
        return a + b + c;
    }
    return add(a, b);
}

outer(1,1);

Control Flow

If Statements

if (a) {
    print(a);
} elif (b) {
    print(b);
} else {
    print(c);
}

While Loops

let i = 0;
while (i < 10) {
    print(i)
    i = i + 1;
}

For Loops

for (let i = 0; i < 10; i = i + 1) {
    print(i)
}

Break

func print0_9() {
    for (let i = 0; i < 10; i = i + 1) {
        if (i > 5) {
            break;
        }
        print(i);
    }
    for (let j = i; j < 10; j = j + 1) {
        print(j);
    }
}

print0_9();

Return

func print_only_one(a,b) {
    print(1);
    return;
    print(2);
    print(3);
}

print_only_one();

IO

print(1 + 1);

Todo

  • Arrays
  • More types
  • First class functions

Usage

  1. Clone the repo
  2. Symlink lara to somewhere on your PATH
  3. Make executable chmod +x lara
  4. Execute programs like lara test.lr (Note this assumes python3 is default python version on your machine)
  5. If python3 is not default, run the script explicitly python3 lara test.lr

About

A toy language I'm working on

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages