开发者

Using GCMathParser for iphone development

I am trying to use GCMathParser in my iPhone application. To compile it, I changed #import <Cocoa/Cocoa.h> to #import <UIKit/UIKit.h> and replaced pi with M_PI and successfully compiled the codes.

It works basically fine, but when I input wrong syntax like 3.3.3 or 3.. , I get syntax error as I am supposed to. But the next time I parse a very simple formula such as 5 , I still get syntax error for that. I made sure to allocate new instance to make开发者_StackOverflow社区 sure it starts new, but still i get it. Does anyone have the same issue?


There seems to be a bug in the GCMathParser; however there is a way around. There is a fixed pattern : when a malformed expression is fed into the parser an exception is raised. Right after that even if a well formed expression is fed, the exception is raised again. The key point is to evaluate the well formed expression twice. First check if an exception was raised; if YES simply reevaluate the same expression. Upon evaluating the well formed expression the second time, exception is not raised.Voila!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