Go Tokens
Go Language - Basics Tokens
We have seen the basic structure of a program and it will be easier to understand some other basic building blocks of the Go Language.
A program consists of different tokens. A token can be either an identifier, a keyword, a constant, a string literal, or a symbol. The following Go statement consists of six tokens:
CODE/PROGRAM/EXAMPLE
fmt.Println(“HelloWorld!”)
The six tokens are:
The line separator key is a statement terminator. In Go individual statements doesn’t need a special separator like “;” in Java. Here Go compiler internally places “;” as the statement terminator to indicate the one logic entity ends.
Look at the following statements:
CODE/PROGRAM/EXAMPLE
fmt.Println(“Hello World!”)
fmt.Println(“I am in Go Programming World!”)
Comments are the helping text in Go program and the comment statements will be ignored by the Go compiler. As we have seen already the comment lines can be represented in two ways /*...*/ or //. Here comment within comments is not allowed.
Example :
Syntax
/* This is my first program in Go*/
// This is my first program in Go
A name used to identify a variable, function, or any other user defined item is known as Go identifiers. An identifier can start with a letter A to Z or a to z or an underscore. And can be followed by zero or more letters, underscores, and digits 0 to 9.
Punctuation character such as @, $ and % will not allowed within identifiers. Go is a case-sensitive programming language. The following are some example of acceptable identifier:
CODE/PROGRAM/EXAMPLE
kanna abc move_name z_123 myname1 _temp i a23b9 recVa
The following shows the reserved keywords in Go. These words may not be used as variable or constant or any other identifier name.
Whitespaces means the term used to describe tabs, blanks, newline, characters and comments in Go. A line consisting of whitespaces along with a comment is also referred to as a blank line which Go compiler completely ignores it.
Whitespaces separates one part of a statement from another which helps the compiler to identify where one element in a statement, such as int, ends and the beginning of the next line.
Example :
Here the whitespace between int and shoesize is helping the compiler distinguish them.Example
CODE/PROGRAM/EXAMPLE
vegetable = potato + onion //get the total vegetable
Here there is no need for the whitespaces between vegetable and =, even though you can add if you wish for readability.