aboutsummaryrefslogtreecommitdiff
path: root/lang.felan
blob: b18785e8ec7740b2ed35fb584dd7e7a5362bbd95 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// variable
// variable definition (full version)
variableName : Type = value;
constantName : Type : value;

// i.e.
myInt : Int = 23;
myConstInt : Int : 23;
myFloat : Float = 23.0;

// multiple variable definition (full version)
variableName0, ... : TypeForAllOfThem = value0, ...;

// i.e.
myInt, yourInt : Int = 23 , 54;

// variable definition (compiler knows types)
variableName := value;
constantName :: value;

// i.e.
myInt := 23;
myConstInt :: 23;
myFloat := 23.0;

// multiple variable definition (compiler knows types)
variableName0, ... := value0, ...;

// i.e.
myInt, yourInt := 23, 54; // all values must have the same type

// variable definition (without initialization) constants can't be defined this way 
variableName : Type;

// i.e.
myInt : Int;
myFloat : Float;

// multiple variable definition (without initialization)
variableName0, ... : TypeForAllOfThem;

// i.e.
myInt, yourInt : Int;

// pointers
// pointers will be initialized to undefined

// definition of a pointer which can't be null
pointerName : *Type = value;

// i.e.
myPointer : *Int = new Int;

// definition of a pointer which can be null
myPointer : nullable*Type = value;

// i.e.
myPointer : nullable*Int = null;

// arrays
arrayName : [size]Type = [size]Type{value,...};

// i.e.
myArray : [4]Int = [4]Int{11,2,23,4};
myArray2 := [4]Int{11,2,23,4}; // identical to the last one
myArray3 : [4]Int;

// function
// function definition
functionName :: (paramName:ParamType, ...) -> ReturnType {
  // body
}

// i.e.
foo :: () {
  // no param no returning (void)
}
bar :: (myInt: Int,myFloat:Float) -> Int {
  // 2 param Int , Float and Int return Type
}
boo :: (myInt: Int) -> Int, Int {
  // this is the way to return multiple values
  return myInt, myInt;
}

// function calling
functionName(paramters, ...);

// i.e
foo();
retValue := bar(myInt,myFloat);
retValue0,retValue2 := boo(myInt);

// lambdas
// lambdas are just functions that have been assigned to variables

// structs (classes)
// definition
StructName :: struct {
  // field
  fieldName : Type;
  
  // constant field
  constantFiledName : Type : value;

  // method (has this pointer)
  methodName :: (paramName:ParamType, ...) -> ReturnType {
    // body
  }

  #static
  staticFieldName : Type = value;

  // static method (has no this pointer)
  #static
  staticMethodName :: (paramName:ParamType, ...) -> ReturnType {
    // body
  }
}

// instancing
instanceName : StructName = StructName {
  .fieldName = value,
  ...
};

// instancing as a pointer
pointerInstance := new StructName{
  .fieldName = value,
  ...
}

// with undefined value
pointerInstance := new StructName;

// if
if (condition) {
  // body
}

// while
while (condition) {
  // body
}

// for
for ( definition ; condition ; step ) {
  // body
}

// i.e.
for (i := 0;i < 10;++i){
  // body
}

// for each
for ( variableName in iteratorName ){
  // body
}