Skip to content

Latest commit

History

8 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

basic.c

A comprehensive (and small) BASIC language interpreter implementation in C that supports classic BASIC programming features and syntax.

Features

Core Language Support

  • Variables: Numeric and string variables with automatic type detection
  • Data Types: Numbers (double precision) and strings
  • Operators: Arithmetic (+, -, *, /, ^, MOD), comparison (=, <>, <, <=, >, >=), and logical (AND, OR, NOT)
  • String Operations: Concatenation and comparison

Control Flow

  • Conditional Statements: IF-THEN with support for both statement execution and line jumps
  • Loops: FOR-NEXT loops with optional STEP values (including negative steps)
  • Jumps: GOTO for unconditional jumps to line numbers
  • Subroutines: GOSUB and RETURN for subroutine calls

Built-in Functions

  • Mathematical: ABS(), SIN(), COS(), TAN(), SQR(), INT(), RND()
  • String Functions: LEN(), VAL(), STR$(), CHR$(), ASC()

I/O Operations

  • Output: PRINT with support for expressions, separators (, for tabs, ; for no separation)
  • Input: INPUT with optional prompts for user data entry
  • Comments: REM for program documentation

Program Management

  • Line Numbers: Traditional BASIC line numbering system
  • Program Loading: Load and execute BASIC programs from files
  • Interactive Mode: Direct command execution and program development

Usage

Command Line

# Run a BASIC program from file
basic.exe program.bas
# Start interactive mode
basic.exe

Interactive Mode Commands

  • RUN - Execute the loaded program
  • LIST - Display program lines
  • VARS - Show variables in memory
  • NEW - Clear program and variables
  • HELP - Show available commands
  • QUIT or EXIT - Exit the interpreter

BASIC Syntax Examples

Variables and Arithmetic

10LET A =1020LET B =530PRINT"A + B = "; A + B
40PRINT"A ^ B = "; A ^ B

String Operations

10LETNAME$ ="World"20PRINT"Hello "+NAME$ +"!\n"30PRINT"Length: "; LEN(NAME$)

Control Flow

10FOR I =1TO10 STEP 220PRINT I; " ";
30NEXT I
40PRINT"\n"50IF A > B THENPRINT"A is greater\n"60IF A < B THENGOTO100

Subroutines

10GOSUB100020PRINT"Back from subroutine\n"30END1000PRINT"Inside subroutine\n"1010RETURN

About

A comprehensive (and small) BASIC language interpreter implementation in C

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages