1

I'm using Parsekit for XCode but this problem may well apply to most parser generators. I parse a script with a gammer and it works fine. However I'm running into problems with the next step. Consider the grmmer:

@start = line+; line = tree;

tree = 'tree' fruits branches;

fruits = 'with' 'fruits' Number; branches = 'with' 'branches' Number;

And the script to pass:

tree with fruits 8 with branches 12

If I then implemenet methods to match, fruits and branches will be matched once, this is expected.

However tree will be matched twice, why? This stops me from building the parse tree I want.

Thanks for any help!

Todd Ditchendorf
  • 11,217
  • 14
  • 69
  • 123
FBryant87
  • 4,273
  • 2
  • 44
  • 72

1 Answers1

1

Developer of ParseKit here. I think you might actually be asking the same question as this:

parsekit given unexpected calls to selectors

If you read through the comments I made on that question, I think you will find the answer. Let me know if not.

Community
  • 1
  • 1
Todd Ditchendorf
  • 11,217
  • 14
  • 69
  • 123
  • Hi Todd, Thanks but I couldn't quite get my head around the solution. Store what I'm working on in the assembly's target? The way I saw it, I would match 'tree', add that to the pass tree, match 'fruits' and 'branches' and add them as children etc... Is there possibly some example somewhere which shows how to use the target solution? Good work on the Parsekit btw :) – FBryant87 Aug 03 '11 at 19:05
  • I think the answer is to store the root object of the abstract tree/graph you are building ("pass tree" i think?) as the current PKAssembly's target, rather than as an ivar. The current PKAssembly is either the one you create to start with or the one passed into a -didMatchXXX: method. The "stuff" you're building by parsing should always be the current assembly's target. The "stuff" you're building should never be an ivar or global var. – Todd Ditchendorf Aug 04 '11 at 02:37