Source: https://www3.cs.stonybrook.edu/~cse304/Fall09/Lectures/lexer-handout.pdf