Bubbling Beaker Awards (Award #33, February 07 2025)

Here is a method to find the address of the GPR routine represented by a token such as [color], by pulling it from the grammar of a verb word that in the first grammar line in its grammar table includes [color] as the first token after the verb word.

In this example, after Understand "mix [color] with [second-color]" as mixing it with., the grammar token [color] is indeed the first token after ‘mix’ in a single grammar line, so…

First when play begins: set color token.

To set color token: (- default_color_token=GetGPRRoutine('mix'); -).

Include (- 
Global default_color_token;
[ GetGPRRoutine verb_wd i line_address first_ttype first_tdata pcount;
! call this with a verb (dictionary word) and if the 1st token of the 1st grammar line for that verb is a GPR routine, the function returns its address

	i = DictionaryWordToVerbNum(verb_wd);

	line_address = ((#grammar_table)-->(i+1))+4;     ! look up start of grammar table for this verb, skip 1 byte for <no of grammar lines>; 3 for <##action name + flags byte> of first line, to reach first token
	first_ttype=line_address->0 & $0F;                         ! token type (we want GPR_TT)
	first_tdata=(line_address+1)-->0;                           ! token data
	
	if (first_ttype==GPR_TT) return first_tdata;    ! first_tdata is address of the GPR routine
	print "###Error - GetGPRRoutine() tried to find a GPR routine address from the first grammar token of the verb'", (address) verb_wd, "' but that token wasn't a GPR routine.^^";
!	PrintGrammar(verb_wd);
	rfalse;
];
-).

which means when play begins, the I6 global default_color_token now contains the address of the GPR routine represented by [color], and we can use that in our second colour token routine, thus:

[ second_color_token x firstnum;
	firstnum = parsed_number; ! saves the first parsed number locally
	x = ParseToken(GPR_TT, default_color_token); ! <- global assigned when play begins with the address of the [color] token GPR routine
	if (x == GPR_FAIL or GPR_REPARSE) return x;
	second_color = parsed_number; ! saves the second parsed number into a global
	parsed_number = firstnum; ! returns the first number to its usual global spot
	return GPR_PREPOSITION;
];
5 Likes