So far a program is just a bare expression. Today you parse your first real statement - a let binding - which means teaching the parser to dispatch on the leading token and choose between statement kinds.
Parse a let binding into a statement holding the name and the value expression.
Until now every “statement” was really just an expression in disguise. A let
statement is different: it has fixed structure - the keyword let, a name, an
=, a value expression, and a semicolon. To handle it, parseStatement grows a
dispatch: look at the leading token, and if it is let, parse a let
statement; otherwise fall back to an expression statement.
That dispatch is the pattern every statement kind will follow, so set it up
cleanly now. Parse the name into an identifier, require the =, then reuse
parseExpression for the value - the binding’s value can be any expression you
have already built, from 5 to 1 + 2 * 3. Return statements come next, and
they slot into the very same dispatch.
type LetStatement struct { Name *Identifier; Value Expression }func (ls *LetStatement) String() string {return "let " + ls.Name.String() + " = " + ls.Value.String() + ";"}// parseStatement dispatches on the first token:// LET -> parseLet, else -> expression statement