HANDWRITING RECOGNITION WITH HIDDEN MARKOV MODELS AND GRAMMATICAL CONSTRAINTS