Author Topic: Help parsing a string  (Read 11850 times)

0 Members and 2 Guests are viewing this topic.

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Help parsing a string
« Reply #15 on: January 20, 2011, 10:35:39 pm »
well i tried copying the prgm token to the string then copying the progname to the string after the prgm token, but when i display it it spits out garbage. im sorry i know i really suck at this

Can you post your copying and displaying code together? Someone may be able to see what went wrong.
« Last Edit: January 20, 2011, 10:36:02 pm by Deep Thought »




Offline Broseph Radson

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 295
  • Rating: +20/-1
  • Its 0x1A4 somewhere
    • View Profile
Re: Help parsing a string
« Reply #16 on: January 20, 2011, 10:44:24 pm »
ok i can try. my phone doesnt do hard returns though.
Code: [Select]
input->I:Tprgm->{R}:I->{R+1}:Disp R Input wont store to a string pointer and i dont want to use OS variables unless i absolutely have to.

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Help parsing a string
« Reply #17 on: January 20, 2011, 10:45:03 pm »
Um, what's R again? What does it point to?

If you never set it (like with GetCalc("Str0")→R) R could point to any address in memory. Most likely R is 0, which points to a location in the flash memory. You're not allowed to store anything to flash, so when you do Tprgm→{R}, it doesn't do anything.
« Last Edit: January 20, 2011, 10:46:49 pm by Deep Thought »




Offline Broseph Radson

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 295
  • Rating: +20/-1
  • Its 0x1A4 somewhere
    • View Profile
Re: Help parsing a string
« Reply #18 on: January 20, 2011, 10:47:25 pm »
The completed string which i want to be "prgmWHATEVS". EDIT: tried doing Tprgm->R instead of {R} and it displayed different garbage.
« Last Edit: January 20, 2011, 10:51:10 pm by Broseph Radson »

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Help parsing a string
« Reply #19 on: January 21, 2011, 09:26:25 am »
The completed string which i want to be "prgmWHATEVS". EDIT: tried doing Tprgm->R instead of {R} and it displayed different garbage.

You're using R as a pointer when you store it as {R}. In other words, the variable R should already be holding an address in memory where you want to store it, or else you're storing to any random spot in memory.

If you just do Tprgm->R, you're setting the address to the value of Tprgm, which is $5F, which is still a random spot in memory. In fact, it still points to flash, and so it's still not doing anything.

The thinng is, R isn't actually a variable. It's just two bytes at a specific spot in memory. When you do {R}, you're taking the value of R and storing to that address. So if R were 32768, {R} would be the byte stored at the 32768th byte in memory. You can't just randomly store to {R} and expect it to be at a safe place.
« Last Edit: January 21, 2011, 09:27:51 am by Deep Thought »




Offline Broseph Radson

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 295
  • Rating: +20/-1
  • Its 0x1A4 somewhere
    • View Profile
Re: Help parsing a string
« Reply #20 on: January 21, 2011, 09:38:08 am »
Code: [Select]
GetCalc("Str0")->A
GetCalc("Str1")->R
[sup]T[/sup]prgm->R
input->A
A->{R+1}
Disp R

Doesnt display properly, but Str1 does have the token in it. The input appears to not store the input as a string...

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Help parsing a string
« Reply #21 on: January 21, 2011, 10:34:21 am »
Oh, you do init R, never mind then :)

But when you do input→A, you're only storing the pointer to the inputted string to A. When you do A→{R+1}, you're storing this value to the string (actually only the smaller byte of it). You need to replace the line A→{R+1} with Copy(A,R+1,LENGTH) and it should work. Make sure Str1 is at least LENGTH+1 long, though.




Offline Broseph Radson

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 295
  • Rating: +20/-1
  • Its 0x1A4 somewhere
    • View Profile
Re: Help parsing a string
« Reply #22 on: January 21, 2011, 10:38:50 am »
Derp moment there. Forgot to give Str1 a size. RAM clear lol. 1 more try
Code: [Select]
GetCalc("Str0",9)->R
GetCalc("Str1",8)->A
input->A
[sup]T[/sup]prgm->R
Copy(A,R+1,8)
Disp R
Gives the following output:
■■■#F2.43

Also Str1 is a bunch of question marks
« Last Edit: January 21, 2011, 10:54:17 am by Broseph Radson »

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Help parsing a string
« Reply #23 on: January 21, 2011, 11:34:00 am »
Tprgm->R

Why that? You're storing the value as an address again, not to the address.

Replace it with Tprgm->{R}.




Offline Broseph Radson

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 295
  • Rating: +20/-1
  • Its 0x1A4 somewhere
    • View Profile
Re: Help parsing a string
« Reply #24 on: January 21, 2011, 11:46:47 am »
I am so fail at this lol. testing...

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Help parsing a string
« Reply #25 on: January 21, 2011, 02:30:15 pm »
Is there any reason you're using the OS string variables for this? It might be easier to just use your own data storage. Also, prgm is a token, not a character, and would not display correctly as part of an ASCII string. May I suggest something like the following?

Code: [Select]
.Prepare a string buffer
"prgm"Zeros(9)→Str1
.Fill the string buffer with input
Copy(input,Str1+1,8)
.Display prgm token
Disp ᵀprgm►Tok
.Display program name
Disp Str1+1

Str1 will also contain the correct data for any GetCalc() operations that you may want to perform after this.
« Last Edit: January 21, 2011, 02:30:47 pm by Runer112 »

Offline Broseph Radson

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 295
  • Rating: +20/-1
  • Its 0x1A4 somewhere
    • View Profile
Re: Help parsing a string
« Reply #26 on: January 21, 2011, 04:04:34 pm »
Wow thats cool i didnt know input could be used like that. It works thanks!

Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
Re: Help parsing a string
« Reply #27 on: January 21, 2011, 04:12:14 pm »
I'm not sure exactly what you're doing, but if you need something very adaptable and want to define the keys, you could always use the more complicated method I used for command line:

1) Record Keypress
2) Determine if Keypress is within valid range
3) Search for keycode in lookup table
4) Use data associated with lookup table to look up the input token in another table
5) Write data to known location
6) Repeat steps 1-6 until user presses Enter
7) Write termination data to the end of the location
8) Step through string until a match is found within parser commands
9) Jump to location of executable code associated with parser command
10) Execute data
11) Return to step 1
« Last Edit: January 21, 2011, 04:12:39 pm by Qwerty.55 »
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

Offline Broseph Radson

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 295
  • Rating: +20/-1
  • Its 0x1A4 somewhere
    • View Profile
Re: Help parsing a string
« Reply #28 on: January 21, 2011, 04:21:15 pm »
I am a fan of graphscreen input, but until i can memorize the math to do a lookup, its a bit out of my range. I think i can find out though. I believe someone posted how to do that somewhere

Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
Re: Help parsing a string
« Reply #29 on: January 21, 2011, 04:24:26 pm »
Actually, it's surprisingly easy in Axe. I cheat and use the inString command, where the string to be searched contains the hex keycodes of all of the keys used.
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