// Create factory for SAX parser
SAXParserFactory parserFactoryImpl = SAXParserFactory.newInstance();
parserFactoryImpl.setNamespaceAware(true);
// Get a SAX parser
XMLReader xmlparser = parserFactoryImpl.newSAXParser().getXMLReader();
// Create a lexicon model for a given lexicon file
LexiconFactory lexiconfactory = new LexiconFactory();
xmlparser.setContentHandler(lexiconfactory);
xmlparser.parse(lexiconFile.toString());
Lexicon lexicon = lexiconfactory.getLexicon();
// Build a automaton from the lexicon model
LexicalAutomaton lexicalautomaton =
(new LexicalAutomatonBuilder(lexicon, log)).getLexicalAutomaton();
// Create a processor for the lexicon
LexicalProcessor lexer = new LexicalProcessor();
lexer.setLog(log);
lexer.setLexicalAutomaton(lexicalautomaton);
// Get a SAX parser
xmlparser = parserFactoryImpl.newSAXParser().getXMLReader();
// Create a grammar model for a given grammar file
GrammarFactory grammarfactory = new GrammarFactory();
xmlparser.setContentHandler(grammarfactory);
xmlparser.parse(grammarFile.toString());
Grammar grammar = grammarfactory.getGrammar();
// Build a automaton from the grammar model
ParserAutomaton parserautomaton =