使用GCMathParser进行iphone开发

发布于 2024-10-09 08:06:08 字数 314 浏览 0 评论 0原文

我正在尝试在我的 iPhone 应用程序中使用 GCMathParser。为了编译它,我将 #import 更改为 #import 并将 pi 替换为 M_PI 并成功编译了代码。

它基本上工作正常,但是当我输入错误的语法(例如 3.3.3 或 3.. )时,我会得到语法错误,正如我所期望的那样。但是下次我解析一个非常简单的公式(例如 5 )时,我仍然会遇到语法错误。我确保分配新实例以确保它开始新的,但我仍然明白。有人有同样的问题吗?

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 sure it starts new, but still i get it. Does anyone have the same issue?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

多像笑话 2024-10-16 08:06:08

GCMathParser 中似乎存在错误;不过,还有一个办法。有一个固定模式:当将格式错误的表达式输入解析器时,会引发异常。之后,即使提供了格式良好的表达式,也会再次引发异常。关键点是对格式良好的表达式求值两次。首先检查是否引发异常;如果是,只需重新计算相同的表达式。第二次评估格式良好的表达式时,不会引发异常。瞧!

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文