Omnimaga
Calculator Community => TI Calculators => Axe => Topic started by: aeTIos on April 14, 2011, 12:20:11 pm
-
Hello, I am experimenting with a possible 83+ Lua interpreter, and I wondered how I can parse strings best. Should I use tokens or just input?
If input, how can I parse it best (via an interpreter, it reads a program)
If tokens, can I change token names in some way?
Thanks!
-
well, in assembly it might be much smaller, but here is an axe code for doing that:
Lbl PAR
"PARSE :)" -> Str1
"PARTY :D" -> Str2
Length(Str1) -> B
For(A,0,B
!If {Str1+A} = {Str2+A}
-1 -> A (this is a -1, not a negative 1)
End
If A = B
//do stuff that needs to be done if it parsed the same
End
This takes Str1 as the example and Str2 as the thing compared to the example. It would be pretty fast - though like I said in assembly would be much faster :) Also, the string being parsed cannot be 65535 characters long, so keep that in mind :P
-
Haha lol it won't be that long I think :)
Thanks!
-
Maybe I can even give you an assembly example, in just a minute ;) Just a second, I'll edit it in.
LD HL, Example
LD DE, StringToBeParsed
LD B, LengthOfExample
Loop
EX DE,HL
LD A,(HL)
EX DE,HL
CPD
JR NZ,NotSame
DJNZ Loop
Same
;code for what to do here
NotSame
RET
That should be a more optimized version, in assembly ;)
Hope you likes, since I am not an asm master, it could be optimized more I'm sure, but this alone is much better than the axe version :)
-
Haha lol it won't be that long I think :)
Thanks!
Never assume that when it comes to users :P
-
Never assume that when it comes to users :P
You mean, strings >65535 bytes? Lol.
-
I edited into my second post the assembly version ;) It should be much smaller and faster. Though, you might wanna disassemble it to get the Hex code :( or I can try right now in IRC :) I'll edit in the hex in a moment
EDIT: or not ;)
-
/smiley flood (lol)
Yep, an hex version would be useful. Wont know how to fit it in the axe code (cuz there are 2 different cases), though, so you should probably give some explaination.
-
Thing is, the routine would have to be changed around for it to be "slid" into axe code. The first one is for Axe only -- the second one would have to have some way of knowing the current Axe address and the address of a later part to work in an axe program -- but it would be perfect in an assembly program :)
-
Yep, I see. Can't you change it to output either 0 or 1 and let the strings input in str1 and 2? Or is that too hard?
-
well, the input isn't really the hard part (It would be really simple actually as an axiom command) but the data flow and the allowing of stuff to work in order the way I have it. However, this might be a simple solution once the next Axe version comes out with stack commands -- if you don't wanna wait, I can write you a an Axiom Version ;)
POP HL
POP DE
POP BC
XOR A
Loop
EX DE,HL
LD A,(HL)
EX DE,HL
CPD
JR NZ,NotSame
DEC BC
JP PE,Loop
Same
INC A
NotSame
LD H,0
LD L,A
PUSH HL
You could then access the command like this:
Length(Str2) -> n
Str2 -> n
Str1 -> n
Asm(the opcode)
n -> A
this would do the parsing and store 1 to A if the two strings are equal, and 0 to A if not. :)
EDIT: and I'm proud to say I was able to write those routines myself :) I don't feel so total noobish anymore in asm :D
-
You do realize there was a new command added in 0.5.1 to compare string equality right ? Equ>String(Str1,Str2) ;)
-
Cool! Just gotta get 0.5.1 on my calc!