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


Groups > comp.lang.forth > #135163

Re: Recognizers vs Parsing words

From Ruvim <ruvim.pinka@gmail.com>
Newsgroups comp.lang.forth
Subject Re: Recognizers vs Parsing words
Date 2026-06-10 19:45 +0000
Organization A noiseless patient Spider
Message-ID <110cet7$100f2$1@dont-email.me> (permalink)
References (8 earlier) <110229l$23vm4$1@dont-email.me> <2026Jun7.152335@mips.complang.tuwien.ac.at> <1104ame$2m7kj$1@dont-email.me> <2026Jun8.070429@mips.complang.tuwien.ac.at> <1108pm8$3tgq9$1@dont-email.me>

Show all headers | View raw


On 2026-06-09 10:25, Ruvim wrote:
> 
> In general, recognizers are suitable in the following cases:
>    - the behavior cannot be implemented with a single word (as for a 
> string literal starter, numeric literals, etc);
>    - the recognizing of a lexeme (or the beginning of a construct) 
> should not depend on the search order (or be shadowed by words from the 
> search order);
>    - reuse of the Forth text interpreter for translating text by 
> different rules (especially, through nested input sources; for example, 
> `execute-parsing` can be implemented using the Recognizer API);
> 
> 
> Otherwise, using a parsing word is also perfectly suitable.
> 
> 
> Whether it is a parsing word or another construct, it is better if the 
> affected lexical block (its beginning and end) is visually marked.
> 
> Therefore, `to( foo )` is better than `to foo`.
> 


The case of `to( ... )`, if implemented using a nested call to the Forth 
text interpreter, falls into the third category — reusing the Forth text 
interpreter. However, we don't have a Forth text interpreter factor that 
would apply only to the next lexical block in the input source. And even 
if we did, it would not simplify the implementation, since in this case 
the contained lexemes must be translated in *reverse order*.


Furthermore, we currently cannot use recognizers (namely, the perceptor, 
the recognizer used by the Forth text interpreter) because we have 
neither `to` factors applicable to typed data objects (results of 
recognizers), nor `to` factors applicable to xt of 
`value`/`2value`/`fvalue` children and to local-id of local 
variables/values.

