From: decwrl!decvax!bellcore!allegra!ulysses!mhuxr!ihnp4!houxm!houxu!jhv

Article 165 of net.lang.forth:
Relay-Version: version B 2.10.2 9/18/84 SMI; site sun.uucp
Posting-Version: version B 2.10 5/3/83 based; site houxu.UUCP
Path: sun!decwrl!decvax!bellcore!allegra!ulysses!mhuxr!ihnp4!houxm!houxu!jhv
>From: [email-masked] (James Van Ornum)
Newsgroups: net.lang.forth
Subject: Re: redefine "+" ??
Message-ID: <[email-masked]>
Date: 8 Feb 85 01:14:30 GMT
Date-Received: 9 Feb 85 02:00:16 GMT
References: <[email-masked]>
Organization: AT&T-Bell Laboratories
Lines: 59

Michael Stolowitz presented the paper "Algebraic Expression Evaluation in
FORTH" at a Computer Faire (I don't know which year - just that it was 1982
or later) with the following screens to convert infix notation to
postfix for evaluation:

	0 ( ALGEBRAIC )
	1 CREATE OP  44 ALLOT
	2
	3 : ?INTERP ( pfa -- ) CFA STATE @ IF , ELSE EXECUTE THEN ;
	4
	5 : OPP@    ( -- addr ) OP DUP @ + ;
	6
	7 : >OP     ( pfa lev -- ) 4 OP +! OPP@ 21 ;
	8
	9 : OP>     ( -- ) OPP@ 2@ -4 OP +! DROP ?INTERP ;
       10
       11 : LEV?    ( -- lev ) OPP@ @ ;
       12
       13 : ]A      BEGIN LEV? WHILE OP> REPEAT
       14           [COMPILE] FORTH ; IMMEDIATE
       15 -->

	0 ( ALGEBRAIC )
	1 : INFIX ( lev -- )  ( old rpn op   new infix op )
	2    '  CREATE  SWAP  ,  ,  IMMEDIATE
	3       DOES> 2@ BEGIN DUP LEV? > NOT WHILE
	4          >R >R   OP>  R> R>  REPEAT  >OP ;
	5
	6 VOCABULARY ALGEBRAIC IMMEDIATE ALGEBRAIC DEFINITIONS
	7
	8 7 INFIX * *    7 INFIX / /
	9 6 INFIX + +    6 INFIX - -
       10 5 INFIX > >    5 INFIX < <    5 INFIX = =
       11 4 INFIX NOT NOT
       12 3 INFIX AND AND
       13 2 INFIX OR  OR
       14
       15 -->

	0 ( ALGEBRAIC )
	1 : (  ['] CR  1  >OP ; IMMEDIATE
	2
	3 : )  FORTH  BEGIN  1 LEV? < WHILE OP> REPEAT
	4      1  LEV? = IF -4 OP +!
	5                ELSE  1 ABORT" Missing (" THEN ; IMMEDIATE
	6
	7 FORTH DEFINITIONS
	8
	9 : A[   0 OP !  [COMPILE] ALGEBRAIC ; IMMEDIATE        EXIT
       10
       11 Examples:      A[  A  +  B  -  C  *  (  D  /  A  )  ]A
       12
       13   or    : EXPR A[  A  +  B  -  C  *  (  D  /  A  )  ]A ;
       14
       15

-----------------------
	James Van Ornum, AT&T Bell Laboratories, inhp4!houxu!jhv