Skip to content
heklietPublic

About

Hekliet Tiny BASIC Compiler

Resources

Stars

4 stars

Watchers

0 watching

Forks

Latest commit

 

History

28 Commits

Folders and files

Repository files navigation

Hekliet Tiny BASIC Compiler

This is a compiler for the language Tiny BASIC as described here.

The compiler deviates a bit from the grammar given in the Wikipedia article in order to accomodate Tiny BASIC source code found in the wild. The changes are:

  • Line numbers are optional.
  • Expression lists may use either comma or semicolon as separator.
  • THEN is optional in IF statements.
  • LET is optional in assignment statements.
  • The RND() keyword is supported.

The compiler produces x64 assembly code which is assembled using NASM and then linked using gcc. Only Linux is supported. (The generated code makes calls into libc.)

As it is a compiler, it has no way of knowing at compile time what an expression evaluates to, therefore GOTO <expression> and GOSUB <expression> are not supported. The USR() keyword is also not supported.

Usage

Requires nasm.

tbc is a shell script which drives the compilation. It invokes tbc.py (the compiler), then NASM, and finally gcc to link the resulting object file with tinylib, which contains the functions for user input and clearing the screen.

When you have a BASIC source file named example.bas, you may invoke tbc by issuing

./tbc example.bas

or

./tbc example

Either will work. Provided there is no error, an executable file named example will be produced.

Invoking tbc from outside the directory where it resides also works, so long as tinylib.c is in the same directory as tbc.

Examples

With the exception of test.bas, the examples are not by me.

About

Hekliet Tiny BASIC Compiler

Resources

Stars

4 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages