Go Languages basic grammar
The last chapter we already know the basic structures of the Go language in this chapter we will learn basic grammar Go language.
Go tags
Go program can consist of multiple tokens may be keywords, identifiers, constants, strings, symbols. As the following GO statement by the six tokens:
fmt.Println("Hello, World!")
6 tag is (one per line):
1. fmt 2. . 3. Println 4. ( 5. "Hello, World!" 6. )
Line separator
Go in the program, a statement on behalf of the end of a line. Each statement is not like the C family of languages other semicolon; at the end, because these jobs are done automatically by the compiler Go.
If you intend to write multiple statements on the same line, they must be used; artificial distinction, but in the actual development, we do not encourage this practice.
The following two statements:
fmt.Println("Hello, World!") fmt.Println("w3cschool本教程:w3cschool.cc")
Note
Comments are not compiled, each package must have the appropriate comments.
Single-line comments are the most common form of comments, you can use single-line comments begin with // anywhere. Multi-line comments, also called block comments, have been with / * at the beginning and end with * /. Such as:
// 单行注释 /* Author by w3cschool本教程 我是多行注释 */
Identifiers
Identifier used to name variables, types, and other program entities. Or an identifier is actually a more letters (A ~ Z and a ~ z) numbers (0 to 9), underscores _ sequences, but the first character must be a letter or underscore and can not be a number.
The following are valid identifiers:
mahesh kumar abc move_name a_123 myname50 _temp j a23b9 retVal
The following are invalid identifiers:
- 1ab (begin with a number)
- case (Go language keywords)
- a + b (operator is not allowed)
Keyword
Here are the code will be used Go to 25 keywords or reserved words:
break | default | func | interface | select |
case | defer | go | map | struct |
chan | else | goto | package | switch |
const | fallthrough | if | range | type |
continue | for | import | return | var |
In addition to these keywords described above, Go language as well as 36 predefined identifiers:
append | bool | byte | cap | close | complex | complex64 | complex128 | uint16 |
copy | false | float32 | float64 | imag | int | int8 | int16 | uint32 |
int32 | int64 | iota | len | make | new | nil | panic | uint64 |
println | real | recover | string | true | uint | uint8 | uintptr |
Program generally consists of keywords, constants, variables, operators, types and functions.
The program may use these delimiters: parentheses (), brackets [] and {} braces.
The program may use these punctuation marks: ,,,;,: and ....
Space Go Language
Go language variable declaration must be separated by spaces, such as:
var age int;
Statements make appropriate use of the space program is easy to read look.
No spaces:
fruit=apples+oranges;
Spaces between variables and operators, the program looks more beautiful, such as:
fruit = apples + oranges;