G2Basic 0.1.1 (1e793fc)
BASIC interpreter for microcontrollers
Loading...
Searching...
No Matches
G2Basic API

G2Basic is a small BASIC interpreter written in C for microcontrollers and other embedded hosts. A host program passes it one line at a time: numbered lines build a stored program, and other lines run immediately. This reference covers the public header g2basic.h and the internal backend hook. The source is on GitHub.

Guides

Guide Contents
Language reference Statements, expressions, commands, and limits
Embedding CMake integration, output, custom functions, and the API contract
Architecture Parser, program store, execution, and memory
Development Builds, options, tests, CI, and API documentation
C coding standard Style, memory, error handling, and documentation rules
Versioning SemVer rules, the public interface, and the changelog

API groups

Group Contents Header
Embedding API Setup and output, Custom functions, Execution g2basic.h
Internal interfaces Built-in function backends g2basic_math.h

The group tree is on the Topics page. The Examples page contains the interactive interpreter, a complete host program.

Minimal host

#include <stdio.h>
#include "g2basic.h"
static void print_text(const char* text) {
fputs(text, stdout);
}
int main(void) {
double result;
const char* error = NULL;
g2basic_init(print_text);
g2basic_parse("10 FOR I = 1 TO 3", &result, &error);
g2basic_parse("20 PRINT I, I * I", &result, &error);
g2basic_parse("30 NEXT I", &result, &error);
g2basic_parse("RUN", &result, &error); // 1 1, 2 4, 3 9
return 0;
}
Public API of the G2Basic interpreter.
int g2basic_parse(const char *input, double *result, const char **error)
Process one line of input.
void g2basic_init(void(*print_func)(const char *str))
Reset the interpreter and set the text output callback.