__ __ __ __ _______ _______ _______ ___ _______
| |_| || | | | | _ || _ || || | | |
| || |_| | ____ | |_| || |_| || _____|| | | |
| || ||____| | || || |_____ | | | |
| ||_ _| | _ | | ||_____ || | | _|
| ||_|| | | | | |_| || _ | _____| || | | |_
|_| |_| |___| |_______||__| |__||_______||___| |_______|
Copyright (C) 2011 - 2016 Wang Renxin. All rights reserved.
Why were other script interpreters so complex? Why was it so difficult to integrate with them and use the API? Why not try MY-BASIC today! Script had never been so simple and enjoyable.
- Introduction
- Compatibility
- Main features
- Script at a glance
- Interpreter workflow diagram
- Installation
- Wiki
- References
- Support the MY-BASIC project
MY-BASIC is a lightweight cross-platform easy extendable BASIC interpreter written in pure C with less than twenty thousand lines of source code. MY-BASIC is a dynamic typed programming language. It supports structured grammar, and implements a style of OOP called prototype-based programming paradigm, furthermore it offers a functional programming ability with lambda abstraction. It is aimed to be either an embeddable scripting language or a standalone interpreter. The core is pretty light; all in a C source file and an associated header file; simpleness of source file layout and tightness dependency make it feels extraordinarily tough. Anyone even C programming newbies could learn how to add new scripting interfaces in five minutes. It's able to easily combine MY-BASIC with an existing project in C, C++, Java, Objective-C, Swift, C# and many other languages. Script driven can make your projects more powerful, elegant and neat. It's also able to learn how to build an interpreter from scratch with MY-BASIC, or build your own dialect easily based on it.
It fits well on a large scale of Workstation, PC, Tablet, Pad, Mobile Phone, PDA, Video Game Console, Raspberry Pi, Intel Edison, Arduino and even MCU; totally portable to Windows, macOS, Unix, Linux, iOS, Android, RTOS, etc.
MY-BASIC is a dynamic typed programming language with BASIC syntax and has a very dynamic nature; it makes it easy to use and flexible. MY-BASIC offers a wide range of features including:
- It is totally free to use MY-BASIC for individual or commercial purpose under the MIT license
- Written in clean ANSI C, source code is portable for a dozen of platforms
- Lightweight (within memory usage less than 128KB), fast, and cuttable
- With most both retro and modern BASIC syntax
- Case-insensitive tokenization, and many other indelible BASIC feelings
- Unicode support
- Prototype-based programming (OOP) paradigm, with reflection support
- Lambda abstraction enhanced functional programming
- Dynamic typed integer, float point, string, boolean, user defined data types, etc. with array support
- Standard numeric functions, and standard string functions
- Referenced usertype support
- Collection implementation and manipulation functions for
LIST
andDICT
- Automatic releasing of referenced objects (list, dictionary, referenced usertype, prototype, lambda, etc.) benefited from Reference Counting and Garbage Collection
- Multiple source file support by
IMPORT
statement - Structured user customizable sub routine definition by
DEF-ENDDEF
support, including tail recursion optimization - Structured
IF-THEN-ELSEIF-ELSE-ENDIF
support - Structured
FOR-TO-STEP-NEXT/FOR-IN/WHILE-WEND/DO-UNTIL
support - Reserved retro
GOTO/GOSUB-RETURN
support - Debug APIs
- Customizable memory pool
- High expansibility, easy to use APIs, easy to write customized scripting interfaces
- Powerful interactive ability to manipulate script facilities at native side; or to use native functionalities in script, and vice versa
- More features under development
You may wondering if it's possible to introduce another feature to MY-BASIC, well, you may would like to take a look at this page.
Come along with a traditional "hello world" script in MY-BASIC:
print "What is your name: "
input n$
def foo(a, b)
return a + " " + b + " by " + n$ + "."
enddef
print foo("Hello", "world");
Read the MY-BASIC Quick Reference (especially the "Programming with BASIC" section) to get more details about how to program in MY-BASIC.
It's necessary to know some principle of MY-BASIC before doing deep customization; nothing is better than a workflow diagram to get a first impression.
More detail are issued in the Wiki pages.
This repository contains precompiled binaries for Windows and macOS, it's efficient to download one of them and have a first impressive playground. Or you could make a build as follow:
- Open the Visual Studio solution
my_basic.sln
on Windows to build an executable - Open the Xcode solution
my_basic_mac.xcodeproj
on macOS to build an MacOS executable - If you were using a *nix OS, then use the
makefile
with a "make" toolchain to build an interpreter binary according to your specific platform
To compile an interpreter binary for your own platform manually, please follow the steps:
- Retrieve at least
core
andshell
folders for a minimum build - Setup your compile toolchain configuration
- Compile
core/my_basic.c
andshell/main.c
, they both requirecore/my_basic.h
; then link up your own executable
The standalone interpreter supports three running modes:
- Execute the binary without arguments to enter MY-BASIC's interactive mode
- Pass a file path to the binary to load and run that script file directly
- Pass an argument
-e
followed by an expression to evaluate it and print the result, eg.-e "2 * (3 + 4)"
Type "HELP" and hint Enter under interactive mode to view full detail usage of the interpreter.
MY-BASIC is cleanly written in a single C source file and an associated header file. Just copy my_basic.c
and my_basic.h
to your project folder and add them to a build configuration.
You can definitely link with MY-BASIC as a lib as well.
For more details about using MY-BASIC when it has be integrated with a project, please see MY-BASIC Quick Reference or read the following Wiki pages.
The MY-BASIC Quick Reference includes most of the fundamental topics, however, it hasn't covered everything, such as the design principle, machinism behind MY-BASIC, effective practice, etc; all of them are issued in the Wiki:
- Principles
- Language design
- Passes
- Interpreter workflow diagram
- Code with MY-BASIC
- Support for Unicode
- Import another file
- Module (namespace)
- Sub routine
- Lambda abstraction
- Understanding data type system in MY-BASIC
- Collection manipulation
- Manipulate an array
- Automatic memory management
- Use usertype values
- Use prototype-based class
- Define a class in C
- Meta methods
- Override operators
- Override functions
- Standalone shell
- Extra functions
- Integration
- Link with MY-BASIC
- Write a debugger
- Callback
- Interop with C#
- Customization
- Customize macros
- Customize a memory allocator
- Redirect PRINT and INPUT
- Redefine int_t and real_t
- Customize an importer
- More scripting APIs
- String matching module
- String manipulation module
- File module
- Bit operation module
- Miscellaneous module
- Stack module
- FAQ
- Is it possible to introduce another feature