Giter VIP home page Giter VIP logo

bast's Introduction

bast

Compiler for BAST(Basic Tiny) - A Tiny Toy Basic Dialect

Introduction

This compiler takes code written in bast and compiles(transpiles) to C code.You need to compile the C code with C compiler (gcc/tcc/clang are tested to work) to produce executable.

This provided the opportunity to learn about lexing,parsing and to learn more Golang. I believe that this toy language will not be used other than for educational purpose(for people like past-me).

Installation

You can download binary for your OS from Releases . Also , if you have Go installed , you can install bast by typing this in terminal.

go install github.com/varbhat/bast@latest

Usage

  • bast --help will print the help.

  • bast -in=filename.bast -out=filename.c will compile bast source filename.bast to C source filename.c.

  • You need to compile the emitted C file with C compiler like GCC/Clang/TCC.

  • cc ./filename.c -o filename (where cc is gcc/clang/tcc)

  • You can combine these steps :

bast -in=filename.bast -out=filename.c && cc filename.c -o filename

And then run the executable binary filename it produced.

Language

Language is small Dialect of BASIC same what AZHenly implemented.I only wrote compiler. Grammer file can be found at grammer.txt

It supports:

  • Numerical variables
  • Basic arithmetic
  • If statements
  • While loops
  • Print text and numbers
  • Input numbers
  • Labels and goto
  • Comments

Example code

PRINT "How many fibonacci numbers do you want?"
INPUT nums
PRINT ""

LET a = 0
LET b = 1
WHILE nums > 0 REPEAT
    PRINT a
    LET c = a + b
    LET a = b
    LET b = c
    LET nums = nums - 1
ENDWHILE

You can find more examples at Examples

Acknowledgements

Thanks to AZHenly for their post Let's make a Teeny Tiny compiler which acted as reference. But , instructions in that post are for Python and the compiler is implemented in Python. I who wanted to know more about compiler , read it as reference , wrote the compiler from scratch in Golang.

Although the language for both the compilers are same,bast compiler is written from scratch in Golang ,implemented by instructions of their post.

License

MIT

bast's People

Contributors

varbhat avatar

Stargazers

 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.