When ParseKit tries to recognize my Grammar, it enters an infinite loop. What's wrong?

旧城冷巷雨未停 提交于 2019-12-24 13:08:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!