ForthHub / discussion

Discussion repository for Forth enthusiasts.
118 stars 4 forks source link

Forth-inspired General Purpose Macro-Processor #48

Open rdrop-exit opened 7 years ago

rdrop-exit commented 7 years ago

Hi,

I've been a Forth enthusiast since the late 70s, but I am new to Github. It's nice to see there is so much Forth related activity here.

I've posted some code for a macro-processing text filter that I'm using as an alternative to Unix's m4 in some personal projects. Although it's written in c, it's Forth-like enough that it might be of interest to some here. https://github.com/rdrop-exit/backtick-macro-processor

Cheers

ChristerNilsson commented 7 years ago

Do you some sample code available?

On Fri, 23 Jun 2017 at 08:28, Mark W. Humphries notifications@github.com wrote:

Hi,

I've been a Forth enthusiast since the late 70s, but I am new to Github. It's nice to see there is so much Forth related activity here.

I've posted some code for a macro-processing text filter that I'm using as an alternative to Unix's m4 in some personal projects. Although it's written in c, it's Forth-like enough that it might be of interest to some here. https://github.com/rdrop-exit/backtick-macro-processor

Cheers

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/ForthHub/discussion/issues/48, or mute the thread https://github.com/notifications/unsubscribe-auth/ADRyi3vWVuocc03vZLnsimBJ3ccAZ2ciks5sG1r1gaJpZM4ODLxq .

-- Sent from my Nokia 3310

rdrop-exit commented 7 years ago

Do you some sample code available?

There are a few examples in the documentation draft: https://rdrop-exit.github.io/backtick-macro-processor/

Much of the macro processor itself is implemented as macros, the source for which can be found in the backtick.mac file in the repository.

Cheers

rdrop-exit commented 7 years ago

Here's an example that prints out the 99 bottles of beer song :-)

`'this-many-bottles  ( n -- n )
 `{`dup`dec`[[no more bottles]]`[[1 bottle]]`[[`dup`print bottles]]`ifa}  `new

`'one-less-bottles  ( n -- n-1 ) `{`dec`this-many-bottles}  `new

`stdout`
`99`{`
`this-many-bottles of beer on the wall, `this-many-bottles of beer.
Take one down and pass it around, `one-less-bottles of beer on the wall.

}`over`times`
No more bottles of beer on the wall, no more bottles of beer.
Go to the store and buy some more, 99 bottles of beer on the wall.