Hi,

Might be worth looking at how programs like the Structured SuperBASIC
and BASIC Linker work to see if anything can be learned from those,
perhaps.

I don(t know hox Structuerd Superbasic does it, the Baic linker does the following:

It collates and numbers the source files, saving them as a normal basic file.
then it calls a parser to parse that file and generate a _sav file.

This is done in a function as follows:



def fn call_parser_ok%
rem this makes the parser command line and calls the parser
rem it returns 1 if all ok, else 0 or -1 if parser not found
rem if any errors, it prints them out
rem if there is an sbasic, it calls sbasic as parser, else the parser file
rem
rem uses global vars parser_file$, error_string$, sav_file$ ...
rem ... parser_cmd$, errfile$, error_message$
rem v. 1.01
local chan%,a$,call_error%,is_sbasic%
  is_sbasic%=is_thg("sbasic")   : rem check: is sbasic there?
  pe_cls#scr_chan%
  pe_print#scr_chan%, cr$&centr$(info_message$(2),warning_width%)
          &cr$&centr$(output_file$,warning_width%)
  if parser_file$="" and not is_sbasic%
    unst
    error_string$=error_message$(1)     : rem no parser name &
                                          not dbasic!
    print_error 0                       : rem print this error now
    return 0
  endif
  call_error%=0                         : rem preset no error
  chan%=topen(parser_cmd$)              : rem try to open_over
                                              parser cmd file
  if chan%<0
    unst
    error_string$=error_message$(2)&cr$&parser_cmd$
    print_error chan%
    return 0
  endif
  if is_sbasic%
    a$='10 Load '&output_file$  : rem command line if we're sbasic
  else
    a$=output_file$&" \W"               : rem parser_exe: write file
                                              only, (don't compile)
  endif
  print#chan%,a$:PRINT#chan%            : rem print command to cmd file
  close#chan%
  if is_sbasic%
    chan%=fop_over(errfile$)            : rem use error file as channel
                                                #0 (!)
    print#chan%,"qsave "&sav_file$      : rem command in channel #0
    close#chan%                : rem now make sure that the _sav file...
    delete sav_file$           : rem ...doesn't exist already (else:
                                        it's not overwritten!)
    ew parser_cmd$,errfile$     : rem ew sbasic, passing the 'load
                                      file' as...
                      : rem ... parameter string, and the "_sav file"...
                      : rem ... as channel 0
  else
    if parser_file$<>"" and not ftest(parser_file$)
       ew parser_file$,parser_cmd$,errfile$ : rem exec parser normally
    else
       unst                     : rem parser not found!
       error_string$=error_message$(28)
       print_error 0            : rem so complain
       return -1
     endif
  endif
  if check_errors%(errfile$)
unst : rem there were errors during parser
    error_string$=error_message$(3)
    print_error 0
    return 0
  endif
  delete parser_cmd$            : rem get rid of parser command file
  return 1                      : rem return all ok
end def call_parser_ok%
:

So, if this is running on SMSQ/E, an sbasic job is used (invisibly) as parser (with some jiggery-pokery for the input/output files), else the parser supplied with the basic linker is used.

The resulting tokenized "sav" file is saved and compiled with Qliberator...

Wolfgang


_______________________________________________
QL-Users Mailing List
http://www.q-v-d.demon.co.uk/smsqe.htm

Reply via email to