[antlr-interest] Testing a grammar

Bryan Ewbank ewbank at gmail.com
Thu Mar 16 06:31:05 PST 2006

Having the tests generated from the grammar seems like a bad thing,
from a project point of view.  Perhaps for the developer, for
unit-tests, but that's about it.

It can do code-coverage and make sure that syntactically legal
programs do not cause errors.  With some imagination, it could also
test behavior with syntactically illegal programs: try putting two
tokens where zero/one are allowed by "( ... )+" in the grammar, or
inject a random token 1% of the time in the walk :-).

It cannot do validation versus requirements.

It can't do much for semantic validation without much additional help.

Taking a different tack, you could generate (for TreeParsers) input
audits that verify tree shape with a simple traversal by stripping out
the actions.  At the very least, this would help developer to see

On 3/16/06, Martin Probst <mail at martin-probst.com> wrote:
> > I think Terence wrote something like that once, a tool that generates
> > random and meaningless, but syntactically correct, expressions from your
> > grammar. Maybe in the filesharing section?
> >
> That strikes me as something that might test the program that uses the
> parser but it would hardly test the parser. After all, the test input is
> guaranteed to obey the rules of the parser.

More information about the antlr-interest mailing list