So, I have endeavored to create a program that will allow a user to combine a program and it's subroutines into one program. Right now, the general idea is to make the source the final product and reading each line, checking for the 'prgm' token, and if it exists, removing the 'prgm' tag from the string, and saving the resultant to a string - Str3 to be exact. Then, it reads the subroutine, and writes the output to the program.

While this seemed to be simple, insofar, it has proven to be very difficult. One of the problems that I have encountered is frequent crashes. Could the repeated read-write be the cause of this, or am I doing something wrong?
I'm fairly inclined to say that the crashes are because you're doing it wrong. What are you using to do this? Can you show us a simplified form of your code? What calculator(s) are you targeting?
I am targeting the TI84+CSE I am using the OS version 4.2, DCSE version 8.2.0 build 1603

My simplest code (note: I am using Str1 for the source, and Str3 for the subroutine)
My code is (rather ironically) divided into subroutines

Main :

Code:

//get number of lines in source and store to A

For(C,1,A)
C
det(0)
//check to see if 'prgm' token exists
then
Str9->Str8
sub(Str8,s,length(Str8)-1)->Str3
Str3->Str0
//number of lines in subroutine then store to B
For(D,1,B)
//readsub routine
//write to source
end
B+E->E
end


Reading source:

Code:

Str1->Str0
C+D+E
det(0)


Reading Subroutine:

Code:

Str3->Str0
D
det(0)


Writing to source:

Code:

Str1->Str0
C+D+E
det(2)
I don't know how you could efficiently figure out how many lines there are in a given program using the DCSE libs (something better than reading consecutive lines until you get an error code), but assuming you've got that figured out, then your code looks fine to me, although you will want to make sure that you write down the tokens exactly as they appear on your calculator ("Then, End, etc.") or else they will not be switched to tokens when you send this file to your calculator. You can check for the prgm token on a line with the inString() command like this:

