Skip to content

ClifferBasic is a sample program for the Cliffer CLI library that implements a very simple BASIC interpreter environment as a REPL (Read-Eval-Print Loop). This project demonstrates the usage of the Cliffer CLI library to build a custom command-line application with an interactive BASIC-like language interpreter.

License

Notifications You must be signed in to change notification settings

paulmooreparks/ClifferBasic

Repository files navigation

ClifferBasic

ClifferBasic is a sample program for the Cliffer CLI library that implements a very simple BASIC interpreter environment as a REPL (Read-Eval-Print Loop). This project demonstrates the usage of the Cliffer CLI library to build a custom command-line application with an interactive BASIC-like language interpreter.

Usage

To use ClifferBasic as a REPL, similar to a Commodore 64 or Apple ][ environment, just run the ClifferBasic executable.

paul@BARN:~$ clifferbasic
Cliffer Basic
bye, exit, goodbye  Exit the application
help, ?             Show help and usage information

> print "Hello, World!"
Hello, World!
>

You may run saved programs directly from the command line as well.

paul@BARN:~$ clifferbasic run "hello.bas"
Hello, World!

Features

  • Interactive REPL for executing BASIC-like commands.
  • Supports variable assignment and arithmetic operations.
  • Commands for listing, saving, and loading programs.
  • Extensible command structure using the Cliffer CLI library.

Recent Changes

27 July 2024

Commands are now case insensitive.

> print "Hello"
Hello
> PRINT "from"
from
> Print "ClifferBasic"
ClifferBasic

Roadmap

  • Add an input command.
  • Add support for arrays via the dim command.
  • Add data and read commands.
  • Implement : command separator.
  • Add structured-programming constructs like while/wend.
  • Add support for float variables (x!). Double, int, and string are currently supported.
  • Extend built-in help to show more of the syntax of the BASIC commands.

Known issues

  • Most BASIC commands will only work inside the REPL and not necessarily from the shell command line. This is an issue in Cliffer.

Commands

cls

Clear the screen

> cls

delete

Delete a line from a program

> 10 print "Hello"
> 20 print "World"
> 30 end
> delete 20
> list
10 print "Hello"
30 end
> del 30
> list
10 print "Hello"

end

End the execution of a program

> 10 print "A bit"
> 20 end
> 30 print "A bit more"
> run
A bit

for

Repeat a section of code for a number of times

> 10 for i = 1 to 10
> 20 print i
> 30 next i
> run
1
2
3
4
5
6
7
8
9
10
> 10 for i = 1 to 10 step 2
> run
1
3
5
7
9

gosub

Jump to a subroutine

> 10 let x = 5
> 20 gosub 60
> 30 let x = 25
> 40 gosub 60
> 50 end
> 60 rem Square a number
> 70 print x * x
> 80 return
> run
25
625

goto

Jump to a line and continue execution

> 10 goto 50
> 20 rem Square a number
> 30 print x * x
> 40 return
> 50 rem Execution continues here
> 60 let x = 5
> 70 gosub 20
> 80 let x = 25
> 90 gosub 20
> 100 end
> run
25
625

if

Take an action conditionally based on a Boolean evaluation

> if 1 = 1 then print "All is well"
All is well
> if (2 + 2) = 5 then print "Something is wrong"
> if (2 + 2) = 4 then print "All is well again"
All is well again

let

Assign a value to a variable. Default data type is double if no sigil is provided.

A % sigil indicates a double data type.

> let x% = 1.23

A # sigil indicates an integer data type.

> let x# = 1

A $ sigil indicates an string data type.

> let x$ = "Hello, World!"
> let x = 5.5
> print x
5.5
> let y# = 2
> print y#
2
> let z$ = "foo"
> print z$
foo

list

List the current program in memory.

> 10 print "Hello, World!"
> 20 end
> list
10 print "Hello, World!"
20 end

load

Load a program from persistent storage.

> load "hello.bas"
> list
10 print "Hello, World!"
20 end
> run
Hello, World!

new

Clear the current program from memory

> 10 print "Hello, World!"
> run
Hello, World!
> new
> list
> run
>

next

Return to the start of a for loop

> 10 for i = 1 to 10
> 20 print i
> 30 next i
> run
1
2
3
4
5
6
7
8
9
10

x

print

Print text to the screen or evaluate an expression.

> print "Hello, World!"
Hello, World!
> print x + y#
7.5
> print z$
foo

rem

Add a comment to the program.

> 10 rem This is a comment
> 20 print "This is a command"
> run
This is a command

return

Return from a subroutine

> 10 let x = 5
> 20 gosub 60
> 30 let x = 25
> 40 gosub 60
> 50 end
> 60 rem Square a number
> 70 print x * x
> 80 return
> run
25
625

run

Run the program currently in memory.

> 10 print "Hello, World!"
> 20 end
> run
Hello, World!
> save "hello.bas"
> run "hello.bas"
Hello, World!

save

Save the current program to persistent storage.

> 10 print "Hello, World!"
> 20 end
> save "hello.bas"

Project Structure

  • ClifferBasic.cs: Entry point of the application, sets up the command-line interface and services.
  • BasicReplContext.cs: Custom REPL context for handling command input and execution.
  • Commands: Directory containing all CLI command implementations.
  • Services: Directory containing supporting services.
  • Model: Directory containing models classes.

Example

Here's an example session with ClifferBasic:

> let x = 20.5
> let y# = 10
> print x + y#
30.5
> 20 print "World!"
> 10 print "Hello"
> 30 let x = 123
> 40 print x
> list
10 print "Hello"
20 print "World!"
30 let x = 123
40 print x
> save "program.bas"
> load "program.bas"
> run

About

ClifferBasic is a sample program for the Cliffer CLI library that implements a very simple BASIC interpreter environment as a REPL (Read-Eval-Print Loop). This project demonstrates the usage of the Cliffer CLI library to build a custom command-line application with an interactive BASIC-like language interpreter.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages