Join our book community on Discord
The first step in any programming language is reading the individual characters of 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 use pattern matching to read in source code and identify the words and punctuation from the raw characters.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 the nouns...