From d6ba30b94a24607bce5db5e706eb20cc051a98f0 Mon Sep 17 00:00:00 2001 From: A404M Date: Wed, 18 Sep 2024 19:46:38 +0330 Subject: initial commit --- lang.felan | 159 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 159 insertions(+) create mode 100644 lang.felan (limited to 'lang.felan') diff --git a/lang.felan b/lang.felan new file mode 100644 index 0000000..b18785e --- /dev/null +++ b/lang.felan @@ -0,0 +1,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 +} -- cgit v1.2.3