Learning path

Full curriculum

Full curriculum

Arrows go from each prerequisite to the units that depend on it. Hover or focus a unit to highlight its path.

Unit content

Parsing numeric text

Text such as "-314" is a sequence of encoded characters, not yet the integer $-314$. Numeric parsing validates the text and constructs the corresponding numerical value.

Accumulating decimal digits

For decimal digits read from left to right, an integer parser can repeatedly update

$$value \leftarrow 10,value + digit.$$

For 314:

0 → 3 → 31 → 314

The character 7 must first be mapped to the numerical digit $7$; its character code is not itself the abstract number being parsed.

Syntax and errors

A parser must define which forms it accepts: optional sign, whitespace, decimal point, exponent or base prefix. Invalid characters and incomplete forms must produce an error rather than silently inventing a value.

Range

Even syntactically valid text can describe a number outside the destination type's range. Robust parsers detect overflow while accumulating the value.

Parsing is therefore both an algorithm and a contract between textual syntax and a numerical representation.