Giter Club home page Giter Club logo

sharplox's Introduction

SharpLox

Hello there and welcome to SharpLox, a modified version of the lox language designed by Robert Nystrom implemented in C#.

Running the interpreter

Simply clone and run the command

dotnet run <fully qualified path to .slox file>

Example

➜ cat test.slox
       │ File: test.slox
   1   │ print("hi");

➜ dotnet run --project CommandLine/CommandLine.csproj /Users/jaymadden/programming/projects/SharpLox/test.slox 
hi

The basics

Variable declarations

var i = 4;
var j = 4;

print(i + j);

Null handling

var a = nil;

if true {
    a = 4;
}

print(a)

Control Flow

Standard control flow concepts are implemented

if statements

var state = true;

if state {
    print("Hello there");
}
else {
    print("Hi there");
}

while and for loops

var i = 0;

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

Break

var i = 0;

while true {
    print(i);
    i = i + 1;

    if i > 10 {
        break;
    }
}

Functions

Top level functions are supported

func someMethod(k) {
    var i = 4;
    var j = 4;

    print(i + j + k);
}

someMethod(k);

Anonymous functions


func someMethod(lambda) {
    lambda(1);
}

var someLambda = func(foo) {
    print(foo + 1);
}

someMethod(someLambda);

Classes

class Foo {
    func init(baz) {
        this.bar = baz;
    }

    func printBar() {
        print(this.bar);
    }
}

var f = Foo(5);
f.printBar();
class Foo {
    func init(baz) {
        this.bar = baz;
    }

    func printBar() {
        print(this.bar);
    }
}

class Baz : Foo {

    func init() {
        super.init(5);
    }

    func something() {
        print("Hi from baz");
    }
}

var f = Baz();
f.printBar();

sharplox's People

Contributors

jay-madden avatar

Stargazers

 avatar  avatar Thinker avatar  avatar Deeton Rushton avatar  avatar

Watchers

James Cloos avatar  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.