'_________INFO_______________________________________
' le funzioni DEF FN possono essere monoriga
' DEF fnP (a%) = a% + 1
' oppure multiriga
' DEF fnP (a%)
' a% = a% * 3
' fnP= a% + 1
' END DEF
' le definizioni monoriga o multiriga non si possono impilare a matrioska
' le DEF Fn devono avere almeno un parametro
' le DEF Fn non possono accedere alle variabili condivise
' nŠ avere variabili con lo stesso nome delle variabili condivise o globali
' ______________END of INFO___________________________
' Project of program__________________________________________
' pseudocodice per il traduttore di FN a FUNCTION
' siccome in QB64 FN non Š un token allora lo lasciamo dov'Š
' e prendiamo una strata pi— semplice
' apri il file da tradurre
' apri il file da tradotto da scrivere
' leggi il file riga per riga fino alla fine
' se c'Š un DEF FN
' se c'Š = Š una funzione a singola riga
' scrivi nel file tradotto
' FUNCTION e la parte della riga da FN e =
' FNnomefunzione = la parte della riga dopo =
' END FUNCTION
' altrimenti Š una funzione multiriga
' scrivi nel file tradotto
' FUNCTION e la parte della riga da FN in poi
' memorizza il nome della FN
' leggi il file riga per riga fino a quando
' trova END DEF o ottiene fine file
' se Š presente EXIT DEF scrivi EXIT FUNCTION
' se Š presente END DEF esci dal loop
' scrivi la riga
' END FUNCTION
'
' End of Project of Program____________________________________________________
' constants of token to translate
CONST Primo
= "DEF FN", Secondo
= "=", Terzo
= "FN" CONST Quarto
= "EXIT DEF", Quinto
= "END DEF", Sesto
= "(" ' variable to process lines of code
Counter% = 0 ' it counts how many functions are translated
Fi$ = "" ' File of input
Fo$ = "" ' File of output
Fdef$ = "" ' Temporary file for function translated
LineOfCode$ = "" ' it brings the line of code read from file
PRINT " Usage: DEF2FUN NamefileToTranslate" PRINT " It needs one parameter at run "
' name file has extention
Fo$
= LEFT$(NamFi$
, LenFi
- 3) + "Tmp" + ExtFi$
Fdef$
= LEFT$(NamFi$
, LenFi
- 3) + ".TMP" ' name file has no extension
Fo$
= "Tmp" + LEFT$(Fi$
, 3) Fdef$ = Fo$ + ".TMP"
' open files for input and output
PRINT " Opened Input file..." PRINT " Opened output file..."
' it puts author's sign
PRINT #2, " REM File made by DEF2FUNC utility by TempodiBasic " PRINT #2, " REM DEF2FUNC translate any function DEF FN to the FUNCTION syntax"
' main loop processing file
PRINT " Reading file...";
' search a definition of DEF FN
PRINT " Found a DEF FN: "; LineOfCode$
' is DEF FN in oneline or in multiline?
OneLine LineOfCode$, Counter%
Multiline LineOfCode$, Counter%
ELSE ' no definition of DEF FN PRINT "End of translation..." PRINT " Rebuilding the file..." PRINT " File translated ..."
Incr% = Intero% + 1
PRINT " It is a multiline DEF FN" ' this subprogram process a DEF FN on multiline
NextLine$ = ""
Counter% = Incr(Counter%)
'here it processes multiline DEF FN after the first line of code
PRINT #3, " EXIT FUNCTION "
SUB OneLine
(LineOfCode$
, Counter%
) PRINT " It is a oneline DEF FN" ' this subprogram process a DEF FN on oneline
Counter% = Incr(Counter%)
NameOfFN$
= MID$(LineOfCode$
, Start%
, Lenght%
) PRINT "FUNCTION "; NameOfFN$