home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!howland.reston.ans.net!spool.mu.edu!yale.edu!yale!gumby!destroyer!ncar!noao!amethyst!organpipe.uug.arizona.edu!news
- From: dave@cs.arizona.edu (Dave Schaumann)
- Newsgroups: comp.lang.c
- Subject: Re: Conversion of BASIC code to "C"
- Message-ID: <1993Jan12.003007.26709@organpipe.uug.arizona.edu>
- Date: 12 Jan 93 00:30:07 GMT
- References: <1993Jan8.183821.20711@adobe.com> <1993Jan10.131651.1@csbina.csubak.edu>
- Sender: news@organpipe.uug.arizona.edu
- Reply-To: dave@cs.arizona.edu (Dave Schaumann)
- Organization: University of Arizona
- Lines: 64
- In-Reply-To: camp5@csbina.csubak.edu
-
- In article <1993Jan10.131651.1@csbina.csubak.edu>, camp5@csbina writes:
- >In article <1993Jan8.183821.20711@adobe.com>, (Scott Sivi) writes:
- >> Does there exist a method or application by which BASIC files can be
- >> converted
- >> to "C".
- >You probably couldn't even do it by hand unless the BASIC program was
- >completely flowed and never used a GOTO! The way BASIC programmers spaghetti-
- >code programs, I doubt it's possible. (I'm assuming you won't use goto in C.
- >I wouldn't.)
-
- Eh, you could do it. But given the sort of code you could generate, you'd
- probably be better off either hand-porting the code to C, or writing/buying
- a BASIC compiler.
-
- For instance, consider the simple BASIC program
-
- 100 FOR I=1 TO 10
- 110 GOSUB 200
- 120 NEXT I
- 130 END
- 200 PRINT "I=";I;"I^2=";I*I
- 210 RETURN
-
- Might "compile" to something like
-
- int line[] = { 100, 110, 120, 130, 200, 210, -1 } ;
-
- main() {
-
- int pc = 0 ;
- int uv_i ;
- for( pc = 0 ; 1 ; pc++ )
- switch( line[pc] ) {
- case 100: uv_i = 1 ; break ;
- case 110: GOSUB(200) ; break ;
- case 120: uv_i++ ; pc = 1 ; break ;
- case 130: exit(0) ;
- case 200: printf( "I= %d I^2 = %d\n", uv_i, uv_i*uv_i ) ; break ;
- case 210: RETURN ;
- default : printf( "SYSTEM ERROR\n" ) ; exit(1) ;
- }
-
- }
-
- GOSUB() would be a function that would push the current value of "pc" onto
- a stack, look up the appropriate label in the line[] array, and make that
- index the new value of "pc". RETURN would then be a macro that pops the
- top of the "pc" stack into pc.
-
- Of course, if maintainability is a concern, you would probably make some
- changes to make the program look more like BASIC (perhaps defining
- macros for each BASIC statement...). One obvious problem with this is
- that you're going to get one huge case statement inside one huge routine.
- Such a method is very likely to run into compiler limitations very quickly.
-
- Perhaps a more "modern" version of BASIC (perhaps with some helpful
- constraints) could be translated in a more one-to-one manner. Ultimately,
- I think you'll find that one of my original suggestions is the most practical,
- though...
-
- --
- [An intertialess drive] is not probable at all, at least in any extrapolation
- of present-day science. But as far as I can determine, it cannot be proved
- absolutely impossible, and that is enough for me. -E. E. "Doc" Smith
-