Egg Grammar
Here is where you will find definitions for grammar and keywords in egg to aid in hatching your chicks. Keep in mind these can be modified using user language packs, so please refer to doc for your specific language pack that you're using, as this page will display default usage.
Literals
Literals in Egg are defined with the VAR function, similar to other languages like PHP, where an explicit type is not necessarily required.
Booleans: VAR boolean = TRUE
Numbers: VAR num = 1
Strings: VAR string = "Hello World!"
Arrays:
VAR x = {}
VAR x = {1, 2, 3} len = 3
VAR x = {:10} len = 10 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
VAR x = {:3, 1, 2, 3} len = 6 {1, 2, 3, 0, 0, 0}
Functions
Functions in Egg support passing in single or multiple arguments, as well as lack thereof. Returning value functions are also fully supported, using the RETURN keyword in all caps at the end of your function.
Note: When passing arguments, the type is generic, but if you perform type specific operations within the function with an incompatible type, it will throw an error.
Defining
DEF myFunction(argument){...}
Calling
myFunction(1)
Classes
Classes in Egg allow for categorization of your data being stored inside the class. The access levels of variables are as follows;
FULL: The variables or functions defined here can be called anywhere in your code in any scope.
READ: The variables or functions defined here can be read or accessed from anywhere in your code, but not modified.
HIDE: The variables or functions defined here can only be accessed within the class, and explicitly not outside of that scope.
There are additional keywords that you can use to define how much access inherited classes have to the information in the parent class. These are as follows;
SHARE: Anything under this scope will be inherited by the child class and be able to be fully utilized.
PRIVATE: Anything under this scope will only be accessible in the parent class and not subsequent child classes.
Defining
An example containing some of the access permissions is displayed below.
CLASS myClass{
FULL:
VAR x = 366
HIDE:
VAR y = 993
PRIVATE:
DEF myFunction(){
x = 993
}
SHARE:
DEF intToStr(arg){
println(toString(arg))
}
}
Egg has support for defining parent and child classes that will inherit from each other, with similar notation to c++, with the following:
CLASS child : parent(){}
Conditionals
IF(fooInteger == 366 AND barInteger == 993)
{
fooInteger = 993
}
ELSE IF(fooInteger == 993 OR barInteger == 366)
{
barInteger = 366
}
ELSE
{
newInteger = fooInteger + barInteger
}
Loops
VAR i = 0
LOOP(i = 0, i < 366, i = i + 1){
println(i)
}
Types
EGG has 4 main types: INTS, FLOATS, STRINGS and BOOLEANS Variables can by typed:
INT integer = 5
FLOAT floating_point = 1.3
STRING string = "I am a string"
BOOL boolean = TRUE
Typing a variable 'type-locks' it, and prevents its value from being changed to that of a different type.
Functions can also be typed:
DEF (INT arg_1, FLOAT arg_2, arg_3) : FLOAT {
print(arg_3)
RETURN arg_1 + arg_2
}
Functions with typed arguments will only accept inputs of the correct type (however they do not NEED to be type-locked). The return type can be specified after the parameter list with a COLON followed by a type.
Custom CLASSES are also valid types:
CLASS Number{
READ:
VAR val
DEF Number(arg){
val = arg
}
}
DEF add(Number first, Number second) : Number {
RETURN MAKE Number(first.val + second.val)
}
Errors
Error detection is currently supported as of v1.3.1 that indicates where your errors occur in your code, as well as if it happens during the parsing or lexing phase of your code's compilation.