Hello again,
I’ve been using routine from the ZILF parser library. One of things I find interesting is the trick (or genius feature) used to decipher the user’s input. In particular:
<READLINE>
<SET W <AND <GETB ,LEXBUF 1> <GET ,LEXBUF 1>>>
This returns the first word from the user’s input (if any) into W by looking up LEXBUF table. To check whether or not it is equal some word, e.g. RESTART, we use something like:
<COND (<EQUAL? .W ,W?RESTART>
...
)>
… as demonstrated in the JIGS-UP routine. This works as long as the word RESTART is explicitly defined anywhere your code (via SYNTAX, SYNONYM, VOC – need to verify) , or was defined as an adjective or a synonym in an OBJECT.
Now, to me, it immediately begged the question, what of the second word? third word?
The following seems to work:
<SET W2 <AND <GETB ,LEXBUF 3> <GET ,LEXBUF 3>>>
<SET W3 <AND <GETB ,LEXBUF 5> <GET ,LEXBUF 5>>>
...
<COND (<AND <EQUAL? .W ,W?THE> <EQUAL? .W2 ,W?WHITE> <EQUAL? .W3 ,W?WOLF>>
...
)>
when trying to check whether the first three words of the user’s input was THE WHITE WOLF.
It seems to work on my tests, however, my question is: is this safe? or reliable in general (i.e. using LEXBUF)?
Thanks in advance for any clarification(s) on this!
Cheers
PS.
Also found this in parser.
<ROUTINE GETWORD? (N "AUX" R)
<SET R <GET ,LEXBUF <- <* .N 2> 1>>>
.R>