Can a structure definition call itself?

+1 vote
asked Feb 7, 2017 in Grammars by alanh (130 points)
I have a file with nested repeating structures. I need to use a count field to repeat a structure which may contain a nested structure of the same type. Does Synalysis handle this recursion, given that the repeat count value will have the same name with different values in the two nested instances?

1 Answer

0 votes
answered Feb 7, 2017 by andreas (2,440 points)
Nested structures are possible if the referenced structure is a top-level structure and an offset or structure reference element references it.

There's a limit to the recursion to avoid stack overflows.
commented Feb 7, 2017 by alanh (130 points)
Thanks. I asked because I'm trying to work out why my repeat count is failing.

I have a top level structure (A) reading an integer field used as a repeat value to count multiple switch/case top level structures that inherit from another top level structure (B).

One of {B}'s child structures (C) references structure (A), so it nests another counted switch/case sequence The nesting sequence may include a further reference to structure (C), but I have not seen a nesting depth greater than three.

It all works OK for the first part of the  file, but at one point, it fails to stop at the count limit, and reads the next structure, which happens to be a reference to structure (C). The count limit error then repeats, resulting in repeated recursion.

So it seems the repeat count is not being honoured when the failure starts.

Structure A reads the "count" field, and then it has a "Structures" list containing references to all the child structures. 'Structures"  has:

Element order: Variable
Repeat: count
     min: 0
     max: count-1

My investigations so far include trying variations on the above Repeat settings with no luck. I've looked at the debug information and established the following:

In earlier parts of the file where the repeat count appears to work, the 'count' value is 5, and the parser's index column for 'Structures' counts from 0 to 4 correctly, and the Debug Log shows: "Stop mapping 'Structures' - maximum repeat count '4' reached.

When it first fails, the 'count' value is 22, and the parser's Index column for' Structures' counts from 0 to 21 and then it continues to 22 instead of stopping. There is no indication in the Debug Log that the maximum repeat count has been reached.

Any ideas as to what I might be doing wrong?