VolksForth

infix
Login

Infix Interpreter by Bernd Paysan

adapted for VolksForth

\ Infix Interpreter by Bernd Paysan
\ published in "Vierte Dimension"
\ December 1991 - www.forth-ev.de

CR .( loading INFIX Interpreter ) CR

\needs cells ' 2* alias cells
\needs cell+ ' 2+ alias cell+

Vocabulary infix   infix ALSO DEFINITIONS

| VARIABLE op  $10 cells allot
| : op@ ( -- addr ) op dup @ cells + ;
| : >o  ( o -- ) 1 op +! op@ ! ;
| : o>  ( -- o ) op@ @ -1 op +! ;
| : prio@ ( -- prio ) op@ @ @ ;
| : op, ( -- ) o> cell+ @ state @ IF
      , ELSE execute THEN ;

: in ( cfa priority -- )
   >in @ ' -ROT >IN ! 
   CREATE , , immediate
   DOES> 
     DUP >R @ 0 MAX >R 
     BEGIN
       prio@ R@ < 0= 
     WHILE 
       op,
     REPEAT
     rdrop r> >o ;

' ! ALIAS =:
| : := swap ! ;
| ' noop ALIAS ((

20 in +
20 in -
21 in *
21 in /
21 in mod
21 in max
21 in min
10 in =
10 in >
10 in <
02 in or
03 in and
03 in not
02 in xor
01 in :=
01 in =:
| -1 in ((

| : unbalanced 
    ABORT" unbalanced Expression!" ;
   
: ( 
  [ ' (( >body ] 
  LITERAL >o ; IMMEDIATE

: )
  op @ 0= unbalanced [compile] (( 
  o> o> 2drop ; IMMEDIATE

: $ 
  toss [compile] ) 
  op @ unbalanced ; IMMEDIATE

FORTH DEFINITIONS INFIX

: $ 
  op off also infix
  [compile] ( ; IMMEDIATE

ONLYFORTH

CR .( INFIX loaded. ) CR