Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forth transpiler? #2

Open
eekee opened this issue Feb 14, 2021 · 0 comments
Open

Forth transpiler? #2

eekee opened this issue Feb 14, 2021 · 0 comments

Comments

@eekee
Copy link

eekee commented Feb 14, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant