Programming 101 – 5. syntax
Disclaimer: the Programming 101 series was originally written to be published as a short book. However, since I never got round to finishing it, I’m publishing the chapters here as individual blog posts…
Now that we understand how a programming language goes from being
language to performing actions, it is high time we take a closer look at what these languages look like. As we saw earlier, we use the linguistic word syntax for that. Because this is easier with a particular example in mind, we will take a look at the specification of the Go programming language, which you can find at https://go.dev/ref/spec.
Tokens
You may recall that the lexing step of a compiler involves splitting up
the source code into tokens. These form the vocabulary of a programming language. In Go there are four kinds of tokens.
- Identifiers name program entities such as variables and types.
- Keywords, like if or break are reserved and may not be used as identifiers.
- Operators, such as
+
or&&
(Go for AND) - Punctuation, like
{
or}
- Literals, like integers (
1
) or strings ("hello"
)
The following keywords are reserved and may not be used as identifiers.