E.K.,
It's the good old problem of line parsing...? Multiple statements on one line are separated by the colon symbol... Hmm... so first you always must make sure the colon symbols occuring in a line are not part of a string themselves. It is unavoidable to write a miniparser to replace non-embedded ':' symbols to some other value, for example NL (0x0A). This is what I do myself too in the BaCon version of BaCon.
Then I would use the SPLIT statement to dynamically separate the string into elements, each of which can be parsed individually.
Hope the below helps!
Peter
' The variable with the line of BASIC
line$ = "PRINT \"MYBASIC: parser\": FOR x = 1 TO 10: PRINT x: NEXT x: END"
' Some declarations
token$ = ""
escaped = 0
in_string = 0
' Step 1: make sure colon is translated to newline symbol
FOR x = 1 TO LEN(line$)
SELECT MID$(line$, x, 1)
' Separator
CASE ":"
IF ISFALSE(in_string) THEN
token$ = CONCAT$(token$, CHR$(10))
escaped = FALSE
ELSE
token$ = CONCAT$(token$, ":")
END IF
' Escape symbol
CASE CHR$(92)
token$ = CONCAT$(token$, CHR$(92))
IF ISFALSE(escaped) THEN
escaped = TRUE
ELSE
escaped = FALSE
END IF
' Quote symbol
CASE CHR$(34)
token$ = CONCAT$(token$, CHR$(34))
IF ISFALSE(escaped) THEN in_string = NOT(in_string)
escaped = FALSE
DEFAULT
token$ = CONCAT$(token$, MID$(line$, x, 1))
escaped = FALSE
END SELECT
NEXT
' Step 2: split into separate elements
SPLIT token$ BY CHR$(10) TO element$ SIZE dim
' Print results
FOR x = 0 TO dim-1
PRINT CHOP$(element$[x])
NEXT