Discuss Scratch

BookOwl
Scratcher
1000+ posts

Scratching Forth, a compiler from Forth to Scratch

I have completed the first version of Scratching Forth, a compiler from Forth to .sb2 files.
You can find it, along with several example Forth programs, on Github

Thanks to @gtoal for letting me use the name Scratching Forth

Last edited by BookOwl (Aug. 12, 2016 18:45:08)


who needs signatures
-stache-
Scratcher
500+ posts

Scratching Forth, a compiler from Forth to Scratch

Did @gtoal use the name Scratching forth before you?


3x3 pb: 13.240
3x3 avg: ~21-26
BookOwl
Scratcher
1000+ posts

Scratching Forth, a compiler from Forth to Scratch

-stache- wrote:

Did @gtoal use the name Scratching forth before you?
Yes, one of his projects uses that name, so I asked him on his profile if I could use it, and he said yes

who needs signatures
gtoal
Scratcher
1000+ posts

Scratching Forth, a compiler from Forth to Scratch

It looks pretty good. Will you be implementing more 4th words so that you can compile existing programs or is this going to be your own forth-like language?

I know you took a deliberate decision to implement this as a compiler that generates json. Are you considering at all a forth environment entirely within Scratch with an editor for pages of code and an interpreter to run it? It wouldn't be as efficient but it would be more approachable than having to install a python environment.

The Scratch screen ought to map fairly well to a forth page (if forth is still structured that way?)

G
BookOwl
Scratcher
1000+ posts

Scratching Forth, a compiler from Forth to Scratch

gtoal wrote:

It looks pretty good. Will you be implementing more 4th words so that you can compile existing programs or is this going to be your own forth-like language?
Thanks! Yes, I'm planning on adding as many forth words as I can.

gtoal wrote:

I know you took a deliberate decision to implement this as a compiler that generates json. Are you considering at all a forth environment entirely within Scratch with an editor for pages of code and an interpreter to run it? It wouldn't be as efficient but it would be more approachable than having to install a python environment.

The Scratch screen ought to map fairly well to a forth page (if forth is still structured that way?)

G
That sounds like a really neat idea, I'll try it later.

who needs signatures
Firedrake969
Scratcher
1000+ posts

Scratching Forth, a compiler from Forth to Scratch

https://github.com/BookOwl/scratching-forth/blob/master/compiler.py#L13

Python has expected argument and return types?

'17 rickoid

bf97b44a7fbd33db070f6ade2b7dc549
BookOwl
Scratcher
1000+ posts

Scratching Forth, a compiler from Forth to Scratch

Firedrake969 wrote:

https://github.com/BookOwl/scratching-forth/blob/master/compiler.py#L13

Python has expected argument and return types?
Those are actually function annotations, and why they are not at all required, they can be used to help document a function's input and return types, and can be verified through a static type checker like mypy.

who needs signatures
Jonathan50
Scratcher
1000+ posts

Scratching Forth, a compiler from Forth to Scratch

What about writing a Forth to Scratch compiler in Forth and compiling itself?

Not yet a Knight of the Mu Calculus.
mobluse
Scratcher
100+ posts

Scratching Forth, a compiler from Forth to Scratch

I have implemented a FORTH-interpreter/compiler with REPL that also can run the kinds of compiled code Scratching Forth generates, but not exactly, but Scratching FORTH (in Python) could be modified.
https://scratch.mit.edu/projects/137676871/
These codes are in the sprite Compiled. One reason why the original code doesn't work is that my stacks are upside down, because then they look as the stacks in the classical book Starting FORTH.

Read an article about the FORTH here: https://scratch.mit.edu/discuss/topic/233532/
The instructions and notes on the project page are more updated, but the article is probably easier to read (I will update the article for newer versions).

It was very fun and educational to write a compiler in Scratch and from Scratch. I didn't look at any compiler code and just implemented the functions required for each chapter in the book Starting FORTH (it still misses file management and string functions). This FORTH-compiler was my first compiler. My first interpreter was PocketCalc: https://scratch.mit.edu/projects/13110194/

This FORTH has pen and noteblocks, and some other Scratch-specific features.

Last edited by mobluse (Feb. 12, 2017 09:41:40)


novice27b
Scratcher
1000+ posts

Scratching Forth, a compiler from Forth to Scratch

It's cool to see a Scratch thread on the front page of HN: https://news.ycombinator.com/item?id=13564754

i use arch btw
BookOwl
Scratcher
1000+ posts

Scratching Forth, a compiler from Forth to Scratch

novice27b wrote:

It's cool to see a Scratch thread on the front page of HN: https://news.ycombinator.com/item?id=13564754
I'm famous!

I guess this means I should start working on this again.

who needs signatures

Powered by DjangoBB