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.
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!
- 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.
- Added input, chgdir, chgvol, listdir, and printdir commands.
- Added line-concatenation operator (;) to input and print commands.
- Commands are now case insensitive.
> print "Hello"
Hello
> PRINT "from"
from
> Print "ClifferBasic"
ClifferBasic
- Add support for arrays via the
dim
command. - Add
data
andread
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.
- Most BASIC commands will only work inside the REPL and not necessarily from the shell command line. This is an issue in Cliffer.
Clear the screen
> cls
Change the current directory
> chgdir "/home/mydir"
> printdir
/home/mydir
> listdir
<DIR> .config
<DIR> repos
hello.bas
Change the current volume
> chgvol "d:"
> printdir
D:\
> listdir
<DIR> MyStuff
<DIR> Source
hello.bas
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 the execution of a program
> 10 print "A bit"
> 20 end
> 30 print "A bit more"
> run
A bit
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
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
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
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
Accept input from the user
> input "What is your name"; name$
What is your name? Slartibartfast
> print name$
Slartibartfast
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 the current program in memory.
> 10 print "Hello, World!"
> 20 end
> list
10 print "Hello, World!"
20 end
List the contents of the current directory
> chgdir "/home/mydir"
> printdir
/home/mydir
> listdir
<DIR> .config
<DIR> repos
hello.bas
Load a program from persistent storage.
> load "hello.bas"
> list
10 print "Hello, World!"
20 end
> run
Hello, World!
Clear the current program from memory
> 10 print "Hello, World!"
> run
Hello, World!
> new
> list
> run
>
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 text to the screen or evaluate an expression.
> print "Hello, World!"
Hello, World!
> print x + y#
7.5
> print z$
foo
Print the name of the current directory.
> chgdir "/home/mydir"
> printdir
/home/mydir
Add a comment to the program.
> 10 rem This is a comment
> 20 print "This is a command"
> run
This is a command
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 the program currently in memory.
> 10 print "Hello, World!"
> 20 end
> run
Hello, World!
> save "hello.bas"
> run "hello.bas"
Hello, World!
Save the current program to persistent storage.
> 10 print "Hello, World!"
> 20 end
> save "hello.bas"
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.
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