Giter Site home page Giter Site logo

jlox's Introduction

jlox

Crafting Interpreters

Install

yarn global add jlox

or

npm install -g jlox

Usage

jlox --path=<FILE.EXT>

Syntax

Variables

var a = 123;
var b;
b = 223;
var c = "hello world";

Print

print "hello world";
print 3 * 4;

Comment

var name = "John"; // username
print name;

Operators

(5 + 6) * 10 - 12 / 3;

Expressions

var a = 5;
print a * 5;
print "John" + " " + "Doe";
// 25
// John Doe

Conditional Execution

var a = 3;
if (a < 4)
    print 111;
else
    print 222;
// 111

Logical Operators

print "hi" or 2; // "hi".
print nil or "yes"; // "yes".

var a = 3;
if (a > 2 and a == 3)
    print("if statement");
else
    print("else statement");
// if statement

For Loop

var a = 0;
var temp;

for (var b = 1; a < 10000; b = temp + b) {
    print a;
    temp = a;
    a = b;
}

While Loop

var a = 1;
while (a < 10) {
    print a;
    a = a + 1;
}

Function

fun sayHi(first, last) {
  return "Hi, " + first + " " + last + "!";
}

print sayHi("Dear", "Reader"); // Hi, Dear Reader!

Class

class Breakfast {
    cook(something) {
        print "cook " + something + ".";
    }
}

Breakfast().cook("egg");

Inherit


class Doughnut {
  cook() {
    print "Fry until golden brown.";
  }
}

class BostonCream < Doughnut {
  cook() {
    super.cook();
    print "Pipe full of custard and coat with chocolate.";
  }
}

BostonCream().cook();

jlox's People

Contributors

protosl 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.