Skip to content
Rusketh edited this page Dec 1, 2016 · 47 revisions

Expression Three

Syntax

Work in progress

The compiler for Expression 3 is a huge work in progress and there for the syntax of this language is likly to change over the course of its development.

Similarities

Expression 3 uses a language based on expression advanced 2 but is closer to c#, it is often described as a lua and c# mash up.

Comments

Expression 3 support 2 styles of comments. Single line

//Example of a single line comment

Multi line

/* Example
of a multi line
comment */

Blocks

In expression 3 a block of code is wrapped in curly brackets.

{
    // Example
}

These brackets can be omitted causing only the first line to be used as the block.

Statements

If Statement

An if statement is a conditional statement that will execute a block of code only under certain conditions.

if (Condition) block
elseif (Condition) block
else block`

if (false) {
    debug.print(0)
} elseif (false) {
    debug.print(1)
} else {
    debug.print(2)
}

Server and Client Statement

These statements will only execute a block of code based on if the code is running server side or client side.

server block

client block

server {
    debug.print("server");
}

client {
    debug.print("client");
}

Assignments

All assignment statements in expression 3 can be used to assign one or more values at once.#

Definition statement

When defining a variable it is important to note that it is nested to its current block.

class variable[, variable]* = expression[, expression]*;

number a = 7;
string first, last = "John", "Doe";
Global definition statement

Same as a definition statement except defines a global variable, these variables are not nested to there current block.

global class variable[, variable]* = expression[, expression]*;

global number a = 7;
global string first, last = "John", "Doe";
Assignment statement

Assignments are used to assign a value to an existing variable.

variable[, variable]* = expression[, expression]*;

a = 7;
first, last = "John", "Doe";
Arithmetic assignment statement

Arithmetic assignments are used to perform an arithmetic operation on a variable and then assign the result of that operation to the variable.

Additon
 variable[, variable]* += expression[, expression]*;

 exampleVar, anotherVar += 100, 200;
Subtraction
 variable[, variable]* -= expression[, expression]*;

 exampleVar, anotherVar -= 100, 200;
Division
 variable[, variable]* \= expression[, expression]*;

 exampleVar, anotherVar \= 100, 200;
Multiplication
 variable[, variable]* *= expression[, expression]*;

 exampleVar, anotherVar *= 100, 200;

User Function statement

Expression 3 supports user defined functions.

function type variable([type parameter,]*) block

function int example(int a, int b) {
    return a + b;
}

Delegates

Delegates are function templates and are used by the compiler to retain information about a functions parameters as well as its return values. This will be covered in depth in a later section.

function type variable([type,]*) {
    return number
}

function string example(string, string) {
    return 1
}

The number that appears after return is the amount of values returned of type.

Expressions

Operators

Ternary (Conditional)
Expression ? Expression : Expression
Logical Or
Expression || Expression
Logical And
Expression && Expression
Binary Xor
Expression ^^ Expression
Binary Or
Expression | Expression
Binary And
Expression & Expression
Binary And
Expression & Expression
Equal To
Expression == Expression
Not Equal To
Expression != Expression
Equal To One Or More

This is a nifty addition to expression 3 that allows you to compare if 1 value is equal to any of a list of values.

Expression == [[Expression,*]]

1 == [1, 2, 3]
Not Equal To All

Just like the previous this allows you to compare if 1 value not is equal to any of a list of values.

Expression != [[Expression,*]]
Grater Than
Expression > Expression
Less Than
Expression < Expression
Grater Or Equal To
Expression >= Expression
Less or Equal To
Expression <= Expression
Binary Shift Left
Expression << Expression
Binary Shift Right
Expression >> Expression
Addition
Expression + Expression
Subtraction
Expression - Expression
Division
Expression / Expression
Multiplication
Expression * Expression
Exponent
Expression ^ Expression
Modulus
Expression % Expression
Positive
+Expression
Negative
-Expression
Not
!Expression
Lengh
#Expression
Cast

The casting operator takes a class. The Compiler will then try to convert the value on the right to that class.

(Class) Expression

number i = (number) 101;

Constructors

A Constructor is used to create an object.

new Class([expression,]*)

new vector.3d(1, 1, 1)
Call Operator

In expression 3 some objects can be called, user functions being the main one.

Value([Expression,]*)

//No good examples currently exist.

Functions and Libraries

In expression 3 all functions exist with in a library.

Library.Function([Expression,]*)

debug.print(278)

Methods

Value.Method([Expression,]*)

"string".find("s")

Events

Events are lambda based callbacks that are used to repsond to events outside the main execution. Events work simular to the hook system in gmod lua.

event.add(string event name, string callback id, function callback )

event.add("Think", "example", function() { system.print("think") })

Simularly you can remove event call backs

event.remove(string event name, string callback id)

event.remove("Think", "example")
Clone this wiki locally