Bug? Topic-based actions not parsed if they share a verb word with another action

I suspect that it is in recognition of this potential issue that the compiler formally disallows simple regex alternative syntax as the first word of grammar lines- e.g.

Understand "employ/deploy/utilise/use [something]" as using.

is rejected with an admonition not to do this sort of thing, although the functionally equivalent

Understand "employ/deploy/utilise/use" as "[utilising]".
Understand "[utilising] [something]" as using.

compiles as a (probably deprecated) workaround that returns GPR_PREPOSITION as the token type for the initial token, rather than a verb. These grammar lines are scanned by the parser with the substituted dummy verb of ‘no.verb’ only when it can find no valid verb in the initial word position of the player’s command, ‘no.verb’ being only made available to the parser by the compiler when it has encountered an ‘Understand…’ action declaration beginning with a token in the source.

As an aside, this mechanism exposes another bug, due to setting the I6 variable verb_wordnum to 0 when the verb is ‘no.verb’- this messes up the automatic diversion of commands such as ‘Darcy, hello’ to the ‘Answering it that’ action. If you have the stomach for it, read on…

If the parser is unable to interpret the first word of a command as a verb word in the dictionary, it calls the routine UnknownVerb, which has the opportunity to help the parser out by supplying a verb word for the parser to work with.
The I7 compiler normally generates a pair of UnknownVerb routines with a hard-coded directive for the I6 compiler to use one or the other according to whether I7 has detected any grammar line declarations that don’t start with a dictionary verb word. In the latter case, UnknownVerb sets the verb_wordnum to 0 and returns the untypeable verb ‘no.verb’ as the verb, which allows the parser to go on to consider grammar lines matching against ‘no.verb’. In the default case, where every grammar line declaration begins with a dictionary verb word, UnknownVerb just returns false and the parser does not go on to consider grammar lines.

#IFTRUE (1 == 1);
[ UnknownVerb; verb_wordnum = 0; return ‘no.verb’; ];
[ PrintVerb v;
if (v == ‘no.verb’) { print “do something to”; rtrue; }
rfalse;
];
#Ifnot;
[ UnknownVerb; rfalse; ]; [ PrintVerb v; rfalse; ];
#ENDIF;

In either case, if the player’s command starts by addressing a speakable object with, for example ‘Mr Darcy, …’ and no grammar lines match the text after the comma, the remainder of the command after the comma is considered to be an unparsed conversational topic and an ##Answer action generated, with the addressee as the ‘noun’ and the topic stored as a snippet in ‘second’.
This fails in the case where verb_wordnum has been set to 0, in UnknownVerb, because verb_wordnum is used by the parser in generating the ##Answer action to determine the start and length of the snippet (it ends up being (100*verb_wordnum) + (numwords-verb_wordnum+1). So for example, for ‘Darcy, hello’ where verb_wordnum should be 3 and the snippet should be 301, it is stored as 4. Obviously this will cause any code dependent on this snippet to fail, often with a program error because a snippet <100 suggests the first word is the (non-existent) 0th word of the player’s command and this leads to attempts to read below the lower bounds of the parse array.

Symptoms:
The fault can be easily demonstrated by declaring a grammar line for an action having a token as its initial word, compiling, invoking actions reporting with the ‘actions’ command, then inputting a command in the form ‘somebody, …’ . A programming error will be reported due to an out-of-bounds array reference.

In source:

Utilising is an action applying to one visible thing.
Understand “[utilise] [something]” as utilising.
Understand “use/employ/deploy” as “[utilise]”.

In play:

actions
Actions listing on.

darcy, hello
[answering Mr Darcy that "
[** Programming error: tried to read from -->-1 in the array “parse”, which has entries 0 up to 60 **]
darcy , hello"]

Any code trying to reference ‘the topic understood’ for this action, or to ‘say’ the action, will similarly run into trouble.

Obviously, the simple way to avoid the problem is by not declaring grammar lines with a token as their first word. As far as I can see, it can be fixed only by making a couple of tweaks to the parser…

caveat scriptor

EDIT: this particular bug relating to ‘verbless grammar’ (the Darcy, … snippet problem) appears to have been fixed in Ver 10.1, although the other problems identified in this thread persist.

2 Likes