The scan function is called by the parser each time a new token is needed. The function does the necessary things such as moving the 'current' with the appropriate number of positions. It also filters useless stuff such as whitespaces , tabs and carriage returns. The process performed by this function is called lexical analysis