stevens@vms.macc.wisc.edu (Paul Stevens) (09/04/87)
I like forth. I have implemented a couple of simple forth systems. And yet I still don't feel comfortable with it at times. Some problems that would be so easy in assembly language ( with GOTOs ) cause me to produce the most terrible looking code in forth. One of the things I lack is the ability to ask the fellow at the next desk how he might do it. ( I am the only forther ). So I thought I would take advantage of the lull in the action and the experience of all you experts by proposing a simple problem I have come across and have been totally unable to solve reasonably. Other novices on the net might also enjoy seeing some 'right' ways of doing things. I want to search a command table in VAX/VMS style. The command table consists of counted strings. Each entry may or may not contain an asterisk to indicate how many characters are mandatory in order to match. For example [6]PR*INT would specify the print command and it says that it can be matched by any of PR, PRI, PRIN, or PRINT. It cannot be matched by P, PRO, or PRINTA. ( [6] represents the byte containing the character count ) A table entry need not contain an asterisk. For example [4]COPY could be matched only by COPY ( not COPYA ). So now....given the address of a counted string containing the command entered by the user and the address of a counted string representing an entry in the command table....how do we find if they match or not? My solutions were full of flags, alternate exits, and such crud. I also had an idea about a two pass approach: one to be sure that there were a sufficient number of characters and another to be sure that there weren't too many. None of the solutions seemed to me to be elegant. Anyone willing to demonstate a 'nice' solution? No fair changing the problem!!! Things seemed to get easier if I used null terminated strings but that ain't what I got! Paul Stevens stevens@vms.macc.wisc.edu MACC-1210 W. Dayton stevens@wiscmacc.bitnet University of Wisconsin Madison, Wisconsin 53706 (608)262-9618