Lexical elements
Source code is UTF-8 encoded. The syntax is specified using Extended Backus-Naur Form.
Comments and character substitution
There are the following types of comments and automatically substitution characters.
// Single-line comment is here
This single-line comment starts with the character sequence //
and stops at the end of the line.
/* General comment is here */
General comments can appear anywhere. Such comment begins with a forward slash/asterisk combination / and is terminated by “end comment” delimiter /.
# header
At the beginning of the script, you can specify the parameters for use in other programs. Such comments should must be listed one after the other in each line from the beginning of the script. If you do not want to specify '#' at the beginning of each line, then insert ### before and after the text.
; The new line character is the separating character between expressions and statements. A semicolon is replaced with a new line character. So, you can use semicolons if you want to put several statements on one line.
: A colon is replaced with an opening curly brace and a closing curly brace is added at the end of the current line.
Identifiers
Identifiers are names that are used to refer to variables, types, functions, constants etc. An identifier is a sequence of letters and digits. The first character of the identifier must be a letter.
There are some predeclared identifiers and keywords. The following words are reserved and may not be used as identifiers.
Keywords
catch const elif else false for func go if in local recover retry return run struct true try while
Literals
An integer literal is a sequence of digits representing an integer constant.
A char literal represents an integer value identifying a Unicode code point. You can specify one character or a sequence of characters beginning with a backslash enclosed in single quotes. Multi-character sequences can be like these:
There are two types of string literals. 1. A string in backquotes can contain any characters. If you want to specify a backquote, then you need to double it. 2. A double-quoted string can also contain any characters (including a line break), but it has a backslash control character. You can specify the following characters after a backslash:
You can insert expressions into any type of string. In this case, the result type of expression can be any, if there is a corresponding function that can convert this value to a string. Expressions must be enclosed in curly brackets with the preceding % sign (for backquotes) or a backslash (for double quotes).
Last updated