Fixed issues with recognising terminals while reading the grammar as
well as the standard input.