Having been convinced that pi is wrong (tauday.com), I am now trying to switch out tau for pi on my 84+SE. This is my first time messing around with hooks, but I like to imagine myself as a somewhat competent assembly programmer.

I have been able to figure out rawkeyhook and getkeyhook for the most part, and have gotten my pi button can now spew out tau's. But I can't get parserhook straight, much less get tau's parsed as 2pi. Wiki Ti and this thread are the only significant resources I have found to deciphering parserhook, and some basic experimenting on my part did little to fill in the gaps.

In short, I am hoping that someone will be able to help me understand parserhooks better, or if I prove simply too think for this, to show me how to get tau's parsed as 2pi. Thanks.

edit:
Just realized I had linked the wrong tab for wiki ti, now it links to actual hook in question.
Can you be any more specific about what you need? Presumably, if you have worked with other hooks, you understand setting up, enabling, disabling, and chaining hooks. There are a bunch of threads about hooking and parserhooks here, but since I've played fairly extensively with them, I'd be happy to answer questions. Also, be aware that the MP OSes don't do parserhooks correctly without some hacks and workarounds. Finally, be sure to Introduce Yourself.
KermMartian wrote:
Can you be any more specific about what you need? Presumably, if you have worked with other hooks, you understand setting up, enabling, disabling, and chaining hooks. There are a bunch of threads about hooking and parserhooks here, but since I've played fairly extensively with them, I'd be happy to answer questions. Also, be aware that the MP OSes don't do parserhooks correctly without some hacks and workarounds. Finally, be sure to Introduce Yourself.


He wants pi to evaluate to 2 pi.
You have to stop responding in threads where you're not contributing anything useful.
KermMartian wrote:
You have to stop responding in threads where you're not contributing anything useful.


You asked that he be more specific. He wants to use tau instead of pi. Therefore, pi must evaluate to 2pi.
seana11 wrote:
KermMartian wrote:
You have to stop responding in threads where you're not contributing anything useful.


You asked that he be more specific. He wants to use tau instead of pi. Therefore, pi must evaluate to 2pi.
More specific about what's confusing him about parser hooks. Here at Cemetch, we prefer to teach people how to do things instead of just giving them code.
KermMartian wrote:
seana11 wrote:
KermMartian wrote:
You have to stop responding in threads where you're not contributing anything useful.


You asked that he be more specific. He wants to use tau instead of pi. Therefore, pi must evaluate to 2pi.
More specific about what's confusing him about parser hooks. Here at Cemetch, we prefer to teach people how to do things instead of just giving them code.


Ohhhhhhhh. That's what you meant. My bad.
First off, I don't actually want pi's parsed as 2pi. I want pi parsed as such, and for tau to be parsed as 2pi. Otherwise, it would ruin every other (ti basic) program already written. I had thought about doing it the other way (tokenhook to make pi's look like tau's, then parserhook to make pi's parse like 2pi), but I don't want to mess up stuff that has already been written. And either way, it's much less elegant; I'd like to avoid it if I can.

I've gotten the example code from wiki ti to work for making sin spew out random numbers, and I have also gotten it to work with other functions that take arguments. But just making the obvious changes (messing with a and changing bc) won't make pi or tau spew out random numbers. (I'll worry about getting 2pi once I can intercept the token at all) I would imagine that this is because pi doesn't take any arguments and it doesn't seem to fit in with the description of an a=2 token, and tau ordinarily doesn't do anything, so I have no idea.

I'd really appreciate it if you could spell out the inputs of parser hook for me, or point me to where they are. If there are any threads that enlighten one on this beyond what I linked, I sure can't find them. But then again, I would not be too surprised if it turns out that I am just that much of a noob.

I'd read about parserhooks being broken in MP OS's (only in the context of you working around it for DCS), but I don't have it, and have no intentions of defiling my calculator with MP. Smile
intercepting tokens or making custom tokens is actually rather broken in all new TI-OS versions, though if the token is already there it should be doable assuming tau is already in the OS and is usable.

In this case you should read up on TI's float format and I think what you'd want to do is replace instances of tau on the floating point stack with the value of 2*pi but I'm not 100% sure how math and parserhooks work on the calcs but looking through the omnicalc source code would be a good place to start.

I believe there is a version on ticalc.org with the legacy tokens patch which is what you'd want as all the new versions use "real(##" format for the functions in place of the cutsom tokens due to TI breaking support for them.
I know that you can't create new tokens anymore, but that's shouldn't be a problem since Tau is already a token ($BBCC), but I can't intercept any tokens that don't take arguments, whether or not they are already used for anything. I thought that the fps was used for passing arguments...
I believe this should be possible just like the hacked pics and strings and such should be but I could be wrong I think condition 0 of the hook may be what you are looking for. wikiti
Yes, I thought condition 0 would be what you want. I'm not sure how it'll work, but I suspect the token will simply be put into parseVar, so you can simply compare that value against the token you want. It's not clear if you can inject a value, but it's worth trying to put 2*pi in either OP1 or on the FPS, and play with the return value of your hook (allow further processing or not).
Based on my experiences, I believe you would:

1) Check if the current token is tau, if not, return after an xor a.
2) Set Op1 to 2*pi
3) set numOp1,(iy+parsFlag2)
4) ld a,1 \ or a \ ret

