December 2015
Intermediate to advanced
400 pages
13h 3m
English
The first phase of your expression-evaluating compiler is lexing. Lexing is the process of turning some input into a sequence of tokens. A token is something with meaning, like a number or a plus sign (the two tokens your compiler will recognize). Lexing is sometimes referred to as “tokenizing” because you are turning some meaningless-to-the-compiler input (like a string) into a sequence of meaningful tokens.
Create a new playground named ErrorHandling. Define an enumeration that has cases for the two kinds of token.
Listing 20.1 Declaring the Token type
import Cocoa
enum Token {
case Number(Int)
case Plus
}
Next, start building your lexer. To lex an input string, you will need to access the individual ...
Read now
Unlock full access