Difference between revisions of "SIPL"

From Software Inc.
Jump to navigation Jump to search
(Created page with "The Software Inc. Programming Language consists of a lexer, parser and interpreter written specifically for scripting in Software Inc. ==Performance considerations== SIPL is a...")
 
 
(18 intermediate revisions by the same user not shown)
Line 6: Line 6:
 
* You cannot define namespaces, classes or functions
 
* You cannot define namespaces, classes or functions
 
* Number operations in SIPL convert all numbers to doubles behind the scenes
 
* Number operations in SIPL convert all numbers to doubles behind the scenes
* You can use the var keyword to declare temporary variables, but you cannot specify their type
+
* You can use the '''var''' keyword to declare temporary variables, but you cannot specify their type
* You cannot use bitwise operations. The ^ symbol raises a number to a power
+
* You cannot use bitwise operations. The <code>^</code> symbol raises a number to a power or evaluates xor on booleans
* You cannot increment or use operations together with assignment, i.e. += or ++. You must write i = i + 1
+
* You cannot increment or use operations together with assignment, i.e. <code>+=</code> or <code>++</code>. You must write <code>i = i + 1</code>
* SIPL does not support the new keyword, but you can create arrays by writing ~[1, 2, 3]
+
* SIPL does not support the '''new''' keyword, but you can create arrays by writing <code>~[1, 2, 3]</code> or call a constructor by just using the type name, e.g. <code>Color(1,0,0)</code>
* For loops are not supported, however you can write foreach (element in list)
+
* For loops are not supported, however you can write <code>'''foreach''' (element '''in''' list)</code>
* Comparisons can be chained, e.g. if (10 < x < 20)
+
* Enums should not be qualified when assigning, comparing or in function parameters, e.g. you should write '''Female''' instead of '''Human.Gender.Female'''.
* Any enumerable can be indexed into with a number (except for dictionaries), including sets.
+
* Comparisons can be chained, e.g. <code>'''if''' (10 < x < 20)</code>
* Single quotation marks () do nothing
+
* Single quotation marks (') do nothing
 
* Multiline comments are not supported
 
* Multiline comments are not supported
 +
 
==Example==
 
==Example==
  <nowiki>var words = ~[“hello”, “ ”, “world”];//Create an array
+
  '''var''' words = ~[<span style="color:blue">"hello"</span>, <span style="color:blue">" "</span>, <span style="color:blue">"world"</span>]; <span style="color:green">//Create an array</span>
if (5 < 10 < 20)//Always true
+
'''if''' (<span style="color:blue">5</span> < <span style="color:blue">10</span> < <span style="color:blue">20</span>) <span style="color:green">//Always true</span>
{
+
{
var result = “”;
+
'''var''' result = <span style="color:blue">""</span>;
foreach (word in words)
+
'''foreach''' (word '''in''' words)
{
+
{
result = result + word; //Concatenate the strings from the array
+
result = result + word; <span style="color:green">//Concatenate the strings from the array</span>
}
+
}
Debug(result);//Log the result
+
Debug(result); <span style="color:green">//Log the result</span>
}</nowiki>
+
}
 +
'''else'''
 +
{
 +
Debug(<span style="color:blue">"Something went wrong"</span>);
 +
}
 +
 
 
==Built-in functions==
 
==Built-in functions==
 
===Math functions===
 
===Math functions===
Abs(x) – Returns the absolute value of x
+
* Abs(x) – Returns the absolute value of x
Pow(x, y) – Raises x to the power of y
+
* Pow(x, y) – Raises x to the power of y
Sqrt(x) – Returns the square root of x
+
* Sqrt(x) – Returns the square root of x
Log(x) – Returns the natural logarithm of x
+
* Log(x) – Returns the natural logarithm of x
Log10(x) – Returns the base 10 logarithm of x
+
* Log10(x) – Returns the base 10 logarithm of x
Round(x) – Rounds x to the nearest integer
+
* Round(x) – Rounds x to the nearest integer
Ceil(x) – Rounds x up to the nearest integer
+
* Ceil(x) – Rounds x up to the nearest integer
Floor(x) – Rounds x down to the nearest integer
+
* Floor(x) – Rounds x down to the nearest integer
Min(x, y) – Returns the smallest number between x and y
+
* Min(x, y) – Returns the smallest number between x and y
Max(x, y) – Returns the largest number between x and y
+
* Max(x, y) – Returns the largest number between x and y
Sign(x) – Returns -1, 0, 1 based on the sign of x
+
* Sign(x) – Returns -1, 0, 1 based on the sign of x
Sin(x) – Returns the sine of x
+
* Sin(x) – Returns the sine of x
Cos(x) – Returns the cosine of x
+
* Cos(x) – Returns the cosine of x
Lerp(a, b, t) – Interpolates between a and b using t
+
* Lerp(a, b, t) – Interpolates between a and b using t
Clamp(x, a, b) – Clamps x between a and b
+
* Clamp(x, a, b) – Clamps x between a and b
Clamp01(x) – Clamps x between 0 and 1
+
* Clamp01(x) – Clamps x between 0 and 1
 
===Enumerable functions===
 
===Enumerable functions===
These functions can be used on any C# enumerable, e.g. arrays, lists, dictionaries, sets, etc. You simply use the function on the enumerable, and pass an anonymous function as a parameter, using x to refer to the elements of the enumerable, e.g. employees.Where(x.Salary > 1000).OrderBy(x.Age).Select(x.Name), will return the names of all employees that make more than $1000 ordered by their age. They work exactly like LINQ extension methods, basically.
+
These functions can be used on any C# enumerable, e.g. arrays, lists, dictionaries, sets, etc. You simply use the function on the enumerable, and pass an anonymous function as a parameter, using x to refer to the elements of the enumerable, e.g.
 +
employees.Where(x.Salary > 1000).OrderBy(x.Age).Select(x.Name) //Will return the names of all employees that make more than $1000 ordered by their age.
 +
They work exactly like LINQ extension methods, basically.
 +
 
 +
* Any(func) – Returns whether any elements satisfy func(x)
 +
* All(func) – Returns whether all elements satisfy func(x)
 +
* None(func) - Returns whether no elements satisfy func(x)
 +
* ForEach(func) – Runs func(x) on all elements
 +
* Select(func) – Runs func(x) on all elements and returns the result
 +
* SelectMany(func) – Assuming input is an enumerable of enumerables, runs func(x) on elements in each sub enumerable and returns it as a flat enumerable
 +
* Count(func) – Returns how many elements satisfy func(x)
 +
* Where(func) – Returns elements that satisfy func(x)
 +
* First() - Returns the first element of the enumerable or null
 +
* Last() - Returns the last element of the enumerable or null
 +
* FindFirst(func) – Returns the first element that satisfies func(x)
 +
* OrderBy(func) – Returns elements sorted by func(x) in ascending order
 +
* OrderByDescending(func) – Pretty obvious
 +
* Distinct() – Returns only unique elements in the enumerable
 +
* Sum(func) – Returns the sum of running func(x) on all elements
 +
* Average(func) – Returns the sum of running func(x) on all elements divided by the amount of elements
 +
* Min(func) – Returns the smallest number resulting from running func(x) on all elements, returns 0 on empty input
 +
* Max(func) – Returns the largest number resulting from running func(x) on all elements, returns 0 on empty input
 +
* Size() – Returns how many elements there are in the enumerable
 +
* GetRandomElement() – Returns a random element from the enumerable
  
Any(func) – Returns whether any elements satisfy func(x)
 
All(func) – Returns whether all elements satisfy func(x)
 
None(func) - Returns whether no elements satisfy func(x)
 
ForEach(func) – Runs func(x) on all elements
 
Select(func) – Runs func(x) on all elements and returns the result
 
SelectMany(func) – Assuming input is an enumerable of enumerables, runs func(x) on elements in each sub enumerable and returns it as a flat enumerable
 
Count(func) – Returns how many elements satisfy func(x)
 
Where(func) – Returns elements that satisfy func(x)
 
FindFirst(func) – Returns the first element that satisfies func(x)
 
OrderBy(func) – Returns elements sorted by func(x) in ascending order
 
OrderByDescending(func) – Pretty obvious
 
Distinct() – Returns only unique elements in the enumerable
 
Sum(func) – Returns the sum of running func(x) on all elements
 
Average(func) – Returns the sum of running func(x) on all elements divided by the amount of elements
 
Size() – Returns how many elements there are in the enumerable
 
GetRandomElement() – Returns a random element from the enumerable
 
 
===Other functions===
 
===Other functions===
String(x) – Converts x to a string, using C# .ToString()
+
* String(x) – Converts x to a string, using C# .ToString()
FormatString(x, y) – Converts x to a string with a format string y using C# .Tostring(format)
+
* FormatString(x, y) – Converts x to a string with a format string y using C# .Tostring(format)
Debug(x) – Writes x to the log using Unity’s log system
+
* Debug(x) – Writes x to the log using Unity’s log system
Random() – Returns a random decimal number between 0 and 1
+
* Random() – Returns a random decimal number between 0 and 1
RandomRange(x, y) – Returns a random decimal number between x and y
+
* RandomRange(x, y) – Returns a random decimal number between x and y
RandomInteger(x, y) – Returns a random integer between x and y(exclusive)
+
* RandomInteger(x, y) – Returns a random integer between x and y(exclusive)

Latest revision as of 12:15, 24 February 2026

The Software Inc. Programming Language consists of a lexer, parser and interpreter written specifically for scripting in Software Inc.

Performance considerations

SIPL is an interpreted language and relies heavily on the .NET reflection library to interact with C# types, which makes it somewhat slow. Since scripts aren’t executed very often, it won’t be much of a problem, just keep the complexity of your scripts in mind.

Syntax

SIPL was written to resemble C# as much as possible, while still remaining a simple scripting language, so the simplest way to explain the syntax is how it varies from C#:

  • You cannot define namespaces, classes or functions
  • Number operations in SIPL convert all numbers to doubles behind the scenes
  • You can use the var keyword to declare temporary variables, but you cannot specify their type
  • You cannot use bitwise operations. The ^ symbol raises a number to a power or evaluates xor on booleans
  • You cannot increment or use operations together with assignment, i.e. += or ++. You must write i = i + 1
  • SIPL does not support the new keyword, but you can create arrays by writing ~[1, 2, 3] or call a constructor by just using the type name, e.g. Color(1,0,0)
  • For loops are not supported, however you can write foreach (element in list)
  • Enums should not be qualified when assigning, comparing or in function parameters, e.g. you should write Female instead of Human.Gender.Female.
  • Comparisons can be chained, e.g. if (10 < x < 20)
  • Single quotation marks (') do nothing
  • Multiline comments are not supported

Example

var words = ~["hello", " ", "world"]; //Create an array
if (5 < 10 < 20) //Always true
	{
	var result = "";
	foreach (word in words)
		{
		result = result + word; //Concatenate the strings from the array
		}
	Debug(result); //Log the result
	}
else
	{
	Debug("Something went wrong");
	}

Built-in functions

Math functions

  • Abs(x) – Returns the absolute value of x
  • Pow(x, y) – Raises x to the power of y
  • Sqrt(x) – Returns the square root of x
  • Log(x) – Returns the natural logarithm of x
  • Log10(x) – Returns the base 10 logarithm of x
  • Round(x) – Rounds x to the nearest integer
  • Ceil(x) – Rounds x up to the nearest integer
  • Floor(x) – Rounds x down to the nearest integer
  • Min(x, y) – Returns the smallest number between x and y
  • Max(x, y) – Returns the largest number between x and y
  • Sign(x) – Returns -1, 0, 1 based on the sign of x
  • Sin(x) – Returns the sine of x
  • Cos(x) – Returns the cosine of x
  • Lerp(a, b, t) – Interpolates between a and b using t
  • Clamp(x, a, b) – Clamps x between a and b
  • Clamp01(x) – Clamps x between 0 and 1

Enumerable functions

These functions can be used on any C# enumerable, e.g. arrays, lists, dictionaries, sets, etc. You simply use the function on the enumerable, and pass an anonymous function as a parameter, using x to refer to the elements of the enumerable, e.g.

employees.Where(x.Salary > 1000).OrderBy(x.Age).Select(x.Name) //Will return the names of all employees that make more than $1000 ordered by their age.

They work exactly like LINQ extension methods, basically.

  • Any(func) – Returns whether any elements satisfy func(x)
  • All(func) – Returns whether all elements satisfy func(x)
  • None(func) - Returns whether no elements satisfy func(x)
  • ForEach(func) – Runs func(x) on all elements
  • Select(func) – Runs func(x) on all elements and returns the result
  • SelectMany(func) – Assuming input is an enumerable of enumerables, runs func(x) on elements in each sub enumerable and returns it as a flat enumerable
  • Count(func) – Returns how many elements satisfy func(x)
  • Where(func) – Returns elements that satisfy func(x)
  • First() - Returns the first element of the enumerable or null
  • Last() - Returns the last element of the enumerable or null
  • FindFirst(func) – Returns the first element that satisfies func(x)
  • OrderBy(func) – Returns elements sorted by func(x) in ascending order
  • OrderByDescending(func) – Pretty obvious
  • Distinct() – Returns only unique elements in the enumerable
  • Sum(func) – Returns the sum of running func(x) on all elements
  • Average(func) – Returns the sum of running func(x) on all elements divided by the amount of elements
  • Min(func) – Returns the smallest number resulting from running func(x) on all elements, returns 0 on empty input
  • Max(func) – Returns the largest number resulting from running func(x) on all elements, returns 0 on empty input
  • Size() – Returns how many elements there are in the enumerable
  • GetRandomElement() – Returns a random element from the enumerable

Other functions

  • String(x) – Converts x to a string, using C# .ToString()
  • FormatString(x, y) – Converts x to a string with a format string y using C# .Tostring(format)
  • Debug(x) – Writes x to the log using Unity’s log system
  • Random() – Returns a random decimal number between 0 and 1
  • RandomRange(x, y) – Returns a random decimal number between x and y
  • RandomInteger(x, y) – Returns a random integer between x and y(exclusive)