Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #54254

Re: Recognizers

From Alex <alex@rivadpm.com>
Newsgroups comp.lang.forth
Subject Re: Recognizers
Date 2017-01-22 17:26 -0500
Organization A noiseless patient Spider
Message-ID <o63bfm$5al$1@dont-email.me> (permalink)
References <o61k4o$9he$1@dont-email.me> <2017Jan22.154253@mips.complang.tuwien.ac.at>

Show all headers | View raw


On 1/22/2017 09:42, Anton Ertl wrote:

>
>    b) Implement ]] ... [[ to have its own loop instead of the text
>    interpreter loop, like ] had in PolyForth.  That's somewhat against
>    the grain of Forth-94/2012, which explicitly standardized the
>    common interpreter loop.  But in any case, that's what is done in
>    <http://www.complang.tuwien.ac.at/forth/compat/macros.fs>.

With recognizers and a POSTPONE state of -2, an implementation of ]] [[ 
for macros is trivial; no interpreter loop is required; no special 
casing is required for literals; & anything that has a recogniser on the 
recogniser stack with a POSTPONE section is valid.

: foo ]] dup 42 = [[ ; immediate

Obviously, it also supports the much talked about

: end ]] exit then [[ ; immediate



\ Avoid having to write so many POSTPONEs; Instead of
\   POSTPONE a 10 POSTPONE LITERAL POSTPONE c
\ write
\   ]] a n c [[

   :noname -600 throw ; \ internal error
   :noname -600 throw ;
   :noname
     get-recognizers 1- set-recognizers drop
     -1 state ! ;
recognizer: r:macro ( --  )

: rec:macro ( addr u -- r:macro | r:fail )
     s" [[" compare if r:fail else r:macro then ;

: ]] ( -- )  \ switch into postpone state
   ['] rec:macro get-recognizers 1+ set-recognizers
   -2 state ! ; immediate



-- 
Alex

Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Recognizers Alex <alex@rivadpm.com> - 2017-01-22 01:42 -0500
  Re: Recognizers Matthias Trute <matthias.trute@gmail.com> - 2017-01-22 03:06 -0800
  Re: Recognizers anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-01-22 14:42 +0000
    Re: Recognizers Alex <alex@rivadpm.com> - 2017-01-22 17:26 -0500
    Re: Recognizers Bernd Paysan <bernd@net2o.de> - 2017-01-24 00:57 +0000
      Re: Recognizers anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-01-24 16:23 +0000
        Re: Recognizers Bernd Paysan <bernd@net2o.de> - 2017-01-24 21:47 +0000
  Re: Recognizers Alex <alex@rivadpm.com> - 2017-01-23 08:30 -0500
    Re: Recognizers Alex <alex@rivadpm.com> - 2017-01-23 08:57 -0500
    Re: Recognizers Matthias Trute <matthias.trute@gmail.com> - 2017-01-23 10:58 -0800
      Re: Recognizers Alex <alex@rivadpm.com> - 2017-01-23 14:45 -0500
      Re: Recognizers JennyB <jennybrien@googlemail.com> - 2017-01-27 15:05 -0800
    Re: Recognizers Alex <alex@rivadpm.com> - 2017-01-29 22:54 +0000
      Re: Recognizers JennyB <jennybrien@googlemail.com> - 2017-01-30 09:11 -0800
      Re: Recognizers anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-01-30 16:34 +0000
  Re: Recognizers Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2017-01-31 21:03 +0000
    Re: Recognizers albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2017-02-01 12:37 +0100

csiph-web