Added validating input functions for both terminals and non-terminals. These functions are not properly tested. Found a bug in input parsing which will be fixed in the check in.