6 ms·
Show HN: PuffinBASIC – A cross-platform modern BASIC interpreter written in Java
GitHub: https://github.com/mayuropensource/PuffinBASIC https://github.com/mayuropensource/PuffinBASIC
BASIC (Beginners' All-purpose Symbolic Instruction Code) is a general-purpose high-level language from the 1960s. PuffinBASIC is an implementation of the BASIC language specification. PuffinBASIC conforms most closely to GWBASIC.
The purpose of this implementation is to learn how to write interpreters and resurrect an old programming language to work in modern ecosystem.
The interpreter is evolving fast and in near future, I wish to apply modern interpreter building techniques to it.
How it works?
1. PuffinBASIC's grammar is defined using antlr4.
2. At runtime, the user source code is parsed using antlr4 lexer+parser.
3. After parsing, an intermediate representation (IR) of the source code is generated. A symbol table keeps track of variables, scalars, arrays, etc. objects.
4. A runtime, processes the IR instructions and executes them.
Performance
PuffinBASIC is an interpreter, and it should not be expected to have very good performance characteristics. Certain operations such as PRINT USING, INPUT, etc. are not optimized for performance. I have not benchmarked PuffinBASIC primitives. That being said, we have written games with graphics in PuffinBASIC is work very well.
TESSEL - A 2D Tile Game written in PuffinBASIC
Source: https://github.com/mayuropensource/PuffinBASIC/blob/master/samples/tessel/tessel.bas https://github.com/mayuropensource/PuffinBASIC/blob/master/s...
Link to YouTube video demo: https://youtu.be/L8xkM-g3Zms https://youtu.be/L8xkM-g3Zms
Memory
PuffinBASIC runs within a JVM and can use as much memory as available for the JVM process.
Compatibility
PuffinBASIC is mostly compatible with Microsoft's GWBASIC. Graphics is supported using Java 2D graphics. PuffinBASIC will not support assembly instructions.
Data Types
PuffinBASIC has extended BASIC types and supports Int32, Int4, Float32, Float64, and String.
Reference: https://github.com/mayuropensource/PuffinBASIC https://github.com/mayuropensource/PuffinBASIC
- tuatoru 6y ago> Data Types PuffinBASIC has extended BASIC types and supports Int32, Int4, Float32, Float64, and String. That's hardly "extended". Where are decimals, arbitrary precision numbers, dates, datetimes, lists/sets/stacks, dictionaries, structured types, enumerated types? Let alone advanced types.
- srivastm 6y agoI am comparing with gwbasic types which was limited to in16, float, double and string. The only type from gwbasic I did not implement is decimal. This is an active project and I plan to add dict/set types soon. I may also add decimal type. Stay tuned. I don’t plan to add complex types in PuffinBASIC. If I do another language, then I might add these.
- srivastm 6y agoBtw, I totally agree with you. I should have said a minor improvement to gwbasic data types. Your comments made me also think about adding a few data types, specially decimal, dict and set.
- easytiger 6y agoIt's BASIC.
- srivastm 6y ago:)
- avyaya123 6y agoBASIC was my first programming language. Thanks!
- tjalfi 6y agoHave you considered submitting this to Show HN instead of Ask? You can email hn@ycombinator.com and ask dang to change the title.
- pavlov 6y agoI'm curious why you chose to extend GW-BASIC specifically? Out of the Microsoft BASIC dialects, QBasic would probably be familiar to a much larger audience, and is a substantially more modern language.
- srivastm 6y agoI learned gwbasic as my first programming language in 90s. After that I switched to C. So, I never made the transition to qbasic. The main reasons for this choice are love and familiarity. Now, that I look back at the language, I would clearly make a lots of changes to it. May be, the next language I implement will be much more modern!
- pavlov 6y ago"The main reasons for this choice are love and familiarity." That is indeed a fundamentally great reason to embark on a project. Congrats and best of luck!
- earthboundkid 6y agoI don't think BASIC is good as teaching language, and it's certainly no good as a practical language, so who is this for? Hobbyists, maybe, but then why not use PICO8 or something similar?
- stevekemp 6y agoI had fun writing my own BASIC - less advanced, as I had no graphics, but also designed to be embedded in golang applications. I accept that 99% of the software I publish will have zero users, so even if it's no good for others it is still rewarding for its own sake. As for why? Nostalgia. The first computer I owned was a ZX Spectrum that booted to BASIC. I loved it. I still love writing in BASIC, and I still play spectrum games under emulation at least once every few months. My BASIC is like this one, fun to write, fun to tinker with, and at the end of the day it doesn't matter if others don't care/like it too https://github.com/skx/gobasic https://github.com/skx/gobasic
- csdreamer7 6y ago> I don't think BASIC is good as teaching language I learned how to do loops and logic in Basic. C & C++'s syntax was just confusing to me when I was younger. A few days with Basic was all that I needed for the light bulb to go off in my head and work in C++.
- earthboundkid 6y agoThere are languages for teaching better than C or BASIC.
- srivastm 6y agoFor teaching in present time, I would start with Python, and may be for CS oriented students go to functional languages, e.g. scheme.
- srivastm 6y agoBASIC was my first programming language. Back in 90s I made tons on graphics game in it. It is also very close to assembly and can be made really fast. As a programming language, I agree it is not a good choice anymore. I was learning antlr4 and wanted to take it all they way to a working programming language. BASIC is an easy language to implement and I am familiar with it. Hence the choice. For my second language implementation, I would probably pick a better language. My goal is to make it feature complete: add sound support, more functions, array processing, may be add a few modern features like references, and then call it done. Then I want to focus on improving the IR and runtime machine.
- jcadam 6y agoCool. Now we just need LOGO on the JVM and I can fully relive my childhood coding days.
- srivastm 6y agoLOGO is very easy to implement. My son loves secret coders books and they are full of turtle graphics code. I myself never used logo. If I get more spare time, I will go for it.