Theoretical investigation on the electronic states localized at grain boundaries in semiconductors