I wanted to find -all- the recursive SUBS and FUNCTIONS inside Bc.bas
Being the lazy type, I told ChatGPT what I wanted. After wasting well over an
hour yesterday, I gave up on that idea and decided to write it myself today.
Here are the recursive SUBS and FUNCTIONS:
JoinStrings
JoinStrTest
BracketHandler
MakeDecProto
GetParameter
Press any key to continue . . .
Here is how I found them:
DIM Stk$[256], Ndx, Filename$, Src$, NamedFunc$
Filename$ = "bc.bas"
IF NOT EXIST(Filename$) THEN
PRINT "File not found ... Aborted."
END
END IF
OPEN Filename$ FOR INPUT AS 1
WHILE NOT EOF(1)
LINE INPUT 1, Src$
Src$ = TRIM$(STRIM$(EXTRACT$(Src$, "'")))
FastLexer(Src$, SPC$, "=&()[]{}',+-*/<>?;.|:^")
IF LCASE$(Stk$[1]) = "sub" OR LCASE$(Stk$[1]) = "function" AND TRIM$(Stk$[2]) <> "=" THEN
NamedFunc$ = Stk$[2]
ITERATE
END IF
IF LCASE$(Stk$[1]) = "end" THEN
IF LCASE$(Stk$[2]) = "sub" OR LCASE$(Stk$[2]) = "function" THEN
NamedFunc$ = ""
ITERATE
END IF
END IF
FOR INT i = 1 TO Ndx
IF Stk$[i] = NamedFunc$ THEN
PRINT NamedFunc$
NamedFunc$ = ""
EXIT FOR
END IF
NEXT
WEND
CLOSE 1
PAUSE
SUB FastLexer (Arg$ AS LPCTSTR, delim1$ AS LPCTSTR, delim2$ AS LPCTSTR, TokQuote = 1)
'**********************************************************************************
' delim1$ = delimiters to remove
' delim2$ = delimiters to keep
'
' When TokQuote = 1: Quoted strings are treated as individual tokens.
' Each quoted string is processed separately, terminated, and stored
' in the token stack as a distinct token.
'
' When TokQuote = 0: Quoted strings are not treated as separate tokens.
' They are included as part of larger tokens, potentially concatenated
' with other characters outside the quotes.
'
' Stk$[] and Ndx are GLOBAL
' As long as Ndx is honored, Stk$[] does not need to be initialized
'**********************************************************************************
DIM RAW pd1 AS PCHAR
DIM RAW pd2 AS PCHAR
DIM RAW cnt1, cnt2
cnt1 = cnt2 = 0
Ndx = 1
DO WHILE Arg[cnt1]
IF Arg[cnt1] = 34 THEN ' quotes - string literals
IF cnt2 AND TokQuote THEN
Stk[Ndx++][cnt2] = 0
cnt2 = 0
END IF
Stk[Ndx][cnt2] = 34
DO WHILE Arg[++cnt1] <> 34
Stk[Ndx][++cnt2] = Arg[cnt1]
IF Arg[cnt1] = 0 THEN EXIT SUB
LOOP
Stk[Ndx][++cnt2] = Arg[cnt1]
IF TokQuote THEN
Stk[Ndx++][++cnt2] = 0
cnt2 = 0
GOTO again
END IF
END IF
pd1 = CAST(PCHAR, delim1)
DO WHILE *pd1
IF *(pd1++) = Arg[cnt1] THEN
IF cnt2 THEN
Stk[Ndx++][cnt2] = 0
cnt2 = 0
END IF
GOTO again
END IF
LOOP
pd2 = CAST(PCHAR, delim2)
DO WHILE *pd2
IF *(pd2++) = Arg[cnt1] THEN
IF cnt2 THEN Stk[Ndx++][cnt2] = 0
Stk[Ndx][0] = Arg[cnt1]
Stk[Ndx++][1] = 0
cnt2 = 0
GOTO again
END IF
LOOP
Stk[Ndx][cnt2++] = Arg[cnt1]
again:
INCR cnt1
LOOP
Stk[Ndx][cnt2] = 0
IF cnt2 = 0 THEN DECR Ndx
END SUB ' FastLexer