Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Forth > Creative with w...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 1 Topic 3751 of 4160
Post > Topic >>

Creative with wordlists.

by Albert van der Horst <albert@[EMAIL PROTECTED] > Feb 7, 2008 at 02:12 PM

The other day I thought about implementing conditional
compilation with state information stored into the
wordlist stack. So we get by with one control structure,
an IF.
In the following VOCABULARY is a defining word that pushes
a wid, like so (untested)

: VOCABULARY CREATE WID , DOES> >R GET-ORDER 1+ R> @[EMAIL PROTECTED]
 SWAP SET-ORDER ;

And ALIASED takes an execution token and a string and creates
a definition with that name and the same execution behaviour.

PREFIX matches a word if it starts with the prefix.

The code below is to convey the idea. It has not been tested.

\ ---------------------------
VOCABULARY SKIPPING-TE
SKIPPING-TE DEFINITIONS PREVIOUS
'NOOP "" ALIASED   PREFIX
'PREVIOUS "[ELSE]" ALIASED
DEFINITIONS

VOCABULARY SKIPPING-TT
SKIPPING-TT DEFINITIONS PREVIOUS
'NOOP "" ALIASED   PREFIX
'PREVIOUS "[THEN]" ALIAS
DEFINITIONS

: [IF] 0= IF SKIPPING-TE THEN ;
: [ELSE] SKIPPING-TT ;
: [THEN] ;

DEFINITIONS
\ ---------------------------

So while (skipping till then)
        SKIPPING-TT
is the topmost wid, only
   [THEN]
is recognized, and other words are ignored, because they match
the prefix.

In ugly Forths you may have to replace 'NOOP by
' NOOP (or ['] NOOP , I always forget) and
"[THEN]" by S" [THEN]" ).

Groetjes Albert

--
-- 
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- like all pyramid schemes -- ultimately falters.
albert@[EMAIL PROTECTED]
 &=n http://home.hccnet.nl/a.w.m.van.der.horst
 




 1 Posts in Topic:
Creative with wordlists.
Albert van der Horst <  2008-02-07 14:12:18 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 18 22:37:43 CDT 2008.