November 2016
Intermediate to advanced
480 pages
14h 42m
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 Cocoavar str = "Hello, playground"enum Token { case number(Int) case plus }
Next, start building your lexer. To lex an input string, you will ...
Read now
Unlock full access