The ANTLR 4 Tool only performs static lookahead evaluation for k=1. If a grammar is LL(1), then the resulting generated parser will not contain any calls to adaptivePredict. The Tool does not contain any code to check lookahead for any k>1.
Also note:
· ANTLR 4 does not require or include support for backtracking. The portion of the DFA necessary for the actual input is computed on-demand by adaptivePredict (at runtime).
· The static lookahead evaluation is completely disabled if the -Xforce-atn flag is passed to the Tool (forces the use of adaptivePredict for every decision).
--
Sam Harwell
Owner, Lead Developer
--
ANTLR does not warn you statically about any LL(k) conditions. As Sam pointed out, it does however do static LL(1) analysis as an optimization.
I'm not sure what you mean by "main use of ANTLR is grammar editing and verification". Does that mean you don't use the generated parsers?
One of the driving goals of ANTLR 4 is removing the need for this use case. With ANTLR 4, you can use grammars that written very much like a language specification, allowing compiler developers to spend time verifying that a compiler matches the language instead of verifying that the compiler matches a set of lookahead properties that have no bearing on correctness (and actually pose additional challenges for correctness by forcing grammars to not follow the design of the language specification).
--
One of the driving goals of ANTLR 4 is removing the need for this use case. With ANTLR 4, you can use grammars that written very much like a language specification, allowing compiler developers to spend time verifying that a compiler matches the language instead of verifying that the compiler matches a set of lookahead properties that have no bearing on correctness (and actually pose additional challenges for correctness by forcing grammars to not follow the design of the language specification).
I wasn’t trying to say LL(k) analysis isn’t ever useful. I was merely pointing out that ANTLR 4 is designed to solve a very different set of problems than you’re working with, so even though there’s some overlap in the analysis abilities it may never be the tool you’re after for working with hand-written parsers. ANTLR 4 will probably be an excellent candidate for writing compilers, just not hand-written ones or ones where it’s more important for the compiler’s grammar to be LL(k) than to resemble the form given in the language specification.
--
Sam Harwell
Owner, Lead Developer
From: antlr-di...@googlegroups.com [mailto:antlr-di...@googlegroups.com]
On Behalf Of trijezdci
Sent: Monday, December 10, 2012 5:04 PM
To: antlr-di...@googlegroups.com
Subject: Re: [antlr-discussion] Can ANTLR4 still verify that a grammar meets LL(1) constraints?
On Monday, December 10, 2012 3:13:40 PM UTC+1, Sam Harwell wrote:
--
ANTLR 4 will probably be an excellent candidate for writing compilers, just not hand-written ones or ones where it’s more important for the compiler’s grammar to be LL(k) than to resemble the form given in the language specification.
http://smlweb.cpsc.ucalgary.ca/
can check for (among many things) LL(1)-ness, I think.