( Timbre framework for parsing Rob Chapman July 30, 1996 ) \ This framework parses the input using two rule sets. \ Parsing is kept going by maintaining something in the input queue. \ The default behaviour is to parse the input and then echo it to the \ output. \ The parse rule echoes any blanks preceding words while the word rule \ grabs the next word in the input stream and switches to the word rule set. \ GET-WORD has been redefined to allow blanks after a word not to be lost. RULE-SET parse ( rules for parsing code ) RULE-SET words ( defined words to look for ) : GET-WORD ( -- s ) GET-WORD INPUT 1 - C@ BL = IF -1 in +! ENDIF ; : TRANSLATOR-INIT ( -- ) TRANSLATOR-INIT parse RULES | parse word | ; parse RULES { parse }[ INPUT BL SKIP INPUT SWAP - FOR BL EMIT NEXT ]{ check input } { word }[ GET-WORD inputq STUFF words RULES ] { check input }[ INPUT C@ 0= IF { get input } ENDIF ] { get input }[ INPUT-LINE IF CR { parse } ELSE { input done } ENDIF ] { input done }[ inputq 0Q ] { output word }[ COUNT TYPE ?STOP ] words RULES { }[ inputq PULL parse RULES ]{ output word parse word }