| Deutsch English Français Italiano |
|
<2025Mar6.190930@mips.complang.tuwien.ac.at> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: anton@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups: comp.lang.forth
Subject: Re: Fetch string from comment
Date: Thu, 06 Mar 2025 18:09:30 GMT
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
Lines: 39
Message-ID: <2025Mar6.190930@mips.complang.tuwien.ac.at>
References: <vq4rmt$1dv1v$1@dont-email.me> <nnd$05d8817a$443d26e2@cbc0f0f0dc4c07a4> <de0b1a90f9b6e2f4a5c05d1f9135e64e@www.novabbs.com> <vq9epj$2cvkj$1@dont-email.me> <2025Mar5.175013@mips.complang.tuwien.ac.at> <d122f0610edfd0bdc2895aa1b726cf1e@www.novabbs.com> <2025Mar5.200303@mips.complang.tuwien.ac.at> <001c29937cf8440ee5cc4a26135820af@www.novabbs.com>
Injection-Date: Thu, 06 Mar 2025 19:40:29 +0100 (CET)
Injection-Info: dont-email.me; posting-host="7d128b98df360799f0f6ea7a432bce1c";
logging-data="3233648"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/goz60cyXmsGm8mNhdrBXZ"
Cancel-Lock: sha1:HxQ05DqMZHq5YyOXsk57y1giZys=
X-newsreader: xrn 10.11
Bytes: 3196
mhx@iae.nl (mhx) writes:
>However, a state machine has well defined rules based on a
>state's stored information and its inputs, causing it to go to
>another well-defined state while generating outputs. In that
>context a goto is harmless and merely serves as a crutch when
>there are not enough computing nodes to serve all states in
>parallel. How to make such an efficient crutch in Forth?
You lost me. Why would one "serve all states in parallel"?
Anyway, if the question is how to implement a state machine
efficiently in Forth, one answer is to stay at a higher, more
structured level of abstraction or recreate it from the state machine.
E.g., don't transform a regular expression into a (indeterministic or
deterministic) finite state machine, but instead interpret it directly
(that's what Bernd Paysan's regexp.fs does). Or instead of
transforming a grammar into a push-down automaton, transform it into a
structured Forth program (like Gray does).
If you cannot do that, in standard Forth you don't really have good
options. The best is probably to have the current state on the stack
(probably in the form of the address of an array indexed with the
input (or whatever causes a state change) and containing the potential
next states at the appropriate elements.
In a particular implementation, you can do more, including goto-like
things. What I would do then is have a colon definition per state,
and do the transition to the next state as tail call. Have some
efficient forward-tail-call mechanism to allow calling states where
the definition comes later. Gforth has a clever FORWARD, but for now
that does not do tail-calls.
- anton
--
M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
New standard: https://forth-standard.org/
EuroForth 2023 proceedings: http://www.euroforth.org/ef23/papers/
EuroForth 2024 proceedings: http://www.euroforth.org/ef24/papers/