[antlr-interest] Testing a grammar

Alexey Demakov demakov at ispras.ru
Thu Mar 23 07:19:34 PST 2006


Hi all,

Recent discussion on this topic force me to release our internal tool 
that generates tests for parsers. The source for test generation is BNF grammar.
But this grammar may differ from parser's grammar - it may be any context free grammar,
not necessarily LR(k). It is possible, that you have such grammar before parser development
and you try to resolve all conflicts that ANTLR reports. So, tests generated from source
grammar can help you find out inconsistency between parser and source grammar.

I absolutely have no time to write docs now, use examples in source distribution.
Unfortunately all docs we have are in Russian :(

Here is grammar for used BNF notation:
-----
grammar ::= ( rule )+ ;

rule ::= ( <JAVADOC> )? id "::=" expression ";" ;

expression ::= term ( "|" term )* ;

term ::= ( factor )+ ;

factor ::=   id
           | <LEXEME_TEXT>
           | <LEXEME_NAME>
           | "(" expression ")" ( "*" | "+" | "?" | "#" )?
       ;

id ::= <ID> ;
-----

'#' is special modifiers useful for such things as java modifiers
( 'public' | 'protected' | 'private' )# 
means the same as 
( 'public' | 'protected' | 'private' )*
but each alternative can't be used more than once.

Lexeme values are in separate file:

-----
<JAVADOC>     "/** javadoc */"
<LEXEME_TEXT> "\"lexeme\""
<LEXEME_NAME> "<LEXEME>"
<ID>          "id1" "id2"
-----



More information about the antlr-interest mailing list