Giter Club home page Giter Club logo

grok's Introduction

Build Status

Grok - Another JavaScript interpreter

Grok is a simple and tiny javascript interpreter written in C++. I made it because I wanted to learn how Compiler works.

Features

Declare variables:

var a = 10;

// or create strings
var b = 'grok';

// or create an array
var c = [ 1,2,4,6 ];

// or create objects
var d = {
  a : 100,
  b : {
    arr : [1,2,4,5]
  }
};

Write complex expressions like:

var sum = d.a + c[0] + c.length + d.b.arr[2];

Create functions:

function fib(n) {
    if (n == 0 || n == 1)
        return 0;
    else if (n == 2)
        return 1;

    return fib(n - 1) + fib(n - 2);
}

// call functions
console.log(fib(10)); // yup console object is supported

Call Array methods:

var arr = [ 1, 2, 3, 4, 5 ];
var squares = arr.map(function(element) {
            return element * element;
}); // squares == [ 1, 4, 9, 16, 25 ]

Building

Requirements

  • Boost C++ Library sudo apt-get install libboost-all-dev
  • GNU Readline Library sudo apt-get install libreadline6-dev
  • pthread
  • cmake sudo apt-get install cmake
  • C++ compiler with C++14 support sudo apt-get install g++-5
  • Ubuntu (not tested for other operating systems)

Compiling

One step: cd grok && mkdir build && cd build && cmake .. && make -j4

Contribute

Grok is currently in development stage. New features will be added slowly. It is just a free time project. I work on it whenever I am free. If you want to help, feel free to open pull requests or create issues. Please do star the project if you like it.

Things that do not work

  • switch case statements
  • break, continue statements
  • this may not work properly
  • constructors

grok's People

Contributors

dhaliwalx avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 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.