Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!decwrl!ucbvax!CS.ARIZONA.EDU!kwalker From: kwalker@CS.ARIZONA.EDU (Kenneth Walker) Newsgroups: comp.lang.icon Subject: RE: fits posting; new l_scan() routines Message-ID: <9008032305.AA28394@megaron.cs.arizona.edu> Date: 3 Aug 90 23:05:32 GMT Sender: daemon@ucbvax.BERKELEY.EDU Distribution: inet Organization: The Internet Lines: 72 > Date: 3 Aug 90 16:19:17 GMT > From: ux1.cso.uiuc.edu!midway!sophist!goer@iuvax.cs.indiana.edu > I want very much to prototype this new scanning method using user- > defined control structures, but it's proving very hard. Emulating regular string scanning using user-defined control structures is also awkward. There is a way to emulate string scanning using nested procedure calls. It does not correctly handle breaking out of string scanning (but then neither did the Icon intepreter until V7!). The idea is to translate expr1 ? expr2 into escan(bscan(expr1), expr2) (Of course, expr2 can be a compound expression, if you want it to be.) This allows the setup routine, bscan, to comunicate with the termination routine, escan. It allows nesting of scanning along with full backtracking into and out of scanning. In addition, escan returns the value of the scanning expression. Saved scanning environments are stored in records record scan_env(subject, pos) procedure bscan(expr1) local outer_env outer_env := scan_env(&subject, &pos) &subject := expr1 &pos := 1 suspend outer_env # pass saved environment to escan &subject = outer_env.subject &pos = outer_env.pos fail # resume expression for expr1 end procedure escan(outer_env, expr2) local inner_env inner_env := scan_env(&subject, &pos) &subject = outer_env.subject &pos = outer_env.pos suspend expr2 outer_env.subject = &subject outer_env.pos = &pos &subject = inner_env.subject &pos = inner_env.pos fail # resume expression for expr2 end (disclaimer: these routines are based on code that works, but I typed them in without trying to translate or run them) This bscan-escan expression works well if you are using a preprocess (for example, one bassed on the variant translator system) to translate from a notation that looks like a control structure, but looks rather odd if you code it directly. However, it may give you some ideas. The only way I know of to solve the "break" problem is to use something more primative than suspend (break just wipes out suspened generators without considering that something more might need to be done), but you can only do this in the run-time system routines written in C, not within Icon itself. Ken Walker / Computer Science Dept / Univ of Arizona / Tucson, AZ 85721 +1 602 621-4324 kwalker@cs.arizona.edu {uunet|allegra|noao}!arizona!kwalker