3

Lexical Analyzer

What you will learn in this chapter

  • The basic functions of a Scanner
  • The relationship between a Scanner and the rest of the phases of a compiler
  • How to implement ad hoc Scanners
  • How to implement Scanners based on FSM theory
  • Relationships between Regular Expressions, FSMs and Scanners
  • Scanner writing tools – Lex and Flex
  • Example Scanner for a C-like language
  • Some initial treatment of the Symbol Table

Key Words

lexical analysis, Scanner, lex, flex

In this chapter, we discuss the first phase of a compiler – the lexical analyzer or Scanner.

Parsing is a general term meaning analyzing a sentence to arrive at its syntactic structure. From theoretical viewpoint, lexical analysis is also parsing, only the atoms of the language ...

Get Compilers: Principles and Practice now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.