Zyxonia
Zyxonia(pronounced /zæiksœniə/) is an Esolang designed by PSTF.
Language Overview
Zyxonia is a quasi-assembly, high-level, and powerful programming language. It uses an easy-to-understand but cumbersome syntax, and is capable of writing extremely powerful programs, even embedded in web pages, and even directly manipulated devices.
Basic Syntax Overview
Module
In Zyxonia, every program must set programming environment to System, otherwise it can not be runned in any machine.
ENV <- System do Main // Anything you want to do end
Comment
// Signe line comment /*Comment block*/
Identifier
Any identifier that legal in Python also legal in Zyxonia.
Variable
Zyxonia uses math-like syntax to assign anything to variable.
LET var_name(var_type) <- var_value
You can also leave var_value blank to set a variable to NULL, or set var_value to DELETE to delete the variable name.
When you assign another value to variable, then you can omit colon and omit variable type.
Statement
ALL STATEMENT MUST WRITTEN IN UPPERCASE, EXCEPT THE START AND THE END OF SUBROUTINE. I USE UPPERCASE HERE, JUST WANT TO LET YOU HOW TO WRITE A STATEMENT IN ZYXONIA.
Input and Output
In Zyonia, the output is oriented to the standard output by default, and the input is oriented to the standard input by default.
You can use the following statements to specify the input and output files. Note that STDIN is used for standard input, while STDOUT is for standard output.
filename |> INPUT filename <| PRINT
Conditional Control Flow
Zyxonia uses following structure to represent a conditional control flow.
Normal conditional
IF(expression){code}
If-else statement
IF(expression){code1}ELSE{code2}
If-elif-else statement
ELSE can be omitted.
IF(expression1){code1}ELIF(expression2){code2}...ELSE{codeM}
Goto-statement
IF(expression){GOTO label}
Loop
Zyxonia uses following structure to represent a loop control flow.
Iterative loop
The iteration loop executes the same statement for each iteration object in the iteration container.
FOR(iter_obj IN iter_cont){code}
Conditional loop
The same code is executed as long as the condition is true (or not).
WHILE(expression){code} DO{code}WHILE(expression) WHILENOT(expression){code} DO{code}UNTIL(expression)
Break and continue
Break will directly break the loop, and continue will jump to next round of loop.
Goto-statement
:LABEL label_name IF(expression) { // Do anything GOTO label_name } :LABEL end
:LABEL label_name IF(!(expression)) { // Do anything GOTO label_name } :LABEL end
:LABEL label_name // Do anything IF(expression) { GOTO label_name } :LABEL end
:LABEL label_name // Do anything IF(!(expression)) { GOTO label_name } :LABEL end
Label
The labels are defined by this:
:LABEL label_name NOP // This is do nothing, you can replace it by your code :LABEL end
Subroutine and functions
Subroutine
A subroutine is just a procedure and doesn't return any value. As a result, the subroutine can be thought of as a function that returns nothing and has no arguments.
do subroutine_name NOP end
Function
do function_name function_type arg_list <- [*args, **kwargs] NOP RET return_value end
Here are some example:
do add INT arg_list <- [a(INT), b(INT)] NOP RET a + b end
do divide INT arg_list <- [a(INT), b(INT)] IF(b=0) { THROW(ZeroDivisionError) "You can't divide by zero!" } ELSE { LET c(INT) <- a / b } RET c end
Error handling
Zyxonia also can handle error.
Throw error
THROW(error_level) error_message
Handle error
TRY{error_statement}CATCH(error_level){handle_code}ELSE{success}FINALLY{final}
Advanced Syntax Overview
Preprocessing code
Preprocessing code is the statement that didn't included in any code-block.
All variable defined in preprocessing code or in Main subroutine are global.
Import library
Zyxonia supports a lot of library, it is too many to show here.
Use these code to import a library:
#INCLUDE<library_name>
Or, if you want to include only some methods:
#INCLUDE<method_name>FROM<library_name>
Here shows some useful libraries. Zyxonia/Libraries
Object-oriented
Definition of class
ENV <- System // Define a class and create an object CLASS Person: LET name(STRING) <- LET age(INT) <- __INIT__ arg_list <- [STRING name, INT age] LET this.name <- name LET this.age <- age end do greet STRING arg_list <- NOP RET f"Hello, my name is {this.name} and I am {this.age} years old." end LET person <- Person("Alice", 30) // "Spawn" a person PRINT person.greet() // Output: Hello, my name is Alice and I am 30 years old.
Inheritance and polymorphism
Let's say we've defined the person class.
CLASS Employee(Person): LET employeeID(STRING) <- __INIT__ arg_list <- [STRING name, INT age] SUPER(name, age) LET this.employeeID <- employeeID end OVERRIDE do greet STRING arg_list <- NOP RET SUPER.greet() + f"My employee ID is {this.employeeID}." end LET employee <- Employee("Bob", 40, "E12345") PRINT employee.greet() // Output: Hello, my name is Bob and I am 40 years old. My employee ID is E12345.
Compilation
See here: Zyxonia/Compile