Move some functions to `common.h`
Implement grammar extraction