Simple Grammar Processor in Java