You will probably find these BatLib commands most useful:
124 = NewVar dim(124,Size[,Option],"VarName")
123 = DBDelLine dim(123,LineByte,LineNumber,"VarName")
117 = SearchReplace dim(117,"VarName","SearchString","ReplaceString")
110 = NumStr dim(110,Number)
94 = InsString dim(94,Offset,"VarName","String"|Str#)
54 = DBRead dim(54,LineByte,Line,"VarName")
With those commands, you can create an appvar, you can read each line of code using DBRead, you can convert numerical inputs into strings, and you can insert a string of code into the program, adding it as a new line. Inserting a line requires some clever trickery, (you have to add a newline token to the string), but to insert a line at the beginning of the program:
Str1+dim(65,63 ;add a newline to the end of Str1
Of course, that can be optimised, but I was trying to make it a little more clear:
Unfortunately, I have yet to add an actual InsertLine command for BatLib (there are about 8 bytes left of coding space— not enough to add a new command), so you can only easily insert a line at the start or end of the variable.
Now, to provide a BASIC solution, why don't you store the whole code in one string? You can separate lines with some token or series of tokens like "::" Here, try this on your calc:
I'm sure you will pick up what is happening immediately. You can then use this to parse Str1 line by line :)
Also, are you making a compiler or a parser/interpreter? The two are very different. Unless you are actually reading the code and converting it to a different format, it is not a compiler. If you are reading the code and converting on the fly, that is a parser.