Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #45369 > unrolled thread
| Started by | lehs <skydda.barnen@gmail.com> |
|---|---|
| First post | 2016-02-08 09:06 -0800 |
| Last post | 2016-02-14 10:20 -0800 |
| Articles | 7 on this page of 27 — 8 participants |
Back to article view | Back to comp.lang.forth
Extending the interpreter? lehs <skydda.barnen@gmail.com> - 2016-02-08 09:06 -0800
Re: Extending the interpreter? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-02-08 17:28 +0000
Re: Extending the interpreter? lehs <skydda.barnen@gmail.com> - 2016-02-08 10:43 -0800
Re: Extending the interpreter? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-02-09 06:46 +0000
Re: Extending the interpreter? lehs <skydda.barnen@gmail.com> - 2016-02-09 00:22 -0800
Re: Extending the interpreter? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-02-09 08:34 +0000
Re: Extending the interpreter? Albert van der Horst <albert@spenarnc.xs4all.nl> - 2016-02-09 11:54 +0000
Re: Extending the interpreter? lehs <skydda.barnen@gmail.com> - 2016-02-09 07:53 -0800
Re: Extending the interpreter? lehs <skydda.barnen@gmail.com> - 2016-02-09 10:46 -0800
Re: Extending the interpreter? Chris Curl <ccurl609@gmail.com> - 2016-02-09 05:18 -0800
Re: Extending the interpreter? Chris Curl <ccurl609@gmail.com> - 2016-02-09 05:23 -0800
Re: Extending the interpreter? Doug Hoffman <glidedog@gmail.com> - 2016-02-09 10:22 -0500
Re: Extending the interpreter? lehs <skydda.barnen@gmail.com> - 2016-02-09 08:00 -0800
Re: Extending the interpreter? hughaguilar96@gmail.com - 2016-02-09 12:59 -0800
Re: Extending the interpreter? lehs <skydda.barnen@gmail.com> - 2016-02-09 13:21 -0800
Re: Extending the interpreter? hughaguilar96@gmail.com - 2016-02-09 14:52 -0800
Re: Extending the interpreter? hughaguilar96@gmail.com - 2016-02-09 14:57 -0800
Re: Extending the interpreter? lehs <skydda.barnen@gmail.com> - 2016-02-09 07:55 -0800
Re: Extending the interpreter? minforth@arcor.de - 2016-02-09 06:42 -0800
Re: Extending the interpreter? lehs <skydda.barnen@gmail.com> - 2016-02-13 14:55 -0800
Re: Extending the interpreter? lehs <skydda.barnen@gmail.com> - 2016-02-13 15:05 -0800
Re: Extending the interpreter? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-02-14 15:18 +0000
Re: Extending the interpreter? Albert van der Horst <albert@spenarnc.xs4all.nl> - 2016-02-14 18:03 +0000
Re: Extending the interpreter? lehs <skydda.barnen@gmail.com> - 2016-02-14 11:24 -0800
Re: Extending the interpreter? lehs <skydda.barnen@gmail.com> - 2016-02-14 11:32 -0800
Re: Extending the interpreter? lehs <skydda.barnen@gmail.com> - 2016-02-14 01:39 -0800
Re: Extending the interpreter? humptydumpty <ouatubi@gmail.com> - 2016-02-14 10:20 -0800
Page 2 of 2 — ← Prev page 1 [2]
| From | lehs <skydda.barnen@gmail.com> |
|---|---|
| Date | 2016-02-13 15:05 -0800 |
| Message-ID | <2c439584-0c62-40b9-ab64-c9634ed3839e@googlegroups.com> |
| In reply to | #45510 |
Den lördag 13 februari 2016 kl. 23:55:23 UTC+1 skrev lehs:
> Den måndag 8 februari 2016 kl. 18:06:37 UTC+1 skrev lehs:
> > I would like the possibility of "extending the interpreter", letting it recognize new data structures. Could this be done?
>
> Using 'see' with trial and error I'd made this
>
> : extended_interpret \ --
> space ." Ok" cr
> begin clear-tibstack
> tib max#tib @ accept #tib ! input-start-line tib c@
> case
> [char] + of endof
> [char] { of endof
> [char] ( of endof
> dup of interpret endof
> endcase space ." Ok" cr
> again ;
>
> that accepts anything starting with '+', '{' or '(' without error messages. Between of and endof there should be a word for handling those inputs.
>
> I don't know the exact consequences of the routine, but when started it works like quit(?) and keep working until an error.
I forgot to mention that this is GForth. It works in Windows and Android.
[toc] | [prev] | [next] | [standalone]
| From | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
|---|---|
| Date | 2016-02-14 15:18 +0000 |
| Message-ID | <2016Feb14.161849@mips.complang.tuwien.ac.at> |
| In reply to | #45511 |
lehs <skydda.barnen@gmail.com> writes:
>Den l=F6rdag 13 februari 2016 kl. 23:55:23 UTC+1 skrev lehs:
>> Den m=E5ndag 8 februari 2016 kl. 18:06:37 UTC+1 skrev lehs:
>> > I would like the possibility of "extending the interpreter", letting it=
> recognize new data structures. Could this be done?
>>=20
>> Using 'see' with trial and error I'd made this=20
>>=20
>> : extended_interpret \ --=20
>> space ." Ok" cr=20
>> begin clear-tibstack
>> tib max#tib @ accept #tib ! input-start-line tib c@
>> case
>> [char] + of endof
>> [char] { of endof
>> [char] ( of endof
>> dup of interpret endof
>> endcase space ." Ok" cr=20
>> again ;=20
>>=20
>> that accepts anything starting with '+', '{' or '(' without error message=
>s. Between of and endof there should be a word for handling those inputs.
>>=20
>> I don't know the exact consequences of the routine, but when started it w=
>orks like quit(?) and keep working until an error.
>
>I forgot to mention that this is GForth. It works in Windows and Android.
For some value of "works". E.g., it does not use REFILL, but ACCEPT,
and therefore only works on the command line. Also, the + { ( must be
at the start of the line (preceding spaces allowed with your BLADD
extension), but not after another word; is this intended?
If you want to work at the word level, defining a recognizer is the
way to go. Get a development version of Gforth and look for r:fail to
see examples of recognizers. This is a work in progress, so it may
change, but it's probably still more sensible to work with that than
to try to replicate the text interpreter, badly. Even if you have to
do it again if we change the recognizer interface, it will be less
work and provide better function.
- 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: http://www.forth200x.org/forth200x.html
EuroForth 2015: http://www.rigwit.co.uk/EuroForth2015/
[toc] | [prev] | [next] | [standalone]
| From | Albert van der Horst <albert@spenarnc.xs4all.nl> |
|---|---|
| Date | 2016-02-14 18:03 +0000 |
| Message-ID | <56c0c178$0$23750$e4fe514c@news.xs4all.nl> |
| In reply to | #45520 |
anton@mips.complang.tuwien.ac.at (Anton Ertl) writes:
>lehs <skydda.barnen@gmail.com> writes:
>>Den l=F6rdag 13 februari 2016 kl. 23:55:23 UTC+1 skrev lehs:
>>> Den m=E5ndag 8 februari 2016 kl. 18:06:37 UTC+1 skrev lehs:
>>> > I would like the possibility of "extending the interpreter", letting it=
>> recognize new data structures. Could this be done?
>>>=20
>>> Using 'see' with trial and error I'd made this=20
>>>=20
>>> : extended_interpret \ --=20
>>> space ." Ok" cr=20
>>> begin clear-tibstack
>>> tib max#tib @ accept #tib ! input-start-line tib c@
>>> case
>>> [char] + of endof
>>> [char] { of endof
>>> [char] ( of endof
>>> dup of interpret endof
>>> endcase space ." Ok" cr=20
>>> again ;=20
>>>=20
>>> that accepts anything starting with '+', '{' or '(' without error message=
>>s. Between of and endof there should be a word for handling those inputs.
>>>=20
>>> I don't know the exact consequences of the routine, but when started it w=
>>orks like quit(?) and keep working until an error.
>>
>>I forgot to mention that this is GForth. It works in Windows and Android.
>For some value of "works". E.g., it does not use REFILL, but ACCEPT,
>and therefore only works on the command line. Also, the + { ( must be
>at the start of the line (preceding spaces allowed with your BLADD
>extension), but not after another word; is this intended?
>If you want to work at the word level, defining a recognizer is the
>way to go. Get a development version of Gforth and look for r:fail to
>see examples of recognizers. This is a work in progress, so it may
>change, but it's probably still more sensible to work with that than
>to try to replicate the text interpreter, badly. Even if you have to
>do it again if we change the recognizer interface, it will be less
>work and provide better function.
You may want a very simple Forth, if you are experimenting with
that kind of thing. You could use "yourforth" with is at the same
time simple and accomodates prefixes.
: { <do you thing> ; PREFIX
: + <do you thing> ; PREFIX
etc.
Note that the latter word would hide +! if you're not careful
with the search order. (Best have these in a separate wordlist
at the end of the search order. )
With lehs approach one has the same problem, e.g. +! at the
start of a line.
>- anton
--
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst
[toc] | [prev] | [next] | [standalone]
| From | lehs <skydda.barnen@gmail.com> |
|---|---|
| Date | 2016-02-14 11:24 -0800 |
| Message-ID | <bbc3d7fd-8fc1-466f-9a05-67507ddc02ff@googlegroups.com> |
| In reply to | #45524 |
Den söndag 14 februari 2016 kl. 19:03:38 UTC+1 skrev Albert van der Horst:
> anton@mips.complang.tuwien.ac.at (Anton Ertl) writes:
>
> >lehs <skydda.barnen@gmail.com> writes:
> >>Den l=F6rdag 13 februari 2016 kl. 23:55:23 UTC+1 skrev lehs:
> >>> Den m=E5ndag 8 februari 2016 kl. 18:06:37 UTC+1 skrev lehs:
> >>> > I would like the possibility of "extending the interpreter", letting it=
> >> recognize new data structures. Could this be done?
> >>>=20
> >>> Using 'see' with trial and error I'd made this=20
> >>>=20
> >>> : extended_interpret \ --=20
> >>> space ." Ok" cr=20
> >>> begin clear-tibstack
> >>> tib max#tib @ accept #tib ! input-start-line tib c@
> >>> case
> >>> [char] + of endof
> >>> [char] { of endof
> >>> [char] ( of endof
> >>> dup of interpret endof
> >>> endcase space ." Ok" cr=20
> >>> again ;=20
> >>>=20
> >>> that accepts anything starting with '+', '{' or '(' without error message=
> >>s. Between of and endof there should be a word for handling those inputs.
> >>>=20
> >>> I don't know the exact consequences of the routine, but when started it w=
> >>orks like quit(?) and keep working until an error.
> >>
> >>I forgot to mention that this is GForth. It works in Windows and Android.
>
> >For some value of "works". E.g., it does not use REFILL, but ACCEPT,
> >and therefore only works on the command line. Also, the + { ( must be
> >at the start of the line (preceding spaces allowed with your BLADD
> >extension), but not after another word; is this intended?
>
> >If you want to work at the word level, defining a recognizer is the
> >way to go. Get a development version of Gforth and look for r:fail to
> >see examples of recognizers. This is a work in progress, so it may
> >change, but it's probably still more sensible to work with that than
> >to try to replicate the text interpreter, badly. Even if you have to
> >do it again if we change the recognizer interface, it will be less
> >work and provide better function.
>
> You may want a very simple Forth, if you are experimenting with
> that kind of thing. You could use "yourforth" with is at the same
> time simple and accomodates prefixes.
>
> : { <do you thing> ; PREFIX
> : + <do you thing> ; PREFIX
> etc.
> Note that the latter word would hide +! if you're not careful
> with the search order. (Best have these in a separate wordlist
> at the end of the search order. )
> With lehs approach one has the same problem, e.g. +! at the
> start of a line.
>
> >- anton
> --
> Albert van der Horst, UTRECHT,THE NETHERLANDS
> Economic growth -- being exponential -- ultimately falters.
> albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst
The prefix approach was just a demonstration. It has to be a pattern search in my case and then, in case, a transformation of input stream to something that Forth recognize.
[toc] | [prev] | [next] | [standalone]
| From | lehs <skydda.barnen@gmail.com> |
|---|---|
| Date | 2016-02-14 11:32 -0800 |
| Message-ID | <dd1cdfe9-ca9e-4da7-897f-01564515802c@googlegroups.com> |
| In reply to | #45520 |
Den söndag 14 februari 2016 kl. 16:36:10 UTC+1 skrev Anton Ertl:
> lehs <skydda.barnen@gmail.com> writes:
> >Den l=F6rdag 13 februari 2016 kl. 23:55:23 UTC+1 skrev lehs:
> >> Den m=E5ndag 8 februari 2016 kl. 18:06:37 UTC+1 skrev lehs:
> >> > I would like the possibility of "extending the interpreter", letting it=
> > recognize new data structures. Could this be done?
> >>=20
> >> Using 'see' with trial and error I'd made this=20
> >>=20
> >> : extended_interpret \ --=20
> >> space ." Ok" cr=20
> >> begin clear-tibstack
> >> tib max#tib @ accept #tib ! input-start-line tib c@
> >> case
> >> [char] + of endof
> >> [char] { of endof
> >> [char] ( of endof
> >> dup of interpret endof
> >> endcase space ." Ok" cr=20
> >> again ;=20
> >>=20
> >> that accepts anything starting with '+', '{' or '(' without error message=
> >s. Between of and endof there should be a word for handling those inputs.
> >>=20
> >> I don't know the exact consequences of the routine, but when started it w=
> >orks like quit(?) and keep working until an error.
> >
> >I forgot to mention that this is GForth. It works in Windows and Android.
>
> For some value of "works". E.g., it does not use REFILL, but ACCEPT,
> and therefore only works on the command line. Also, the + { ( must be
> at the start of the line (preceding spaces allowed with your BLADD
> extension), but not after another word; is this intended?
>
> If you want to work at the word level, defining a recognizer is the
> way to go. Get a development version of Gforth and look for r:fail to
> see examples of recognizers. This is a work in progress, so it may
> change, but it's probably still more sensible to work with that than
> to try to replicate the text interpreter, badly. Even if you have to
> do it again if we change the recognizer interface, it will be less
> work and provide better function.
>
> - 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: http://www.forth200x.org/forth200x.html
> EuroForth 2015: http://www.rigwit.co.uk/EuroForth2015/
I will try to find the recognizers. Thanks!
[toc] | [prev] | [next] | [standalone]
| From | lehs <skydda.barnen@gmail.com> |
|---|---|
| Date | 2016-02-14 01:39 -0800 |
| Message-ID | <a1c1db3c-1469-4120-800c-9f8b83266380@googlegroups.com> |
| In reply to | #45369 |
Den måndag 8 februari 2016 kl. 18:06:37 UTC+1 skrev lehs:
> I would like the possibility of "extending the interpreter", letting it recognize new data structures. Could this be done?
A cleaner variant that works for GForth Win, GForth Android and SP-Forth Win..
: bladd \ ad1 -- ad2
begin dup c@ bl =
while 1+
repeat ;
: .ok space ." OK" cr ;
: xinterpreter .ok
begin 0 >in !
tib 80 accept #tib !
tib bladd c@
case
[char] + of ." +" endof
[char] { of ." {" endof
[char] ( of ." (" endof
dup of interpret endof
endcase .ok
again ;
But there is some problems left.
Leave xinterpreter with 'abort'.
[toc] | [prev] | [next] | [standalone]
| From | humptydumpty <ouatubi@gmail.com> |
|---|---|
| Date | 2016-02-14 10:20 -0800 |
| Message-ID | <2884fe06-6249-4a2a-878e-9640b1c5313b@googlegroups.com> |
| In reply to | #45369 |
On Monday, February 8, 2016 at 7:06:37 PM UTC+2, lehs wrote: > I would like the possibility of "extending the interpreter", letting it recognize new data structures. Could this be done? Hi! For inspiration, 24game I wrote some time ago: \ 24 Game, using Gforth. \ The goal of the game is find a way to obtain number 24 \ from a randomly chosen four numbers \ using only * / + - arithmetic operations. \ \ It use post-fix operators, ex: 4 9 + to obtain 13 \ As game run once, it starts with EMPTY stacks. \ include random.fs FVARIABLE Top VARIABLE Found : end-game? ( -- ) FDEPTH 1 = IF ." You " 24E0 F= IF ." WIN!" ELSE ." loose." THEN CR BYE THEN ; : (fextract) FDEPTH 0= IF EXIT THEN FDUP Top F@ F= IF Found ON FDROP EXIT ELSE F>D RECURSE THEN D>F ; : fextract ( F: r0..ri-1 x ri+1..rn x -- r0..ri-1 ri+1..rn;S: -- x>D | TERMINATE PROGRAM ) Found OFF Top F! (fextract) Found @ IF Top F@ F>D ELSE ." Do not cheat! :)" CR BYE THEN ; WORDLIST CONSTANT SECURE-WORDLIST GET-CURRENT SECURE-WORDLIST SET-CURRENT : + 2SWAP D>F D>F f+ ; : - 2SWAP D>F D>F f- ; : * 2SWAP D>F D>F f* ; : / 2SWAP D>F D>F f/ ; SET-CURRENT : word-interpret ( .. ca u -- ... ) 2DUP SECURE-WORDLIST SEARCH-WORDLIST IF NIP NIP CATCH THROW end-game? ELSE >FLOAT IF fextract THEN THEN ; : secure-interpret ( -- ) BEGIN parse-name DUP WHILE word-interpret REPEAT 2DROP ; : run ( -- ) BEGIN REFILL WHILE secure-interpret REPEAT ; ." Make 24 using only + - * / from this numbers" :noname 8 4 7 8 TIME&DATE + + + + + 0 DO 3 ROLL DROP 9 RANDOM 1+ LOOP ; EXECUTE .S CR :noname 4 0 DO S>D D>F LOOP ; EXECUTE STDIN ' run EXECUTE-PARSING-FILE CR BYE
[toc] | [prev] | [standalone]
Page 2 of 2 — ← Prev page 1 [2]
Back to top | Article view | comp.lang.forth
csiph-web