Re: modified interpreter
- Posted by "Kat" <gertie at visionsix.com> Jun 29, 2005
- 538 views
On 29 Jun 2005, at 3:40, Matt Lewis wrote: > > > posted by: Matt Lewis <matthewwalkerlewis at gmail.com> > > Kat wrote: > > > > Has anyone else built a Eu modified interpreter which implements a > > restricted goto like D, or Xbasic, or QWbasic, or mirc ? > > > > wanted: > > goto label > > goto variable > > goto computed label -- goto 5 + variable > > > > restrict: > > no goto into loops > > no goto into/outof proc/functions > > Haven't done this yet, although after implementing the 'continue' statement, I > think it shouldn't be too difficult. I implemented continue using the EXIT IL > code, which is basically just a goto. The most challenging part would be to > implement the label mechanism itself. Could you elaborate on 'goto variable' > and 'goto computed label'? I'm guessing that the 'goto variable' might be > something like this: }}} <eucode> > :some_label > puts(1, "Some label\n" ) > > :another_label > puts(1, "Another label\n" ) > > g = "some_label" > goto g -- same as goto "some_label" > </eucode> {{{ That's a good example, yes. Not good coding style, but a good goto example for what i meant. > I think that if I were implementing this, I'd make the argument for goto > be some sort of value (i.e., not a label bareword). You mean not a string variable label? Ouch, i was going to use almost exclusively strings! > I'm not sure what > 'goto 5 + variable' means, though.
integer x x = 12 puts(1,sprintf("%d",x)&"\n") -- goto x goto x + 3 :1 :2 puts(1,sprintf("%d",x)&"\n") goto end :3 :12 puts(1,sprintf("%d",x)&"\n") goto end :15 puts(1,sprintf("%d",x)&"\n") goto end :end
prints: 15 Yes, another good example of rather bad coding AND the "evaluated goto" i meant. The interesting part is, if the label isn't there, there's no error and it doesn't go anywhere. And if there's labels and no goto to call them, that's ok too! Makes a nice case (or switch) statement. I really believe this is a good idea also:
function(sequence example) --code for loop = 1 to whatever do -- code while blah do -- code if zortched then goto end end if -- code end while -- blah -- code end for -- whatever return blarg :end -- special zortched code end function
The reason is it gets terribly non-normal exceptions out of the normal program flow as it's read, plus it's faster and cleaner than flag vars being constantly tested for "break"ing and "exit"ing or "continue"ing. It provides for a consistant block of zortch-handling code inside the function. Naturally, any jump out of any loop, in any direction, resets the loop vars. > > While you are at it, perhaps string execution? > > > > This has nothing to do with OO. > > OOEU has string execution (OOEU is really more than OO, even though that's the > name I chose). The latest release (v1.6.0) is at: > http://prdownloads.sourceforge.net/wxeuphoria/ooeu-src-1-6-0.zip?download Cool, upgraded!, thanks! > You don't need wxEuphoria unless you want to use the debugger. > > Matt Lewis Kat