On recognizing regular and context free languages