Coded in basics of Grammar, Rule, Variable, and made a new abstract class RuleItem which both Rule and Variable extend.