All Projects â†’ nanoflite â†’ basic

nanoflite / basic

Licence: MIT license
📺 A from-scratch BASIC interpreter with a focus on being easy to extend and port.

Programming Languages

c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to basic

pythonvm-rust
An incomplete stackless interpreter of Python bytecode, written in Rust.
Stars: ✭ 65 (-1.52%)
Mutual labels:  interpreter
kiwi-8
CHIP-8 interpreter for Windows and MacOS
Stars: ✭ 16 (-75.76%)
Mutual labels:  interpreter
wizard-engine
Research WebAssembly Engine
Stars: ✭ 164 (+148.48%)
Mutual labels:  interpreter
wasm
A fast Pascal (Delphi) WebAssembly interpreter
Stars: ✭ 40 (-39.39%)
Mutual labels:  interpreter
lispy
LISP interpreter in Python
Stars: ✭ 31 (-53.03%)
Mutual labels:  interpreter
Tagha
Minimal, low-level, fast, and self-contained register-based bytecode virtual machine/runtime environment.
Stars: ✭ 101 (+53.03%)
Mutual labels:  interpreter
Xstate
State machines and statecharts for the modern web.
Stars: ✭ 18,300 (+27627.27%)
Mutual labels:  interpreter
EightBall
The Eight Bit Algorithmic Language for Apple II, Commodore 64 and VIC20
Stars: ✭ 17 (-74.24%)
Mutual labels:  interpreter
fundot
The Fundot programming language.
Stars: ✭ 15 (-77.27%)
Mutual labels:  interpreter
malbolge
A Malbolge implementation and interpreter in Rust.
Stars: ✭ 23 (-65.15%)
Mutual labels:  interpreter
clox
A virtual machine and a tree-walk interpreter for the Lox programming language in C89 🌀
Stars: ✭ 38 (-42.42%)
Mutual labels:  interpreter
sturdy
Sturdy is a library for developing sound static analyses in Haskell.
Stars: ✭ 49 (-25.76%)
Mutual labels:  interpreter
molt
Embeddable TCL Interpreter for Rust applications
Stars: ✭ 86 (+30.3%)
Mutual labels:  interpreter
StepULC
Efficient and single-steppable ULC evaluation algorithm
Stars: ✭ 15 (-77.27%)
Mutual labels:  interpreter
avaloni
Interpreter of the Avalon programming language.
Stars: ✭ 14 (-78.79%)
Mutual labels:  interpreter
NatsuLang
No description or website provided.
Stars: ✭ 96 (+45.45%)
Mutual labels:  interpreter
sigmastate-interpreter
ErgoScript compiler and ErgoTree Interpreter implementation for Ergo blockchain
Stars: ✭ 56 (-15.15%)
Mutual labels:  interpreter
pocketlang
A lightweight, fast embeddable scripting language.
Stars: ✭ 1,412 (+2039.39%)
Mutual labels:  interpreter
iris
The interpreter of ISLisp
Stars: ✭ 58 (-12.12%)
Mutual labels:  interpreter
snabl
a Lispy Forth in C++
Stars: ✭ 21 (-68.18%)
Mutual labels:  interpreter

BASIC

A from-scratch BASIC interpreter with a focus on being easy to extend and port.

asciicast

Introduction

This is a BASIC interpreter written from scratch in C. For the moment two architectures are supported, POSIX and AVR XMega via the avr-gcc toolchain.

Most of the common BASIC keywords are supported:

  • PRINT expression-list [ ; ]
  • IF relation-expression THEN statement
  • GOTO expression
  • INPUT variable-list
  • LET variable = expression
  • GOSUB expression
  • RETURN
  • FOR numeric_variable '=' numeric_expression TO numeric_expression [ STEP number ]
  • CLEAR, NEW
  • LIST
  • RUN
  • END
  • DIM variable "(" expression ")"
  • ABS, AND, ATN, COS, EXP, INT, LOG, NOT, OR, RND, SGN, SIN, SQR, TAN
  • LEN, CHR$, MID$, LEFT$, RIGHT$, ASC

Extend

It should be easy to register a new BASIC function, as shown here with a sleep function for the XMEGA.

register_function_1(basic_function_type_keyword, "SLEEP", do_sleep, kind_numeric);
...
int do_sleep(basic_type* delay, basic_type* rv)
{
  delay_ms(delay->value.number);
  
  rv->kind = kind_numeric;
  rv->value.number = 0;

  return 0;
}

Let's use that new keyword.

10 INPUT "YOUR NAME?", NAME$
20 CLS
30 FOR I=1 TO LEN(NAME$)
40 PRINT MID$(NAME$,I,1); 
50 SLEEP(500)
60 NEXT
70 PRINT

Port

It should be easy to port the interpreter to other architectures. As an example there is a port to an XMega 128A4U included using the Batsocks breadmate board.

Use

There is a simple REPL for the BASIC interpreter. You can use it in an interactive way, just as you would do on a 80's era computer.

 _               _
| |__   __ _ ___(_) ___
| '_ \ / _` / __| |/ __|
| |_) | (_| \__ \ | (__
|_.__/ \__,_|___/_|\___|
(c) 2015-2016 Johan Van den Brande
10 PRINT "HELLO"
20 GOTO 10

You can give it a BASIC file on the command line.

$> basic examples/diamond.bas
         *
        ***
       *****
      *******
     *********
    ***********
   *************
  ***************
 *****************
  ***************
   *************
    ***********
     *********
      *******
       *****
        ***
         *

You can also use the shebang operator to make standalone BASIC scripts

#!/usr/bin/env basic

10 RADIUS=10
20 FOR I=1 TO RADIUS-1
30 W=INT(RADIUS*SIN(180/RADIUS*I*3.1415/180))
40 PRINT SPC(RADIUS-W);:FOR J=1 TO 2*W:PRINT "*";:NEXT J:PRINT
50 NEXT I
$> ./examples/circle.bas
       ******
     **********
  ****************
 ******************
********************
 ******************
  ****************
     **********
       ******

It is easy to embed the interpreter into your own application.

  basic_init(2048, 512); // memory size, stack size
  basic_register_io(putchar, getchar);
  basic_eval("10 PRINT \"HELLO\"");
  basic_eval("RUN"); 
  basic_destroy();  

On OSX/POSIX you can use the 'BASIC_PATH' environment variable to set the folder used for loading and saving BASIC programs. The 'BASIC_PATH' defaults to '.'. BASIC programs are expected to end with '.bas'. You can use LOAD, SAVE, DELETE and DIR.

Copyright

(c) 2015 - 2016 Johan Van den Brande

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].