Let me know if that doesn't make sense, as my memory may be flawed, but I believe it's at least partially based on sane things. Wink
I got it! Well, mostly.

As it turns out, parserhook isn't actually called at all for tau, e, rand, and the like. But it is called in mode zero when it starts, with what it will be working on between basic_start and basic_end, giving you the chance to go through and replace occurances of tau with some other token. But since there is no token that parses as 2pi, you would need to give it a dummy token that you could intercept. But that would require a dummy token that takes an argument, and the only safe way I can envision doing that is by inserting a dummy argument and a dummy close paren, with all the shifting that entails. The cop out is to just replace tau with either ztmax or z[theta]max, both of which have default values of um, 2pi. Not quite foolproof, but it's what I've done so far, and its a score for tau. Anybody see a better way?
Glad to hear you figured it out. And yes, I now remember that the parser hook doesn't trigger for non-command tokens, which had totally escaped me until you mentioned it. I can't think of a particularly better solution than what you have come up with, although I'm going to poke BrandonW, our resident calculator superexpert, to see if he has anything to add.
I hate to say it, but replacing all the occurrences in the program when it starts (as you did) with an interceptable token is the only way.

I would recommend NOT trying to insert any new data, just replace it with a parserhookable token of the same size, that's asking for trouble in low-memory conditions and so on. It doesn't even have to be an unused or rare token, you can take control at that point and see if this is one of the occurrences you had to change (by keeping a list in RAM or something of everything you had to change) and either perform the default action or return 2*pi.

I would recommend executing the BASIC program yourself from within the parser hook with A=0, and wrapping that in an error handler. In the error handler, you can restore all the occurrences (using that list from RAM as above) and then throw the error back out with _JError.

That way no one ever has to know you had to do this godawful hack. Smile
How would you do that? Since everything a=1 takes arguments, does that would mean you are suggesting to replace it with something that I could catch under a=2 or a=3 right? In that case, any hints as to how to make something like "If" parse like a function and return 2pi?

edit:
Or maybe it would be better to replace it with a mode 1 token, which would be easy to make return 2pi, but restoring the aeguments that it finds in the program sounds near impossible. All I have (successfully) done is replace it with a variable, which don't trigger the hook at all.

Another idea, would it be possible to insert the extra tokens I mentioned through getkeyhook when the key is first pressed? Then you could use tokenhook to make it look like a tau, and the contained funtion couldeasily be made to return 2pi with the parserhook.

Why can't everyrhing that returns a number call the parserhook in mode 1?
kgmstwo wrote:
How would you do that? Since everything a=1 takes arguments, does that would mean you are suggesting to replace it with something that I could catch under a=2 or a=3 right? In that case, any hints as to how to make something like "If" parse like a function and return 2pi?

edit:
Or maybe it would be better to replace it with a mode 1 token, which would be easy to make return 2pi, but restoring the aeguments that it finds in the program sounds near impossible. All I have (successfully) done is replace it with a variable, which don't trigger the hook at all.

Another idea, would it be possible to insert the extra tokens I mentioned through getkeyhook when the key is first pressed? Then you could use tokenhook to make it look like a tau, and the contained funtion couldeasily be made to return 2pi with the parserhook.

Why can't everyrhing that returns a number call the parserhook in mode 1?


Because TI is stupid.

That is what I was suggesting, yes. What causes a token to just execute (and display "Done" if run from the homescreen) versus returning a value is driven entirely by the flag numOP1,(iy+ParsFlag2). You would calculate 2*pi in OP1, set that, and return whatever you need to return to prevent it from trying to parse it itself.

Unfortunately, TI severely broke the parser hook starting with OS 2.53MP onward (and have ignored our attempts to contact them regarding a bug fix), and their bug prevents that flag from behaving properly. So, this *might* not work on 2.53MP and up. I would recommend testing it before releasing anything.

Or this could all be totally wrong. It's been a long time since I've touched it.
It works! Now there is no way to prevent my tau's from being parsed as 2pi!

Setting the flag works just as you remember, making mode 2 tokens return OP1. Whatever else goes on in mode 2 doesn't doesn't cause any problems when you set numOP1,(iy+ParsFlag2) and return nz.

Thanks again.
  
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