finished all algorithms, however, order of the grammar is not preserved, fixing in the next commit