What is lexical analyzer in compiler design?

Asked By:
1 answer(s)
[]

The lexical analyzer is the first part of a compiler's job. It looks at your code, the text you wrote. Its main job is to chop the code into small, sensible bits. We call these 'tokens'.

A token is something like a keyword (e.g., if or while), a variable name, or a symbol like +. It also cleans the code up. It gets rid of comments and empty spaces because the next part doesn't need them.

After it's done, it passes this neat stream of tokens to the next stage, which is the parser.