Hacker News new | past | comments | ask | show | jobs | submit login
Show HN: PuffinBASIC – A cross-platform modern BASIC interpreter written in Java
36 points by srivastm 33 days ago | hide | past | favorite | 28 comments
GitHub: 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/s... Link to YouTube video demo: 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




I'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.


I 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!


"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!


Cool. Now we just need LOGO on the JVM and I can fully relive my childhood coding days.


LOGO 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.


I 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?


I 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


BASIC 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.


BASIC is great. Neat project! I'm just not a fan of line numbers.


Line numbers are optional in PuffinBASIC now, introduced labels, e.g. https://github.com/mayuropensource/PuffinBASIC/blob/master/s...


After writing the PuffinBASIC interpreter and a game, here are my initial comments on the BASIC language: 1. Drop line numbers and use Labels 2. Needs multi-line IF-THEN 3. Needs switch 4. Needs named subroutines with local scope, much like functions 5. Needs references (not pointers) 6. Drop variable suffix


Could be because I'm old and it's what I started with, but I can't see how BASIC isn't a great beginner language -- especially with regard to going from "0 to working code."

10 PRINT "John is awesome"

20 GOTO 10

..and now you've shown a child the power of complete control as well as the concept of infinity. I have not seen a remotely comparable demonstration for getting someone excited about programming in any other language.


I started in BASIC in the 80s. The olden days sucked!

- No good manuals! I lived in the sticks and had little access to the library. All I could do was flip through the GW-BASIC reference book. It sucked!

- Teaches bad habits. It took me years before I realized I was a bad programmer and was doing everything wrong!

- Not as powerful as a modern system. Modern stuff lets you easily sprites on the screen. That's 99.9% of what kids want to do! You can do a lot more, a lot more quickly with modern educational languages.

There are still big issues with distribution, but all things equal, it's way better to be a kid learning a modern language today than a kid learning BASIC in the 80s.


I worked on gwbasic in early 90s and I turned lack of Docs/resources to my advantage. I used to spend time thinking about different ways to solve a problem. Basic does teach some bad habits, but it also teaches basic control structures, debugging skills and problem solving. Later, when I switched to C/Java/C++, the old programming habits changed quickly. In modern times, I would recommend Python as a beginner’s language.


I agree. I had access to no other language in early 90s. I made tons of graphics games in gwbasic back then. I recently wrote a game in PuffinBASIC as well to relive old days: https://github.com/mayuropensource/PuffinBASIC/blob/master/s...

In modern languages, python is an excellent beginner’s language.


> 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++.


There are languages for teaching better than C or BASIC.


For teaching in present time, I would start with Python, and may be for CS oriented students go to functional languages, e.g. scheme.


VB.Net was my first language in 2010. The syntax made it really easy to pick up and make small projects on Windows. The ease of use made it pretty fun to play around with and learn new things.

I think learning a more popular language (like python) would have been more helpful, but as a teaching tool, VB was great and helped me quickly jump into those other languages.


Plenty of shareware programs have been written in BASIC. One example can be found at http://roevalley.com/newsbrowser/english/software.htm


Have you considered submitting this to Show HN instead of Ask?

You can email hn@ycombinator.com and ask dang to change the title.


I wasn’t aware if this. I will do. Thanks!


Added. Thanks for watching out for a fellow user!


> 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.


I 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.


Btw, 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.


It's BASIC.


:)




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact

Search: