End position is checked using the string length value . q0 is the starting state . q1 and q2 are intermediate states . q3 and q4 are final states .
def q1 ( s , i ) : NEW_LINE INDENT print ( " q1 - > " , end = " " ) ; NEW_LINE if ( i == len ( s ) ) : NEW_LINE INDENT print ( " NO " ) ; NEW_LINE return ; NEW_LINE DEDENT DEDENT