Hi Bernd,

In your one screeners section you list Rodriguez's BNF parcer generator slightly modified to run on bigforth. I am trying to use it to recognize binary strings. The task is to leave 0s and 1s on stack given single continuous string of 0s and 1s. It does not quite work.

In my code, below, please note the change in the second line from *0 Variable success* to *0 Variable success success !* It seems to be correct that way.

<eol> does not make sense to me since I am not sure how bigforth signifies end of line in tib.

I will appreciate your usage example that does work on bigforth. Of course, if you have ever tested in on bigforth.

Thanks!

--
Sergey

Here is the complete file listing:

\ BNF Parser                                (c) 1988 B. J. Rodriguez
0 Variable success success ! \ instead of 0 Variable success
: <bnf ( -- )  success @ IF  r> >in @ >r dp @ >r >r
   ELSE  r> drop  THEN ;
: bnf> ( -- )  success @ IF  r>  r> r> 2drop >r
   ELSE  r>  r> dp ! r> >in ! >r THEN ;
: || ( -- )   success @ IF  r> r> r> 2drop drop
   ELSE  r> r> r> 2dup >r >r >in ! dp !  1 success ! >r THEN ;
: bnf: ( -- sys )  : postpone recursive postpone <bnf ; immediate
: ;bnf ( sys -- )  postpone bnf> postpone ; ; immediate

: @token ( -- n )    source >in @ /string drop c@ ;
: +token ( f -- )    IF 1 >in +! THEN ;
: =token ( n -- )    success @ IF @token =  dup success ! +token
   ELSE drop THEN ;
: token ( n -- )    Create c, DOES> ( a -- )  c@ =token ;

hex '0 token '0' '1 token '1' 0 token <EOL>
bnf: {binary} '0' || '1' ;bnf
bnf: <binary> @token {binary} dup '0 = if 0 swap then '1 = if 1 then ;bnf
bnf: <number> <binary> <number> || <binary> ;bnf

: mparse
    true SUCCESS ! <number> <eol>
    cr success @ if ." Successful" else ." Failed" then ;

decimal

mparse 101010

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to