问题
Hi I am creating grammar for some formula which is using recursion. The formula is much more complicated but for now I test only some part of it. After calling parse method it crashes on allMatchesFor method. The stack trace is full of allMatchesFor invocations so it looks like it is in infinite loop Where is the problem. Is it in my grammar construction logic or else ? How can I accomplish similar thing to avoid this crash
My grammar is like:
@start = formula;
formula = valueTypeResult;
valueTypeResult = (value | concept | arithmeticStatement);
arithmeticStatement = valueTypeResult (arithmeticOperator valueTypeResult)+;
value = 'V';
concept = 'C';
arithmeticOperator = 'A';
Can you please tell me how to create grammars which use recursion ?
Thanks
回答1:
Developer of ParseKit here.
ParseKit has no problem with recursion, but your grammar is incorrect. This is more of a BNF grammar problem than a ParseKit problem.
Here's the correct version of what I believe you are attempting with your grammar above:
@start = formula;
formula = arithmeticStatement;
arithmeticStatement = valueTypeResult (arithmeticOperator valueTypeResult)+;
valueTypeResult = (value | concept);
value = 'V';
concept = 'C';
arithmeticOperator = 'A';
来源:https://stackoverflow.com/questions/13866165/when-parsekit-tries-to-recognize-my-grammar-it-enters-an-infinite-loop-whats