Coder Social home page Coder Social logo

unwiredben / my_basic Goto Github PK

View Code? Open in Web Editor NEW

This project forked from paladin-t/my_basic

0.0 1.0 0.0 31.07 MB

Lightweight BASIC interpreter written in standard C in dual files. Aimed to be embeddable, extendable and portable.

Home Page: http://paladin-t.github.io/my_basic/

License: MIT License

C 98.92% Batchfile 0.09% Makefile 0.09% HTML 0.89%

my_basic's Introduction

 _____ __ __     _____ _____ _____ _____ _____ 
|     |  |  |___| __  |  _  |   __|     |     |
| | | |_   _|___| __ -|     |__   |-   -|   --|
|_|_|_| |_|     |_____|__|__|_____|_____|_____|

Copyright (C) 2011 - 2019 Wang Renxin

Build status MIT license

Web playground

Contents

Introduction

MY-BASIC is a lightweight BASIC interpreter written in standard C in dual files. It's aimed to be embeddable, extendable and portable. It is a dynamic typed programming language, reserves structured syntax, supports a style of prototype-based programming (OOP), also implements a functional paradigm by lambda abstraction. The core is written in a C source file and an associated header file. It's easy to either use it as a standalone interpreter or embed it with existing projects in C, C++, Java, Objective-C, Swift, C#, etc. and totally customizable by adding your own scripting interfaces.

Main features

MY-BASIC offers a wide range of features including:

  • Written in standard C, source code is portable to a dozen of platforms
  • Lightweight (within less than 128KB footprint), fast, and configurable
  • With both retro and modern BASIC syntax
  • Case-insensitive tokenization, and many other indelible BASIC flavour
  • Unicode support
  • Prototype-based programming, with reflection support
  • Lambda abstraction enhanced functional programming
  • Customizable referenced/non-referenced usertype
  • Collection construction and manipulation functions for LIST and DICT
  • Automatic releasing for referenced values (prototype, lambda, referenced usertype, list, dictionary, etc.) benefited from reference counting and garbage collection
  • Common numeric and string functions
  • Structured sub routine definition with the DEF/ENDDEF statements
  • Structured IF/THEN/ELSEIF/ELSE/ENDIF
  • Structured FOR/TO/STEP/NEXT, FOR/IN/NEXT, WHILE/WEND, DO/UNTIL
  • Reserved retro GOTO, GOSUB/RETURN
  • Importing multiple source files with the IMPORT statement
  • Debug API
  • Customizable memory pool
  • Easy API, for extending new BASIC functions
  • Easy interacting BASIC facilities at native side, and vice versa
  • More features under development

BASIC8

Get BASIC8 - the fantasy computer powered by MY-BASIC - on Steam for game and other program development in an integrated environment.

See awesome user creations.

BASIC at a glance

A "Hello World" convention in MY-BASIC:

input "What is your name: ", n$

def greeting(a, b)
	return a + " " + b + " by " + n$ + "."
enddef

print greeting("Hello", "world");

Read the MY-BASIC Quick Reference to get details about how to program in MY-BASIC.

Installation

Using standalone interpreter binary

This repository contains precompiled binaries for Windows and macOS, the easiest way is to download to get a direct playground. Or you can make a build by:

  • Using the Visual Studio workspace my_basic.sln on Windows to build an executable
  • Using the Xcode workspace my_basic_mac.xcodeproj on macOS to build an executable
  • Using the makefile on *nix OS to build an executable

Follow these steps to compile an interpreter binary manually for any platform:

  1. Retrieve everything under the core and shell folders for a minimum build
  2. Setup your toolchain for compiling and linking
  3. Compile core/my_basic.c and shell/main.c, with both including core/my_basic.h; then link up an executable

The standalone interpreter supports three running modes:

  • Execute the binary without arguments to use the interactive mode
    • Type "HELP" and hint Enter to get usages of it
  • Pass a file to the binary to load and run that BASIC source code
  • Pass an argument -e followed with an expression to evaluate and print instantly as a simple calculator, eg. -e "2 * (3 + 4)"

Combining with existing projects

Just copy core/my_basic.c and core/my_basic.h to your project and add them to the build configuration. You can link with MY-BASIC as a lib as well.

For details about using MY-BASIC after integration, see MY-BASIC Quick Reference and read the Wiki pages.

It's recommended to know the basic principle of MY-BASIC before customizing; nothing's better than a workflow diagram to get a first image.

A simple setup as follow:

#include "my_basic.h"

int main() {
	struct mb_interpreter_t* bas = NULL;

	mb_init();
	mb_open(&bas);
	mb_load_string(bas, "print 22 / 7;", true);
	mb_run(bas, true);
	mb_close(&bas);
	mb_dispose();

	return 0;
}

The manual explains most of the fundamental topics, however it doesn't cover everything; read the Wiki as supplement instructions, such as machinism behind MY-BASIC, efficient practice, etc:

Donate

List of donors.

Consider supporting MY-BASIC development with a donation if you like this project.

One-off donation via PayPal.

my_basic's People

Contributors

paladin-t avatar wwiv avatar unwiredben avatar wangrenxin avatar

Watchers

James Cloos 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.