Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!akgua!mcnc!decvax!harpo!ihnp4!zehntel!hplabs!sri-unix!O'KeefeHPS From: O'KeefeHPS@sri-unix.UUCP Newsgroups: net.lang.prolog Subject: A coding trick for grammar rules. Message-ID: <12452@sri-arpa.UUCP> Date: Wed, 4-Apr-84 06:05:13 EST Article-I.D.: sri-arpa.12452 Posted: Wed Apr 4 06:05:13 1984 Date-Received: Mon, 23-Apr-84 01:45:15 EST Lines: 31 From: O'Keefe HPS (on ERCC DEC-10) Someone here today wanted to write a grammar rule which could detect the end of a word. It isn't always possible to check the next character, becuase the word might be at the end of the string. What was needed was something like end_of_word --> ( end_of_string | [C], {not_in_word(C)} ). It finally dawned on me that I could write end_of_string(X, X). This dodge may be useful to other hackers. REAL hackers will doubtless prefer to write end_of_word --> ( = | [C], {not_in_word(C)} ). If one prefers not to eat the character following the word, one can write end_of_word --> = . % space needed for tokeniser! end_of_word, [C] --> [C], {not_in_word(C)}. Of course the clean way would have been to match the longest possible string of letters, digits, and underscores, but we were after a quick patch. I'm not at all sure that I care for any of this... Possibly we could start a Prolog Joke Book ?