5 ms·
Bashforth: A Forth interpreter, written as bash script
- sudobash1 5y agoMy brother just finished writing a forth like interpreter for a freshman CS project (in java, not Bash, thankfully). It is a really nice language for learning the basics of an interpreter without worrying about the parser side too much.
- shadowofneptune 5y agoNow that I think about it, the grammar is entirely regular, yes?
- Someone 5y agoI’m not sure Forth has a grammar in the traditional sense. I think any grammar needs to cover immediate words because you cannot ignore CREATE… DOES>. Those can do anything, so how do you handle them? There’s also BASE (the current number conversion radix). It makes parsing integers context-dependent.
- codr7 5y agoIt's just a stream of tokens, which are either literals or identifiers; it's the only language I know that has less syntax than Lisp.
- vitiral 5y agoAnd "tokens" are literally "any string of non whitespace characters." One of it's biggest downfalls imo is that the toeknizer is too simple. I'm making GitHub.com/civboot/fngi as a "better than forth".
- codr7 5y agoOh, I've been down that rabbit hole for a long, long time :) It makes a nice foundation for syntactic experiments. https://github.com/codr7/gfoo https://github.com/codr7/gfoo https://github.com/codr7/forthy2 https://github.com/codr7/forthy2
- zengargoyle 5y agoForth is a really nice language for learning raw machine code then adding an assembler then moving up to a HLL in a few printed pages of code. The ultimate macro assembler. Back in 1986 teenage me found this library book that described Forth as "a ball of mud" which later made sense. A small core of machine specific bits form the core, you have to make that by hand. Then you accumulate and write an assembler on top of that. Then there's the I/O and logistics of the system. Then there's the whole interpreter/compiler all the same. It's the ultimate bootstrap. From laying down bytes in memory to a hybrid interpreter/compiler that you can say "take this word and make it a thing" and it can fart out this little polished turd. Forth is a ball of mud that you start at the beginning and at the end you end up with a shiny turd of a https://en.wikipedia.org/wiki/Dorodango https://en.wikipedia.org/wiki/Dorodango. Forth is bottom up insted of top down. The concepts teaching/learning wise start at the bottom and lead up to the top. You can't learn that starting with Python or Fortran or C or BASIC, or even Assembler. Bottom up. Forth might not be the best Pascal/Basic/Python learning some stuff language, but Forth is the best bits in memory to HLL "full-stack" language. I wish your brother had done it on raw hardware instead of in Java. It is a really nice language for learning.
- cachvico 5y ago"Bash and forth" would be a good name Edit: I'll get me coat
- daenz 5y agoCan someone explain to me why people are writing complex systems in Bash? It seems to be somewhat of a joke/meme, but I am having a hard time understanding why someone would put so much effort into a joke. Another recent example: https://news.ycombinator.com/item?id=29648135 https://news.ycombinator.com/item?id=29648135
- ColinWright 5y agoSame reason why people write non-trivial programs in any of the esoteric languages ... in part it's a challenge, in part it's a demonstration of cool techniques, and in part it's a demonstration of your skills. For them it's fun, for the readers it's a view into a weird world. Maybe it's just not for you, but not everything has to be for you.
- daenz 5y agoAre you saying there is credibility/virtue in making something deliberately difficult to build, read, and maintain, in the absence of real constraints?
- bendbro 5y agoYes, compare it to art.
- sharkbot 5y agoPart of what attracted me to technology, computers, programming, etc is the ability and freedom to tinker and experiment with ideas. If I’m building something professionally, then difficulty in building, reading and maintaining is a problem. If I’m building something to learn or to be creative, I don’t worry about how difficult it is to build or read or maintain: my aim is different, and therefore so are my concerns.
- ColinWright 5y agoAre you saying that there's no value in demonstrating the skill to create something that many, perhaps most, programmers would say is impossible? Have you looked at the code? It's beautifully laid out, extremely readable, and completely maintainable. If you don't know bash it's a great example of how to create a reasonably complex program that's designed to be read and maintained. And finally, yes, when taken as an opportunity to improve your skills, absolutely there is value in creating something as a vehicle for developing your abilities, to demonstrate to others that you have those skills, and quite simply, as a challenge.
- chubot 5y agoI added this to https://github.com/oilshell/oil/wiki/The-Biggest-Shell-Programs-in-the-World https://github.com/oilshell/oil/wiki/The-Biggest-Shell-Progr... although there are a lot of whitespace and comments to get up to ~3800 lines. The biggest shell scripts in the world seem to be about 10x bigger, around ~30K lines. Feel free to add any "program" that's more than 10K lines, and smaller ones if they are "interesting". (That's subjective, but I think a Forth qualifies.)
- bendbro 5y agoTangentially related, but I have found making good use of local, functions, and jq (for structured data) makes large bash programs significantly more viable. The nice thing about using bash is it implies the program is intended to be quick and dirty, and easy to deploy. Users might have to get their hands dirty- and they can since it is interpreted and interactive. Code reviewers usually respect this and don't hang you out to dry.
- lurker58w48i 5y ago