fixed a bug in parser

we need to check the index otherwise we get out of range on broken syntax