Objective-C ParseKit 返回值
在 flex/lex/bison/yacc (所有这些我刚刚开始阅读)中,您可以将“$$”设置为等于某个值($1,$2,$3),这就是返回的值。至少我认为它就是这样运作的。
在 ParseKit 中,你会得到一个堆栈,所以我想象 ($1,$2,$3) 将是堆栈上的前三个值。但我认为你想要做的是将这些值从堆栈中弹出并将返回值放入堆栈中。我看到堆栈带有一个push方法。在推送某些内容之前是否必须先弹出传入的值?
谢谢
In flex/lex/bison/yacc (all of which I just started reading about), you can set "$$" to be equal to some value ($1,$2,$3) and that's the value that gets returned. At least I think that's how it works.
In ParseKit, you are given a stack so I imagine that the ($1,$2,$3) would be the first three values on the stack for example. But then I think what you would want to do is pop those values off the stack and put your return value on the stack. I see that the stack comes with a push method. Do you have to pop the incoming values first before pushing something on?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ParseKit 的开发者在这里。我想说:这要看情况。一些想法:
是的,通过在发送到解析器委托回调的程序集上调用
-[PKAssembly Push:]
将对象/值存储在程序集的堆栈上通常是有用/可取的。稍后的回调将在程序集的堆栈上找到这些值,并可能希望在找到它们时采取操作。另一个选项:如果您的回调方法正在构建某些结果对象,您通常希望将其存储为传递到回调方法的程序集的
-[PKAssembly target]
属性。因此,您有两个位置可以存储值:程序集的目标或程序集的堆栈。目标是“正确”的地方,但通常堆栈也很方便。两者都可以,但我想说:将临时值存储在堆栈上,但存储您正在构建的最终对象作为目标。但同样,您可以执行任一操作。是的,您的回调通常应该首先从堆栈中弹出值,但这不是必需的。可以这样想:您的委托回调方法接收一个
PKAssembly
对象作为参数。通常,您的回调方法将检查程序集的堆栈并根据在那里找到的内容采取行动。通常,在回调中,如果您要对它们采取操作,则需要弹出在那里找到的值。基本上:您的回调应该弹出它感兴趣/采取操作的值,因为从某种意义上来说,您的回调是这些项目/信息的预期接收者。Developer of ParseKit here. I would say: it depends. A few thoughts:
Yes, it is often useful/desirable to store objects/values on the assembly's stack by calling
-[PKAssembly push:]
on the assembly sent to your parser delegate callbacks. Later callbacks will find these values on the assembly's stack and may want to take action when they are found.Another option: if your callback methods are building some result object, you usually want to store it as the
-[PKAssembly target]
property of the assembly passed into your callback method. So you have two places where you can store values: the assembly's target or the assembly's stack. The target is the 'correct' place for this, but often the stack is also convenient. Either is fine, but i would say: store temp values on the stack, but store the ultimate object you are building as the target. But again, you can do either.Yes, your callbacks should often want to pop values off the stack first, but that is not required. Think of if this way: Your delegate callback method receives a
PKAssembly
object as a parameter. And usually your callback method will inspect the assembly's stack and take action depending on what it finds there. Usually, in your callback, you'll want to pop the values you find there, if you are taking action on them. Basically: your callback should pop the values it is interested in/taking action on, because in some sense your callback was the intended recipient of those items/information.