At long last, we have completed the section of the spec on expressions… and now we move on to:
Statements
Statements control execution.
Statement = Declaration | LabeledStmt | SimpleStmt | GoStmt | ReturnStmt | BreakStmt | ContinueStmt | GotoStmt | FallthroughStmt | Block | IfStmt | SwitchStmt | SelectStmt | ForStmt | DeferStmt . SimpleStmt = EmptyStmt | ExpressionStmt | SendStmt | IncDecStmt | Assignment | ShortVarDecl .
In my experience, the terms “expression” and “statement” and “declaration” are often confused and conflated.
As we can see from the EBNF definition above, there’s maybe some basis for this confusion. A statement may be a delcaration, or an expression!
So in general, “statement” is a general term for these other concepts, and “expression” and “declaration” are special cases of “statements”. In Go, certain types of declarations (in particular, function and method declarations) are not considered “statements”. But type, constant, and variable declarations are. But this really isn’t terribly important.
The main take-away here is that we don’t have a concise definition of “statement” to go on. But that shouldn’t be a problem.
And tomorrow we’ll start diving into the particular types of statements that we have in Go.
Quotes from The Go Programming Language Specification Language version go1.22 (Feb 6, 2024)