Objective-C Return Value ParseKit

In flex / lex / bison / yacc (all that I just started to read about) you can set "$$" to some value ($ 1, $ 2, $ 3) and the return value. At least I think it works.

ParseKit provides you with a stack, so I assume that ($ 1, $ 2, $ 3) will be the first three values ​​on the stack, for example. But then I think what you want to do is pull these values ​​from the stack and put the return value on the stack. I see that the stack comes with a push method. Do you need to put the input values ​​first before clicking anything?

thanks

+1
source share
1 answer

ParseKit developer is here. I would say: it depends. A few thoughts:

  • Yes, it is often useful / advisable to store objects / values ​​on the assembly stack by calling -[PKAssembly push:] in the assembly sent to your parser delegate callbacks. Later callbacks will find these values ​​on the assembly stack and may want to take action when they are found.

  • Another option: if your callback methods create some kind of result object, you usually want to save it as a property -[PKAssembly target] assembly passed to your callback method. Thus, you have two places where you can store values: the assembly target or the assembly stack. The goal is the "right" place for this, but often the stack is also convenient. Curious, but I would say: keep temporary values ​​on the stack, but keep the final object that you are building as a target. But again, you can do it.

  • Yes, your callbacks often need to push values ​​from the stack first, but this is not required. Think about it this way: your delegate callback method takes a PKAssembly object as a parameter. And usually your callback method checks the assembly stack and takes action depending on what it finds there. Usually, in your callback, you want to output the values ​​that you find there if you take action on them. Basically: your callback should call the values ​​that it is interested / take action, because in a sense, your callback was the intended recipient of these elements / information.

+2
source

Source: https://habr.com/ru/post/912613/


All Articles