o
odinpkg.dev
packages / library / EZLang

EZLang

50cb9fblibrary

The EZ programming language

Apache-2.0 · updated 1 year ago

EZLang Programming Language Specification

A programming language designed to be accessible for programmers of all levels.

1. Basic Syntax Rules

  • Statements end with semicolons (;)
  • Code blocks are enclosed in curly braces { }
  • Case-sensitive keywords
  • Comments start with //

2. Data Types

Type Description Example
Number Integer values Number x = 42;
Float Floating-point numbers Float x = 3.14;
String Text values String x = "hello";
Boolean True/false values Boolean x = true;
Null Null type Null

3. Variable Declaration and Assignment

Variable Declaration

// Implicit typing
`name = "John";`
`age = 21;`

Note: When defining a variable but not assigning a value, you MUST explicitly define its type.
Example" `String name;`

// Explicit typing
`String name = "John";`
`Number age = 21;`



// Constants
const x = 100; // implicitly typed constant with value
const string name; // explicit typed constnant without value
const Number x = 0; // explicit typed constant with value

Variable Reassignment

Note: Constants cannot be re-assigned

now x = 1;

4. Operators

Arithmetic Operators

Symbol Example
+ x + y
- x - y
* x * y
/ x / y
% x % y

Comparison Operators

Symbol Example
== x == y
!= x != y
> x > y
< x < y
>= x >= y
<= x <= y

Logical Operators

Keyword Symbol Example
and && x and y
or || x or y

5. Control Structures

Conditional Statements

If Statement

if (x > 10) {
    // code
}
else if (condition) {
    // code
}
otherwise {
    // code
}

Loops

// While loop
while (x > 0) {
    // code
}

// Do-while loop
until (x == 1) {
    // code
}

// For loop
for (Number i; i < 0; i++) {
    // code
}

// For-each loop
for every name in names  {
    // code
}

Switch Statements

check (x) {
    event 0:
        // code
        go-on;  //go-on to next event, is the same as fallthrough in C++
    event 1:
        // code
        stop;  //stop the execution of the switch
    event 2:
        // code
        stop;
    default:
        // code
        stop;
}

6. Functions

Function Declaration

// No parameters, no return
do function_name(){
    // code
}

// With parameters, no return
do function_name(Number x, String name) {
    // code
}

// With parameters and explicit return type
do function_name(Float y, Number x)  >>> Boolean {
    // code
    return true;
}


//No parameters, with explicit return type
do main() returns Number {
    // code
    return 0;
}

// No parameters, no return
// If a return type is not specified, it will be inferred as void
do main() {

}

Function Calls

// No parameters
function_name();

// With parameters
function_name(21, "John")

// With return value
result = function_name(21, "John");

// Multiple return values
result, error = function_name(21, "John");

//Multiple return values, but ignoring one
result, _ = function_name(21, "John");

7. Example Program

#import "ez:std"
#import "ez:io"

Number a = 5; //Global variable declaration and assignment
Number b = 10;

do add(Number x, Number y) returns Number {
    Number total = x + y;
    return total;
}

do main() returns Number {
    result = std.add(a, b); //accessing a function from the std module
    io.display(result);  // output: 20     //accessing a function from the io module
    return result;
}