You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I maintain an ANTLR4 grammar for a language where one rule requires a lot of tokens for disambiguation. I have no control over the language specification so I have to deal with the "broken" syntax. I'd like to add a switch to have two modes, one where the broken syntax would be accepted, the other where it would be rejected. I did that with a semantic predicate, as explained in the ANTLR4 book:
classStatement:
{ acceptBrokenSyntax }? methodStatement1
| { !acceptBrokenSyntax }? methodStatement2 // Trimmed down version of methodStatement1
| ... // other rules
;
The semantic predicate works perfectly in both cases, but when analyzing the content of Parser#getParseInfo()#getDecisionInfo(), I was surprised to see the SLL_MaxLook value was identical in both cases, as if the parser was trying both rules and then discarding one based on the predicate value. I've done a test with only methodStatement2 and no semantic predicate, resulting in a much lower SLL_MaxLook value and improved performance.
Is this the expected behavior ? Or is there another way of handling such a case, without the lookahead performance penalty ?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I maintain an ANTLR4 grammar for a language where one rule requires a lot of tokens for disambiguation. I have no control over the language specification so I have to deal with the "broken" syntax. I'd like to add a switch to have two modes, one where the broken syntax would be accepted, the other where it would be rejected. I did that with a semantic predicate, as explained in the ANTLR4 book:
The semantic predicate works perfectly in both cases, but when analyzing the content of
Parser#getParseInfo()#getDecisionInfo()
, I was surprised to see the SLL_MaxLook value was identical in both cases, as if the parser was trying both rules and then discarding one based on the predicate value. I've done a test with only methodStatement2 and no semantic predicate, resulting in a much lower SLL_MaxLook value and improved performance.Is this the expected behavior ? Or is there another way of handling such a case, without the lookahead performance penalty ?
Context:
I can provide an example if required.
Beta Was this translation helpful? Give feedback.
All reactions