Giter VIP home page Giter VIP logo

gb_lang's Introduction

About Gb

Gb is a project I created to learn more about the inner workings of programming languages. While it is not fully functional, it has achieved this goal and (usually) works within its extremely constrained scope.

Why Gb?

Gb is intended to be a lightweight scripting language that combines the type system of Rust with the ease of use of Python. Combine a familiar syntax with an automatic command line argument parsing (not implemented), Gb should be perfect for small CLI automations in your daily workflow.

Does it work?

Yes! The body of the interpreter is finished and the language can be used for simple calculations. The standard library is extremely sparse and error handling and messages can often be improved. Also, there is currently no repl nor anyway to use it without writing at least a touch of Rust (unless you want to write your entire project in "file.gb", in which case, cargo r is all you need!).

It's clear that this project is still in its infancy, but it should see more and more progress as time goes on.

Features

So, What makes Gb unique? Here are a few present and planned features on the docket for Gb.

  • Top level code with auto-executing main function (if present)
  • Strong, inferred typing (not implemented)
  • Automatic parsing of command line arguments (not implemented)
  • First class support for interpreted, JIT, and compiled modes (1/3 complete)
  • Algebraic Data Types (not implemented)

Code Sample

Gb is a very familiar language in its very early stages. While it looks largely unassuming now, it should gain additional character as development progresses.

fn main() {
    let x = 0;
    while x < 10 {
        x = x + 1;
    }
    print(x);

    let foo = fn() { print("Hello, foo!"); };
    
    x = 0;
    while x < 10 {
        foo();
        x = x + 1;
    }
}
Outputs:
> 10
> Hello, foo!
> Hello, foo!
> Hello, foo!
> Hello, foo!
> Hello, foo!
> Hello, foo!
> Hello, foo!
> Hello, foo!
> Hello, foo!
> Hello, foo!

Why not use a parser generator?

Since Gb was primarily a learning exercise, I wanted to try and do as much as possible of it from scratch. Armed with only my programming languages textbook and some serious willpower, I created Gb by myself as an extracurricular project. There are a few branches where I have experimented with using parser generators (like Pest), but ultimately, these efforts weren't as fun for me as it was to build it from the ground up.

The Process

Gb has been built and rebuilt a few different times. The current iteration is based on Thorsten Ball's book Writing an Interpreter in Go, which ended up being quite a convenient resource because the syntax for Monkey was nearly identical to what I had planned for Gb. But the initial versions were built entirely on my own.

In specific, this branch represents the work I was able to put in with a parser generator. As mentioned above, I ended up being pretty unhappy with this approach. I especially disliked how difficult it was to hook into the Pest error system to emit useful error messages from Gb.

It's also worth checking out this branch, which was the version I had before I began to use the Writing an Interpreter in Go version. I learned the most from this version and ultimately decided to rewrite it again only because I wanted to switch to a fancier Pratt-parser rather than my grammar-based parser of this version.

The future of Gb

I occasionally resume work on Gb. My plan is to one day make it a sleek scripting language with support for interop with Rust. As of now, development of the project has taken the back seat to my studies in college.

gb_lang's People

Contributors

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