Scanning Source Code
The first step in any programming language is reading the individual characters of the input source code and figuring out which characters are grouped together. In a natural language, this would include looking at the adjacent sequences of letters to identify the words. In a programming language, clusters of characters form variable names, reserved words, or sometimes operators or punctuation marks that are several characters long. This chapter will teach you how to read source code and identify the words and punctuation from the raw characters using pattern matching.
In this chapter, we’re going to cover the following main topics:
- Lexemes, lexical categories, and tokens
- Regular expressions
- Using UFlex and JFlex
- Writing a scanner for Jzero
- Regular expressions are not always enough
First, let’s look at the several kinds of words that appear in program source code. A natural language reader must distinguish...