Spring 2008, David Matuszek
You should have an "is-Method" for each nonterminal defined in the grammar. Specifically,
Each of these methods should be spelled correctly (according to the Grammar),
public boolean, and should take no arguments.
Our JUnit tests will depend on each of these methods being present and being
Each method should do one of three things:
SyntaxException. It can do this by calling the
error(String message)method with a suitable error message. (This is because the
pushBack()method cannot recycle more than a single token.)
Tokens form the foundation of the grammar. Low-level grammar rules, such as
<term>, are built on these; higher-level rules, such as
are built on lower-level rules; and so on, all the way up to
<program> is to be correct, everything, all
the way down, has to be correct. Hence, JUnit testing is essential.
You should test that each "is-Method" recognizes both simple and
complex versions of the nonterminal it is intended to describe. In addition,
you should test that each "is-Method" throws an exception when it should. However, you
only need to check for SyntaxExceptions that should be thrown by the method
you are testing, not by lower-level methods. For example, the
checks for seven different statement types; you should check that
recognize each of those statement types, but don't check for
all the possible exceptions thrown by all seven statement types! Trust your
JUnit tests of the seven statement types to do that for you.