Giter VIP home page Giter VIP logo

compiler_ruby_to_js's Introduction

Ruby Compiler

Contains a tokenizer, a parser, and a code generator.

By the end, it successfully compiles some code in our language test.suvan , producing JavaScript output that we can execute.

While most compilers are highly optimized for speed, but ours will be optimized for easy readability and understanding.

Usage

In ./test.suvan:

make f (x,y)
    add(100, add(10,add(x,y)))
end

The above code will be compiled to:

function add(x,y){ return x + y};
function f(x,y){
        return add(100,add(10,add(x,y)))
}
console.log(f(1,2));

For now the compiler only supports the add function and the make keyword. The make keyword is used to define a function, and the add function is used to add two numbers. The end keyword is used to end the function definition.

Then once ruby has compiled the code, we pipe it to node to execute the JavaScript code.

Execution

To run the compiler, you can use the following command:

  • Windows
ruby .\compiler.rb 
  • Linux / mac
./compiler.rb | node

Then once ruby has compiled the code, we run the newly created file output.js to node to execute the JavaScript code.

node output.js

compiler_ruby_to_js's People

Contributors

greeenboi avatar

Stargazers

Aditya Kumar avatar Saransh Bangar avatar  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.