owoScript icon indicating copy to clipboard operation
owoScript copied to clipboard

Forth transpiler?

Open eekee opened this issue 4 years ago • 0 comments

Harro! (<.< >.>) I love the concept of this language, I had to take a peek when I stumbled on its esolangs wiki page. :D Looking at the README, I was struck by the similarity to Forth. That's a good thing in my books. I mean, why boast about mere Turing completeness when Forth was once a popular choice for operating systems! :D More seriously, writing transpilers between Forth and owoScript looks like a fairly simple task, many words have identical equivalents in standard Forth. I think the only tricky words to implement in Forth would be fetch push and pushdupe, but if the targetted Forth lets you see the stack base address, (usually S0 or sp0, but not standard,) they wouldn't be hard. (fetchdupe has an identical equivalent in pick.) Oh and there's not usually an equivalent for exp, but there are binary shifts. If performance matters at all, you might like to know that many modern Forths compile to native code, unlike Python. Gforth is one of these, and TIO supports it.

But all of this is rather subversive because you wanted to learn about writing a formal grammar. Forth needs no grammar. :D Whitespace-delimited words are read by word or parse, the compiler looks them up with words available to the programmer, and depending on whether the word should be compiled or run, it either compiles it into the current definition or runs it at compile time. The latter feature is very powerful: conditionals and loops are commonly implemented in Forth itself! So are comments, where a typical definition might be : ( [char] ) parse 2drop ;. I also like Forth because its simple syntax better supports domain-specific languages. But... I guess I shouldn't try too hard to seduce you away from fancy parsers and stuff. I have a bad habit of doing that to people. >:D I may well have a go at a Forth transpiler myself.

eekee avatar Feb 14 '21 03:02 eekee