I have a grammar of a programming language that I would like to explode in several subclasses of PPCompositeParser (for example, one class will process instructions, another class will process expressions, another class with the structure of the handle structure). I want to do this to avoid getting a large class with dozens of instance variables.
My problem is that these subgrams have a cyclical dependence: the structural grammar refers to the statement statement rule of the operator grammar, which refers to the expression rule of the expression grammar of the expression, which refers to the "subroutine name" structural grammar (closing the dependent word). I tried a simple approach to have, for example, the #subroutineName method in the grammar of an expression that looks like this:
MyExpressionGrammar>>subroutineName ^ N2TJStructureParser newStartingAt:
but this fails during initialization due to infinite recursion (obviously).
To solve this problem, I created PPDeferedParser:
PPParser subclass:
which makes the previous #subroutineName look like this:
MyExpressionGrammar>>subroutineName ^ PPDederedParser creationBlock: [N2TJStructureParser newStartingAt:
This seems to work, but I wonder if there is another solution.
source share