CIT 594 Recognizer Addendum
Spring 2008, David Matuszek

Required methods

You should have an "is-Method" for each nonterminal defined in the grammar. Specifically,

isAction
isAddOperator
isAllbugsCode
isArithmeticExpression
isAssignmentStatement
isBlock
isBugDefinition
isColorStatement
isCommand
isComparator
isDoStatement
isEol
isExitIfStatement
isExpression
isFactor
isFunctionCall
isFunctionDefinition
isInitializationBlock
isLineAction
isLoopStatement
isMoveAction
isMoveToAction
isMultiplyOperator
isParameterList
isProgram
isReturnStatement
isStatement
isSwitchStatement
isTerm
isTurnAction
isTurnToAction
isVarDeclaration
isVariable

Each of these methods should be spelled correctly (according to the Grammar), should be public boolean, and should take no arguments. Our JUnit tests will depend on each of these methods being present and being spelled correctly.

Each method should do one of three things:

JUnit testing

Tokens form the foundation of the grammar. Low-level grammar rules, such as <term>, are built on these; higher-level rules, such as <expression>, are built on lower-level rules; and so on, all the way up to <program>. If <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 isStatement() method checks for seven different statement types; you should check that isStatement() will 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.