1. Forth in Euphoria

David Cuny wrote in response to Kat:


> Coding a FORTH-like language in Euphoria would be fairly easy. Since FORTH
> is a threaded language, code body is simply stored as a list of jump
> addresses. Instead, Euphoria could store the code body as a list of
indexes.
> Built-in routines could be indicated by negative values.
>
> For example, here's a Euphoria routine:
>
>    procedure foo( integer n )
>       ? n + 12
>    end procedure
>
> Here's essentially the same code in FORTH:
>
> : foo 12 + . ;
>
> Arguments are passed on the stack. Operations are reverse polish notation.
> In this case, the literal 12 is pushed on the stack, the two top items are
> added, and then the top of stack is popped and displayed.
>
> Encoded in Euphoria, it might look like this:
>
>    { "foo", LITERAL, 12, PLUS, DOT }
>
> With this sort of approach, coding a TIL (threaded interpreted language)
is
> pretty easy. The problem with FORTH is that RPN is quite klunky to work
> with, and stack operations can get tricky if there are more than 4 values
on
> the stack.
>
> FORTH has some very baroque string operators; you would probably want to
> define your own, since Euphoria would give you much more flexible handling
> of strings.
>

This is a very similar to an abandoned project of mine.  In addition, I was
using an EDS database to store the definitions which would be loaded into
memory at first use.  Thus a script not using "foo" wouldn't waste RAM for
it.  Maybe I'll work on this some more.

-- Mike Nelson

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu