<READLINE> and deciphering user input

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>
1 Like

I believe this gets the number of words in the buffer. The AND expression proceeds if the number of words is non-zero.

Reading the bytes at offsets 3 and 5 doesn’t make sense. Rather, you should compare the byte at offset 1 to the desired number of words.

https://www.inform-fiction.org/zmachine/standards/z1point1/sect15.html#read

1 Like

That makes sense. I did encounter some weird results. Thanks for the clarification!

So to somewhat correct the above, we can use:

<SET W2 <GET ,LEXBUF 3>>
<SET W3 <GET ,LEXBUF 5>>
...
<COND (<AND <G? <GETB ,LEXBUF 1> 2> <EQUAL? .W ,W?THE> <EQUAL? .W2 ,W?WHITE> <EQUAL? .W3 ,W?WOLF>>
...
)>
1 Like