Top

Syntax Syntax

Encoding

By default, Z1h source file to utf-8 encoding Allows the use of any of the characters in the code, such as English, Chinese, Japanese, Uighur and other Z1h is compatible with most Golang, Python, JavaScript and The syntax of Java, developers with experience in the above programming languages ​​can try to encode directly

Token

- Code statements are composed of multiple tokens, which can be keywords, identifiers, constants, strings, symbols - Including delimiters: (), [], {} - These punctuation marks may be used in the code: . , ; : ? ! * ^ ' " etc. Following Z1h statement consists of 6 tokens print('Version' + VERSION) 6 tokens are (one per line): 1. print 2. ( 3. 'Version' 4. + 5. VERSION 6. )

Line Separator

Semicolon ; Explicit indicates the end of a line of statement. But at the same time, Z1h's compiler also supports (automatic semicolon insertion, ASI) in most scenarios. If you plan to write multiple statements on the same line, you must use ; to artificially distinguish The following two statements: print("Hello") print("World") or print("Hello"); print("World")

Identifier

The identifier is used to named variables, like the type of program entity identifier actually It is a continuous string of one or more characters (English, numbers, Chinese or other language characters, special symbols). The first character cannot be a number. It is case sensitive. The These are valid identifiers: zwr Zwr z_w_r $zwr ... These are invalid identifiers: 1ab (beginning with a number) if (cannot be the same as a keyword) a + b (no operator allowed)

Reserved Words

Reserved words are keywords. We can't use them as any identifier names. The following lists the 33 keywords or reserved words that will be used in the Z1h code: break case var const continue defer chan default else fallthrough for in func go goto if import global true false nil null undefined try catch finally throw with as package return switch synchronized In addition to these keywords introduced above, Z1h language also has predefined identifiers: len cap new del has append bool string bytearray int8 uint8 byte int16 uint16 rune int32 uint32 int64 uint64 float32 float64 nil panic

Comment

comment is beginning with // At the , the example is as follows: //Output 2 to the 3rd power 2 ** 3 It can also be used multiple lines of code in the following way /* author: Zwei.Ren */

Space

Proper use of spaces in space statements can make the program easier to read. No spaces: area=math.Pi*2*2 Add spaces between variables and operators, the program looks more beautiful, such as: area = math.Pi * 2 * 2

Language Features

Following shows the various language features of Z1h, For developers who have a foundation in other languages ​​** Quick reference, adaptation

go

Use the go keyword followed by a function call, you can put the execution process of this function in another coroutine (newbies can be roughly understood as (New process) go is a characteristic function of Go language, Z1h also borrows this syntax For specific implementation, please refer to Concurrent

defer

defer is used to declare a delay function, put This function is put on a stack. It is called before the end of the code block. It can also be called when it reaches the outermost method body. We often use it to release some resources, such as closing the io operation. Similar to other The finally in the language's try...catch...finally.... Of course, the difference is still obvious. defer is a feature of Go language, Z1h also borrows from this syntax a = { Say: tag => {print(`I am ${this.name}, tag = ${tag}`)} } defer a.Say("Defer 2") // bottom of the stack, output at last defer a.Say("Defer 1") a.name = "test1" a.Say("Eval 1") return a.name = "test2"

Synchronized

To lock the code block synchronized is a feature of the Java language, Z1h also borrowed from this syntax specific For implementation, please refer to Concurrency

with..as..

For tasks that need to be set in advance and do cleanup afterwards, you can use with..as..{...} The method automatically executes the Close method with..as..is a feature of the Python language. Z1h also borrows this syntax. For specific implementation, please refer to Function

Ternary operator

Supports Java/JavaScript, Python-style ternary operators // Java xxx ? a: b // Python a if xxx else b Specific implementation, please refer to The Operator

String

Similar to JavaScript, support 'xxx'、"xxx"、 `name=${n}` three string declaration methods