Skip to content

toth-matus/MiniBasicInterpreter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

63 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MiniBasic Interpreter - User Documentation

Prerequisites

This project is meant to be run using .NET 9 and C# 13.

Usage

To interpret your MiniBasic source files (.mb) run the following command in the project root directory:

dotnet run NAMES_OF_SOURCE_FILES_SEPARATED_BY_SPACES

The interpreter will then interpret the given program. If a file is inaccessible, due to any reason, its parsing will be skipped without stopping the interpreter.

MiniBasic language 'standard'

Types

  • INTEGER - %
    • Their size will be 32-bit
  • STRING - $
  • Arrays - []
    • Only arrays of INTEGERs %[] and STRINGs $[] are supported
    • Arrays are indexed from 0, cannot be multidimensional
    • Only basic indexing is supported

Operators

  • For INTEGER: +, -, *, /, MOD
  • For STRING: +, LEN%, MID$
  • For Arrays: []

Variables

Variables are declared using the DIM keyword. Variables are strongly typed, their names are case-sensitive and must satisfy the regex: ^[a-zA-Z_][a-zA-Z0-9_]*$.

Input/Output

  • INPUT will be used to read from the standard input (no ; joining of PRINTs and without the LINE specifier)
  • PRINT will be used to print variables to the standard output (no ; joining of PRINTs)

Subprocedures (SUB) and functions (FUNCTION)

  • No forward declarations are allowed

  • SUB/FUNCTION parameters are passed by reference and must be strongly typed

  • SUB/FUNCTION can only see parameters inside their scope

  • No SUB/FUNCTION can be defined inside another SUB/FUNCTION

  • Each SUB/FUNCTION must have a unique name and their name must also satisfy the variable name regex

  • SUBs are called with the CALL keyword with their parameters between ( and )

  • SUB cannot return any value

  • Return type for FUNCTION must be strongly typed as well, and it can only return INTEGER or STRING

Labels and GOTO statement

Each label must be defined on a new line. Label names must satisfy the regex : ^[a-zA-Z_][a-zA-Z0-9_]*:$, similar to variables, but their definition must end in :.

GOTO is used to jump to label using its name.
Without the trailing :.

GOTO cannot jump outside current SUB/FUNCTION body.

If-else (IF THEN ELSE) statements

Only block statements are supported, no single line IF THEN ELSE statements are allowed.

Branching with ELSEIF is allowed as well.

Variables defined inside a block are not accessible from other blocks.

For loop (FOR TO NEXT)

The index variable is implicitly declared, do not re-declare it. The NEXT keyword must be followed by the index variable.

No extra restrictions, STEP statement is allowed as well.

Variables defined inside FOR loop are not accessible from outside.

Program entry point

  • The first source code outside any SUB/FUNCTION body will be considered as the entry point
  • The entry point will end with the first SUB/FUNCTION body definition or with the end of file

Comments

Comments are declared using the REM keyword.

Error handling

Any incorrect usage (invalid variable name, out-of-bounds indexing, GOTO to non-existent label, ...) will result in stopping the interpretation and an error message.

Examples

To get to know the language more try some example programs, you can find them in ./examples.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages