a basic like gosub in C

Josh Siegel josh at crunch.uucp
Mon Feb 24 06:06:37 AEST 1986


In basic there is a GOSUB routine that will push the current
 position onto the stack and jump to another line.  Then, upon
 hitting a return will return to that place.  I wish to write
 something like that in C that will be movable between compilers.

A sample of something like it is below:

5  rem Basic
10 print "hi"
20 gosub 50
30 print "bye"
35 gosub 50
40 end
50 print "hello"
55 print "who are you?"
60 return

/* C code that does work */
main () {
    (void)gosub (0);
}
gosub (line)
int     line;
{
    switch (line) {
	default: 
	    puts ("hi");
	    (void)gosub (50);
	    puts ("bye");
	    (void)gosub (55);
	    exit (0);
	case 50: 
	    puts ("hello");
	case 55: 
	    puts ("who are you");
	    return (0);
    }
}


Can anybody think of a better way to do this? I want it for a
  Basic->C translator (Please, I am writting it for fun... No abuse...Please?).


	thanks much,

Send me mail . . . I   L O V E  mail

          Josh Siegel

        {convex,ucbvax,gatech,csu-cs,anl-mcs,lanl-a}!unmvax
                                                           \
                                                           !crunch!josh
                                                           /
{cmcl2,csu-cs,dirac,dspo,gel,ias,ihnp4,mtu,nmsu}!lanl!quark



More information about the Comp.lang.c mailing list