But if we do have the latter `to` factors, then using them and the 
perceptor, the word `to(` can be implemented as follows (with a bit of 
compatibility layer at the beginning):

   : equals ( sd1 sd2 -- flag ) compare 0= ;

   synonym take-lexeme-maybe parse-name

   : extract-lexeme ( -- sd )
     begin take-lexeme-maybe dup if exit then
       2drop  refill 0=
     until -39 throw \ "unexpected end of the input source"
   ;

   ' translate-xtval-setter constant td-xtval-setter
   ' translate-localid-setter constant td-localid-setter

   : to(
     extract-lexeme 2dup ")" equals if 2drop exit then
     perceive ?found ( tdo ) \ "tdo" stands for "typed data object"
     tdo>xtval? if ( xtval )
       td-xtval-setter 2>r
     else ( tdo ) tdo>localid? if ( localid )
       ?comp td-localid-setter 2>r
     else -32 throw then then
     recurse 2r> execute
   ; immediate


Using the perceptor and the `to` factors allows us to make the `to( ... 
)` construct multi-line more easily than using the top-level word `to`, 
since we don't have to allocate and free strings.

This approach works in SP-Forth/4.

The word `td-xtval-setter ( -- td )` returns the same type descriptor as 
a proper recognizer returns for "->foo", where "foo" is a children of 
`value`.

The word `td-localid-setter ( -- td )` returns the same type descriptor 
as a proper recognizer returns for "->bar", where "bar" is a local variable.

The word `tdo>xtval? ( tdo1 -- xtval true | tdo1 false )` converts tdo 
to xtval (a subtype of xt).

The word `tdo>localid? ( tdo1 -- localid true | tdo1 false )` converts 
tdo to localid.



Note: Above I use the data type symbol "tdo" rather than the proposed by 
Anton data type symbol "translation", as the latter is too confusing in 
this context, because the English "translation" means either an act of 
translating, or a result of translating [1]
[1] <https://en.wiktionary.org/wiki/translation#Noun>



--
Ruvim

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


Thread

Coroutines in Forth Gerry Jackson <do-not-use@swldwa.uk> - 2026-04-05 23:25 +0100
  Re: Coroutines in Forth Gerry Jackson <do-not-use@swldwa.uk> - 2026-04-05 23:30 +0100
    Re: Coroutines in Forth Paul Rubin <no.email@nospam.invalid> - 2026-04-05 17:16 -0700
      Re: Coroutines in Forth Gerry Jackson <do-not-use@swldwa.uk> - 2026-04-06 19:58 +0100
        Re: Coroutines in Forth Paul Rubin <no.email@nospam.invalid> - 2026-04-22 11:13 -0700
          Re: Coroutines in Forth albert@spenarnc.xs4all.nl - 2026-04-22 22:05 +0200
      Re: Coroutines in Forth albert@spenarnc.xs4all.nl - 2026-04-07 13:23 +0200
  Re: Coroutines in Forth albert@spenarnc.xs4all.nl - 2026-04-06 13:51 +0200
    Re: Coroutines in Forth Gerry Jackson <do-not-use@swldwa.uk> - 2026-04-06 22:20 +0100
      Re: Coroutines in Forth albert@spenarnc.xs4all.nl - 2026-04-07 13:35 +0200
        Re: Coroutines in Forth Gerry Jackson <do-not-use@swldwa.uk> - 2026-04-07 20:55 +0100
          Re: Coroutines in Forth albert@spenarnc.xs4all.nl - 2026-04-08 12:34 +0200
            Re: Coroutines in Forth Gerry Jackson <do-not-use@swldwa.uk> - 2026-04-08 12:32 +0100
            non-parsing `TO` considered harmful Ruvim <ruvim.pinka@gmail.com> - 2026-06-04 22:26 +0000
              Re: non-parsing `TO` considered harmful Ruvim <ruvim.pinka@gmail.com> - 2026-06-06 12:54 +0000
                Re: non-parsing `TO` considered harmful anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-06-06 16:17 +0000
                Re: non-parsing `TO` considered harmful Ruvim <ruvim.pinka@gmail.com> - 2026-06-06 21:09 +0000
                Re: non-parsing `TO` considered harmful anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-06-07 13:23 +0000
                Re: non-parsing `TO` considered harmful Ruvim <ruvim.pinka@gmail.com> - 2026-06-07 17:44 +0000
                Re: non-parsing `TO` considered harmful anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-06-08 05:04 +0000
                text translator (was: non-parsing `TO` considered harmful) Ruvim <ruvim.pinka@gmail.com> - 2026-06-08 15:53 +0000
                Recognizers vs Parsing words (was: non-parsing `TO` considered harmful) Ruvim <ruvim.pinka@gmail.com> - 2026-06-09 10:25 +0000
                Re: Recognizers vs Parsing words Ruvim <ruvim.pinka@gmail.com> - 2026-06-10 19:45 +0000
                compilation of compilation (was: non-parsing `TO` considered harmful) Ruvim <ruvim.pinka@gmail.com> - 2026-06-08 07:28 +0000
                Recognizer API v.2025-09-11 (was: non-parsing `TO` considered harmful) Ruvim <ruvim.pinka@gmail.com> - 2026-06-14 12:41 +0000
                Re: Recognizer API v.2025-09-11 (was: non-parsing `TO` considered harmful) anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-06-15 17:17 +0000
                Re: Recognizer API v.2025-09-11 Ruvim <ruvim.pinka@gmail.com> - 2026-06-16 17:34 +0000
                Re: Recognizer API v.2025-09-11 anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-06-17 05:05 +0000
                Setters and getters in APIs (was: Recognizer API v.2025-09-11) Ruvim <ruvim.pinka@gmail.com> - 2026-06-19 16:17 +0000
                Re: Setters and getters in APIs (was: Recognizer API v.2025-09-11) anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-06-20 15:51 +0000
                Re: non-parsing `TO` considered harmful Stephen Pelc <stephen@vfxforth.com> - 2026-06-07 11:59 +0000
                Re: non-parsing `TO` considered harmful anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-06-07 15:25 +0000
          Re: Coroutines in Forth Stephen Pelc <stephen@vfxforth.com> - 2026-04-09 10:12 +0000
            non-parsing `TO` considered harmful Ruvim <ruvim.pinka@gmail.com> - 2026-06-04 22:30 +0000
              VFX Forth problems Ruvim <ruvim.pinka@gmail.com> - 2026-06-05 16:24 +0000
            Re: Coroutines in Forth marcel hendrix <mhx@iae.nl> - 2026-07-09 09:50 +0200
              Re: Coroutines in Forth albert@SPENARNC.XS4ALL.NL - 2026-07-10 01:48 +0200
          Re: Coroutines in Forth Stephen Pelc <stephen@vfxforth.com> - 2026-06-07 11:53 +0000
            non-parsing `TO` considered harmful (was: Coroutines in Forth) Ruvim <ruvim.pinka@gmail.com> - 2026-06-07 13:31 +0000
              Re: non-parsing `TO` considered harmful Travis Bemann <tabemann@gmail.com> - 2026-08-28 20:36 -0500
        Re: Coroutines in Forth Hans Bezemer <the.beez.speaks@gmail.com> - 2026-04-10 19:01 +0200
          Re: Coroutines in Forth dxf <dxforth@gmail.com> - 2026-04-11 11:54 +1000
            Re: Coroutines in Forth Hans Bezemer <the.beez.speaks@gmail.com> - 2026-05-01 13:07 +0200
          Re: Coroutines in Forth peter <peter.noreply@tin.it> - 2026-04-11 09:49 +0200
          Re: Coroutines in Forth albert@spenarnc.xs4all.nl - 2026-04-11 22:03 +0200
            Re: Coroutines in Forth dxf <dxforth@gmail.com> - 2026-04-12 12:49 +1000
              Re: Coroutines in Forth albert@spenarnc.xs4all.nl - 2026-04-12 12:13 +0200
                Re: Coroutines in Forth Hans Bezemer <the.beez.speaks@gmail.com> - 2026-04-12 17:39 +0200
                Re: Coroutines in Forth dxf <dxforth@gmail.com> - 2026-04-13 10:54 +1000
                Re: Coroutines in Forth Hans Bezemer <the.beez.speaks@gmail.com> - 2026-04-13 19:24 +0200
              Re: Coroutines in Forth Hans Bezemer <the.beez.speaks@gmail.com> - 2026-04-12 13:48 +0200
              Re: Coroutines in Forth albert@spenarnc.xs4all.nl - 2026-04-13 12:13 +0200
              Re: Coroutines in Forth Paul Rubin <no.email@nospam.invalid> - 2026-04-22 11:18 -0700
                Re: Coroutines in Forth dxf <dxforth@gmail.com> - 2026-04-23 11:13 +1000
                Re: Coroutines in Forth Hans Bezemer <the.beez.speaks@gmail.com> - 2026-04-23 12:37 +0200
                Re: Coroutines in Forth Paul Rubin <no.email@nospam.invalid> - 2026-04-24 10:36 -0700
                Re: Coroutines in Forth dxf <dxforth@gmail.com> - 2026-04-25 12:12 +1000
                Re: Coroutines in Forth Paul Rubin <no.email@nospam.invalid> - 2026-04-24 23:31 -0700
                Re: Coroutines in Forth albert@spenarnc.xs4all.nl - 2026-04-25 10:45 +0200
                Re: Coroutines in Forth dxf <dxforth@gmail.com> - 2026-04-25 22:06 +1000
                Re: Coroutines in Forth Hans Bezemer <the.beez.speaks@gmail.com> - 2026-04-25 15:11 +0200
                Re: Coroutines in Forth dxf <dxforth@gmail.com> - 2026-04-26 13:33 +1000
                Re: Coroutines in Forth Hans Bezemer <the.beez.speaks@gmail.com> - 2026-04-26 16:28 +0200
                Re: Coroutines in Forth Paul Rubin <no.email@nospam.invalid> - 2026-04-25 21:46 -0700
                FP stack depth limitations (was: Coroutines in Forth) anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-04-26 05:55 +0000
                Re: FP stack depth limitations Paul Rubin <no.email@nospam.invalid> - 2026-04-26 00:28 -0700
                Re: FP stack depth limitations dxf <dxforth@gmail.com> - 2026-04-26 19:55 +1000
                Re: FP stack depth limitations (was: Coroutines in Forth) peter <peter.noreply@tin.it> - 2026-04-26 09:57 +0200
                Re: FP stack depth limitations (was: Coroutines in Forth) albert@spenarnc.xs4all.nl - 2026-04-26 14:34 +0200
                Re: Coroutines in Forth Hans Bezemer <the.beez.speaks@gmail.com> - 2026-04-25 15:01 +0200
                Re: Coroutines in Forth Hans Bezemer <the.beez.speaks@gmail.com> - 2026-05-01 13:13 +0200
                Forth, C, hardware, and programming virtues (was: Coroutines in Forth) anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-04-25 05:26 +0000
                Re: Forth, C, hardware, and programming virtues Paul Rubin <no.email@nospam.invalid> - 2026-04-24 23:55 -0700
                Re: Forth, C, hardware, and programming virtues anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-04-25 08:21 +0000
                Re: Forth, C, hardware, and programming virtues albert@spenarnc.xs4all.nl - 2026-04-25 11:27 +0200
                Re: Forth, C, hardware, and programming virtues Hans Bezemer <the.beez.speaks@gmail.com> - 2026-04-25 15:43 +0200
                Re: Forth, C, hardware, and programming virtues anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-04-25 17:21 +0000
                Re: Forth, C, hardware, and programming virtues dxf <dxforth@gmail.com> - 2026-04-26 15:21 +1000
                Re: Forth, C, hardware, and programming virtues Hans Bezemer <the.beez.speaks@gmail.com> - 2026-04-26 15:08 +0200
                Re: Forth, C, hardware, and programming virtues albert@spenarnc.xs4all.nl - 2026-04-26 00:34 +0200
                Re: Forth, C, hardware, and programming virtues Hans Bezemer <the.beez.speaks@gmail.com> - 2026-04-26 15:10 +0200
                locals (was: Coroutines in Forth) anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-04-25 04:47 +0000
                Re: locals Paul Rubin <no.email@nospam.invalid> - 2026-04-24 23:21 -0700
                Re: locals anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-04-25 06:43 +0000
                Re: locals albert@spenarnc.xs4all.nl - 2026-04-25 11:43 +0200
                Re: locals anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-04-25 10:22 +0000
                Re: locals peter <peter.noreply@tin.it> - 2026-04-25 16:07 +0200
                Re: locals Hans Bezemer <the.beez.speaks@gmail.com> - 2026-04-25 17:38 +0200
                Re: locals albert@spenarnc.xs4all.nl - 2026-04-26 01:13 +0200
                Re: locals anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-04-26 14:03 +0000
                Re: locals peter <peter.noreply@tin.it> - 2026-04-27 09:31 +0200
                Re: locals anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-04-27 07:53 +0000
                Re: locals peter <peter.noreply@tin.it> - 2026-04-27 11:52 +0200
                Re: locals albert@spenarnc.xs4all.nl - 2026-04-26 00:51 +0200
                Re: locals Paul Rubin <no.email@nospam.invalid> - 2026-04-25 22:40 -0700
                Re: locals albert@spenarnc.xs4all.nl - 2026-04-26 14:55 +0200
                Re: locals anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-04-26 09:50 +0000
                Re: locals Hans Bezemer <the.beez.speaks@gmail.com> - 2026-04-26 16:22 +0200
                Re: locals anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-04-26 17:04 +0000
                Re: locals dxf <dxforth@gmail.com> - 2026-04-27 11:51 +1000
                Re: locals Hans Bezemer <the.beez.speaks@gmail.com> - 2026-04-28 08:21 +0200
                Re: locals Hans Bezemer <the.beez.speaks@gmail.com> - 2026-04-28 08:22 +0200
                Re: locals dxf <dxforth@gmail.com> - 2026-04-27 11:12 +1000
                Re: locals Hans Bezemer <the.beez.speaks@gmail.com> - 2026-04-28 14:34 +0200
                Re: locals Hans Bezemer <the.beez.speaks@gmail.com> - 2026-04-28 14:34 +0200
                Re: locals Gerry Jackson <do-not-use@swldwa.uk> - 2026-04-29 12:44 +0100
                Re: locals Hans Bezemer <the.beez.speaks@gmail.com> - 2026-04-29 14:37 +0200
                Re: locals Hans Bezemer <the.beez.speaks@gmail.com> - 2026-04-29 14:44 +0200
                Re: locals Paul Rubin <no.email@nospam.invalid> - 2026-05-01 23:50 -0700
                Re: locals anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-05-02 10:34 +0000
                Re: locals Paul Rubin <no.email@nospam.invalid> - 2026-05-01 23:54 -0700
                Re: locals dxf <dxforth@gmail.com> - 2026-05-02 17:36 +1000
                Re: locals Paul Rubin <no.email@nospam.invalid> - 2026-05-02 01:11 -0700
                Re: locals anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-05-02 15:58 +0000
      Re: Coroutines in Forth Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-04-07 09:28 -0500
        Re: Coroutines in Forth anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-04-07 16:12 +0000
          Re: Coroutines in Forth Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-04-07 18:06 -0500
          Re: Coroutines in Forth Gerry Jackson <do-not-use@swldwa.uk> - 2026-04-08 11:43 +0100
            Re: Coroutines in Forth albert@spenarnc.xs4all.nl - 2026-04-08 13:16 +0200
              Re: Coroutines in Forth Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-04-08 11:47 -0500
                Re: Coroutines in Forth Gerry Jackson <do-not-use@swldwa.uk> - 2026-04-08 21:48 +0100
                Re: Coroutines in Forth Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-04-09 07:06 -0500
                Re: Coroutines in Forth albert@spenarnc.xs4all.nl - 2026-04-09 16:41 +0200
                Re: Coroutines in Forth Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-04-09 13:34 -0500
                Re: Coroutines in Forth albert@spenarnc.xs4all.nl - 2026-04-10 01:23 +0200
                Re: Coroutines in Forth Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-04-09 21:34 -0500
                Re: Coroutines in Forth albert@spenarnc.xs4all.nl - 2026-04-09 13:01 +0200
                Re: Coroutines in Forth Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-04-09 07:01 -0500
                Re: Coroutines in Forth albert@spenarnc.xs4all.nl - 2026-04-09 16:10 +0200
                Re: Coroutines in Forth Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-04-09 13:29 -0500
              Re: Coroutines in Forth Gerry Jackson <do-not-use@swldwa.uk> - 2026-04-08 21:26 +0100
          Re: Coroutines in Forth Hans Bezemer <the.beez.speaks@gmail.com> - 2026-04-08 14:22 +0200
          Re: Coroutines in Forth Hans Bezemer <the.beez.speaks@gmail.com> - 2026-04-28 15:31 +0200
            Re: Coroutines in Forth albert@spenarnc.xs4all.nl - 2026-04-29 10:49 +0200
              Re: Coroutines in Forth Hans Bezemer <the.beez.speaks@gmail.com> - 2026-04-29 15:22 +0200
        Re: Coroutines in Forth Gerry Jackson <do-not-use@swldwa.uk> - 2026-04-08 11:33 +0100
          Re: Coroutines in Forth albert@spenarnc.xs4all.nl - 2026-04-08 13:07 +0200
            Re: Coroutines in Forth Gerry Jackson <do-not-use@swldwa.uk> - 2026-04-08 22:05 +0100
  Re: Coroutines in Forth albert <albert@spenarnc.xs4all.nl> - 2026-06-21 01:26 +0200

csiph-web