[antlr-interest] Composite grammars and "no start rule" warning

Gavin Lambert antlr at mirality.co.nz
Mon Jul 13 13:51:48 PDT 2009


At 05:33 14/07/2009, Peterson, Joe wrote:
>I've had to make a change to my grammar recently that requires me 
>to use a rule in a file that I use elsewhere. The rule is in a 
>separate file and I want to keep that to make it easier to 
>maintain. Because I have two locations that I need to use it, I 
>wind up with the warning: warning(138): another_file.g:0:0: 
>grammar another_file: no start rule (no rule can obviously be 
>followed by EOF).
[...]
>import a_file, another_file;
>unit  : list? group;

If you're only using a_file and another_file from this grammar, 
then changing unit to:

   unit : list? group EOF;

ought to do the trick.

If you are using another_file from other contexts (or if the above 
doesn't work), then you could try defining a throwaway rule in 
another_file.g:

another_start : list EOF;

(Don't actually call it, unless you're actually trying to use 
another_file.g as your top-level grammar somewhere else.) 



More information about the antlr-interest mailing list