Role of a Lexical Analyzer
The lexical Analyzer being the first phase in compiler designing, plays an important role.
- It reads the source program, scans it, groups them into lexemes, and gives a sequence of tokens.
- It eliminates the comments and white spaces present in the source code.
- It helps in removing errors.
- It reads the source program character by character and returns tokens of the source program.
- It feeds the information about identifiers into the symbol table.
- It expands macros in the source code if any is found.
Why do we need a Lexical Analyzer?
- Simplicity of the design of the compiler.
- Efficiency of the compiler is improved.
- Portability of the compiler is improved.
Reference Link