implemented override WeightedGrammar class
Adapted to work with new grammar class