Anomalous nonabelian gauge theories based on the Batalin-Fradkin formalism