APPENDIX B ■ A SIMPLE PARSER
function trigger( Scanner $scanner ) {
if ( $scanner->tokenType() != Scanner::WORD ) {
return false;
}
if ( is_null( $this->word ) ) {
return true;
}
return ( $this->word == $scanner->token() );
}
protected function doScan( Scanner $scanner ) {
$ret = ( $this->trigger( $scanner ) );
return $ret;
}
}
By combining terminal and nonterminal Parser objects, I can build a reasonably sophisticated
parser. You can see all the Parser classes I use for this example in Figure B–1.
Figure B–1. The Parser classes