Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!ucbvax!astroatc.UUCP!tenaglia From: tenaglia@astroatc.UUCP (Chris Tenaglia) Newsgroups: comp.lang.icon Subject: (none) Message-ID: <8907191744.AA03022@astroatc.UUCP> Date: 19 Jul 89 17:44:34 GMT Sender: daemon@ucbvax.BERKELEY.EDU Distribution: inet Organization: The Internet Lines: 49 Dear Icon-Group, I am a heavy Icon user. We have icon in DOS, UNIX, and VMS. Having benefitted so much from it, I feel glad to be able to contribute a little. Below is one of my favorite procedures. I realize it can be done in line with the string scanning features. But I discovered, I do the same string scanning over and over. So I composed this software chip that I include in many programs. It could be ucoded too. I leave that up to the programmer. This first one is more general. As a postscript I include a variation that is a little more specific, but still very useful. It can be used in an assignment -> words := parse(line) Or on the fly -> if parse(line,' :,')[3] == "X800" then... ################################################################## # # # THIS PROCEDURE PULLS ALL THE ELEMENTS (TOKENS) OUT OF A LINE # # BUFFER AND RETURNS THEM IN A LIST. A VARIABLE NAMED 'CHARS' # # CAN BE STATICALLY DEFINED HERE OR GLOBAL. IT IS A CSET THAT # # CONTAINS THE VALID CHARACTERS THAT CAN COMPOSE THE ELEMENTS # # ONE WISHES TO EXTRACT. # # # ################################################################## procedure parse(line,delims) if delims === &null then delims := ' \t' chars := &cset -- delims tokens := [] line ? while tab(upto(chars)) do put(tokens,tab(many(chars))) return tokens end #ps procedure parse(line) static chars initial chars := &cset -- ' \t' tokens := [] line ? while tab(upto(chars)) do put(tokens,tab(many(chars))) return tokens end Chris Tenaglia Astronautics Corporation of America 4115 N. Teutonia Avenue Milwaukee, Wi 53209 USA (414) 447-8200 X-421