Coder Social home page Coder Social logo

lara's Introduction

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

lara's People

Contributors

nuriamari avatar

Stargazers

Puyan Lotfi avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.