Posts

Showing posts from April, 2011

Test-driven grammar-class understanding with ANTLR

Suppose you would like to understand some grammar classes such as LL(1) and LL(*). Then you might appreciate a test suite like the following, or you would actually try to discover such a test suite yourself. I used the following suite in a lab of my " Software Language Processing " class. It is very convenient means of illustrating things. Students can copy and paste these codes now and further investigate. It helps understanding formal notions and actual, operational parser behaviors. The first ANTLR input specifies a trivial grammar with a fixed lookahead of 1. grammar LL1; options { k = 1; } s : 'a' 'x' | 'b' 'x' ; Let's apply ANTLR: java -classpath ".:antlr-3.2.jar" org.antlr.Tool LL1.g ANTLR likes that grammar just fine. (There are no complains.) We are allowed to infer hence that the grammar is indeed LL(1). The next ANTLR input combines two alternatives that are clearly not LL(1). However, we still use a lookahead of 1. gra