Next | Tricks of the Wizards | 192 |
A regex is already a program for reading data character-by-character and running a state machine
Let's write a lexer for a calculator. It has the following tokens:
+, -, *, /, ^, **, (, ), =
:=
Variable names: Value2, for example
Numbers with optional decimal points and scientific notation
Whitespace will be ignored except where it separates tokens
Next | Copyright © 2003 M. J. Dominus |