Code:
If inString(Str9,"prgm


EDIT: Why do you use subprograms so much?
mr womp womp wrote:
I don't know how you could efficiently figure out how many lines there are in a given program using the DCSE libs (something better than reading consecutive lines until you get an error code), but assuming you've got that figured out, then your code looks fine to me, although you will want to make sure that you write down the tokens exactly as they appear on your calculator ("Then, End, etc.") or else they will not be switched to tokens when you send this file to your calculator. You can check for the prgm token on a line with the inString() command like this:

Code:
If inString(Str9,"prgm


EDIT: Why do you use subprograms so much?


1:
If you attempt to read line 0 (ans=0 when calling det(0)) it returns the number of lines in the program to θ
2:
I have noticed that when I read the lines, the tokens are preserved (that may be what is causing problems).
3:
I use so many subprograms because it helps me troubleshoot problems that don't necessarily cause TI-OS to throw an error. and I can get to those parts of my code faster. For example, if I were to have a program that gets an input, and outputs it to random points on the screen, and the points were not being randomized, rather than breaking the program, and hoping that I land somewhere near the problem, I can go straight to the subprogram that has the randomizing code, make sure that it is free of errors, then can check to make sure that my program flow is correct.
Another, more simpler way to say the above: It allows me to treat TI-Basic variables like objects, with the subprograms being 'methods'. then I use the main program for flow, and the subprograms for operations on the variables.
This has proven useful in many of my programs that I have made.
1:

Mind = Blown
2: It should not cause problems... remember the tokens are all in a string so as long as they stay in a string, they should be treated like characters... except maybe the sto► arrow and " teardrop quotes, which might be a bit iffy to mess around with in a string, but even those I think should be just fine.
3: It hurts my brain. ლ(ಠ益ಠლ)
It makes sense that the program's header would contain the length of the program. (what about... line -1?)
oldmud0 wrote:
It makes sense that the program's header would contain the length of the program. (what about... line -1?)


After I did some research (A.K.A I typed length("prgm) I found that the prgm token has a length of one, and with that being said, I needed to make sure that I didn't specify a string length greater than the length of the string, since I am removing the first 'character'.
How is the project going?
Nik wrote:
How is the project going?


I am still encountering crashes, but my last try had been fully copying the code, but it was writing it backwards (Line 1 would be Line 5 in a 5-Line program) but each line was in order. I deleted me 'test' program, and then my calculator crashed. I am starting to think that it may be because I am constantly using the On-Break when I find an error.
New update:

I now have a working version, and it is archived, however, due to the issues with the crashing, I will probably be testing it for a while. One change I have made is to, rather than seeing how big the original file is, I am simply using a repeat loop since it is much simpler
Any ideas on how to break the program?

So far, I have noticed that frequent use of using the on-break (approximately 15 times) is the cause of the crash. I am also going to create a log-maker to help people analyze where their program is crashing. (I hope this will be much easier to do)
BigSmoke3320 wrote:
Any ideas on how to break the program?

I am not sure I understand what you mean here...
Nik wrote:
BigSmoke3320 wrote:
Any ideas on how to break the program?

I am not sure I understand what you mean here...


Any code to compile to try to cause my calculator to crash during execution.
BigSmoke3320 wrote:
Any code to compile to try to cause my calculator to crash during execution.

Cosidering the lack of a list of things you already tried, examples and the compiler itself, this a very hard question.
Try one with no subprograms, one with only one, one with many (Overflow proof?). Then try empty and large subprograms. And that's about all I can think of right now...
Here is my source code:

Code:

0→E
Input "SOURCE: ",Str1
ClrHome
Output(1,1,"LOADING"
For(A,1,248)
" "+Str8→Str8
Output(2,1,iPart((A/248)*100)
End
Str1→Str0
0
det(0)

θ→A
1→C
If Str9≠"..P:NT:FN"
Then
Repeat Str9="..L:NT:FN"

Str1→Str0
C
det(0)
Output(1,1,"                          "
Output(1,1,">READ.MAIN")
Output(2,1,Str8
Output(2,5,Str9)

If inString(Str9,"prgm")
Then
Str9→Str8
sub(Str8,2,length(Str8)-1)→Str3
Str3→Str0
0
det(0)
θ→B

For(D,1,B)
Str3→Str0
D
det(0
Output(1,1,"READ.SUBS       "
Output(2,1,Str8
Output(2,5,Str9
If Str9≠"..NULLSTR"
Then
Str1→Str0

C+D
det(2
Output(1,1,"WRITE.SRC"
End
End
End
C+1→C
End
End
After a long hiatus due to the frustration with my code, and me questioning my abilities, I have decided to revive this project, and hopefully get it to work dependably. First, I am starting from scratch, and am taking a completely different approach than my original approach, hopefully this approach will result in a more simple code, and will therefore encounter fewer bugs, If my attempts at a pure BASIC version are successful, I do plan on making a Hybrid BASIC version also, simply for the aesthetics.

Current pseudo-code:



Code:

0→ErrorCode
Get Main_Source_Name
Check to see if Main exists

If not(Main) exists
then
1→ ErrorCode
goto end
end

Get output_name
Check If ouput exists
if output exists
then
2→Error
goto End
end

Lbl Again

get lineN

if lineN does not exist
then
0→Error
goto End
end

if lineN begins with token 'prgm'
then
   1→M
   lineN-'prgm' → Sub

   get lineM

   if lineM exists
   then
   1→Line_exits
   Write lineM to lineX

   M+1→M
   X+1→X
   ELSE
   0→Line_exists
   end

   if Line_exists=1
   goto Sub
ELSE
Write LineN to LineX
N+1→N
X+1→X
end

goto Again

lbl End

if Error=1
disp "Error:","Program Not Found"
If Error=2
disp "Error:","Program Already Exists"
If Error=0
disp "Operation Complete"

  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement