oh, good luck. thats pretty hard and ambitious. you should learn some stuff about grammer rules first. that is, study the mathematics behind it, learn various ways to model grammer, i.e. state machines. i had read of a new program that does something similar to what you wish to do:
the program is not open source but you can use the same strategy.
here is their site: