https://github.com/krzys9876/z80_basic
MS Basic interpreter in Scala
https://github.com/krzys9876/z80_basic
basic functional-programming immutability scala z80
Last synced: 4 months ago
JSON representation
MS Basic interpreter in Scala
- Host: GitHub
- URL: https://github.com/krzys9876/z80_basic
- Owner: krzys9876
- License: mit
- Created: 2022-07-05T21:13:03.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2022-09-26T11:09:56.000Z (about 3 years ago)
- Last Synced: 2023-03-10T09:36:46.007Z (over 2 years ago)
- Topics: basic, functional-programming, immutability, scala, z80
- Language: Scala
- Homepage:
- Size: 195 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# MS Basic Interpreter in Scala #
Following the Z80 simulator in Scala (https://github.com/krzys9876/z80_sim_scala), this is
a MS Basic interpreter to run similar programs. As always it's mostly for fun and for practicing
FP, immutability, class composition and parser combinators.
I did not intend to implement all Basic commands - the list is quite long but I realised that
actually most of my example programs use just a small portion of all available statements.
So I chose the core: printing, loop, jumps, conditionals.
My implementation is not strict, e.g. I did not put constraints on numbers, string length,
printing is a little different too bit overall the programs do what they are intended to.
I did not implement string operations at all as I hardly use them in Basic.
I've spent quite some time on parser combinators, learning and browsing for simple solutions.
I tried hard not to create a huge one-class-to-parse-them-all. This is where scala traits shine -
they allow separating logical bits from one another yet combining them seamlessly (just be aware of
circular dependencies).
## Keywords and functionality










This is enough to run tic-tac-toe (10x10) game, which was a test program for Z80 simulator.
## Program execution ##
I was wondering how to enable parameterized program execution, i.e. how to easily choose between
executing e.g. first X steps or finishing after Y seconds etc.
I came up with the idea of Iterator and Iterable classes (I know, the names are so general that they may be
easily confused...). Iterator simply runs a step method of a Iterable object and checks if the execution is over
by invoking an external function. Is it an overkill for this purpose? Well, it may be but this is
also a brain-teaser, and that's what fun projects are all about :smile:
This also enables different execution of test (i.e. always run a test program to an end and check the results)
vs runtime.