PERMANENTLY MOVED HERE: Repository Link
SPL is a small friendly neighbourhood programming language which is developed with the intention of helping people start with their programming journey. Live Demo
It is not any advanced language which you can use to build things. It is designed just to help people learn about programming. This language is very close to the english language. When you are starting your programming journey, syntax should be the least of your worries. You should primarily focus on the logic-building which is the most critical element in building solutions.
Fun Fact: The syntax is influenced by Python's and Javascript's syntax.
You can use three different types of primitive data:
number
Example:123
,45.67
string
Example:'I am a string'
boolean
Example:true
,false
string
can only be defined using single quotes.
array
Example:[ 1, 2, 3 ]
,[ true, false, false ]
- Supports only 3 types of arrays namely of type
number
orstring
orboolean
.- Jagged or multi-dimensional arrays are not supported in this version.
- Indexing of non-numeric arrays is not supported in this version.
pop from
will remove the last element from the array.push
-into
will push an item at the last of the array.length of
will return the length of the array
- If you want to use
length of
in a complex arithmetic expression, make sure to wrap it in parentheses. eg.,1 * (2 + (length of numberArray))
- Finding length of a naked array is not supported. eg.,
length of [1, 2, 3, 4]
won't work. Store the array in some variable and then use that variable along withlength of
.
You can declare variables as shown below.
- Don't forget the punctuation mark, comma, in declaration of an array.
- You must initialize the variable to some value when declaring it.
To modify the values in the variables, you use
the set
keyword.
To output data, use the display
keyword. By default,
a new line character will be added by the display
command at the end.
The output of the above commands will be
Hello World
123
A number less than 1000, is: 200.
1,2,3,4
true
To display more than one values on the same line, pass them as comma separated values to the display command.
Supports +
, -
, *
, /
and %
operators.
Notice the punctuation, comma, after the boolean expression.
If you want to use arithmetic expressions in the boolean expression, then use them without having any whitespace between them and no parentheses in arithmetic expressions inside a boolean expression, or unexpected things may occur. eg.
1 + 2 * 3 * 1 < 4
won't work but1+2*3*1 < 4
will. It is recommended to store the result of the arithmetic expression in a variable and then use that variable to compare.
Three variations
loop for x times
loop for x times with i as counter
loop while <EXPRESSION_IS_TRUE>
Two variations
for every item in arr
for every item in arr with i as index
To invoke a function, use the result of
command
if the function returns something, else, use execute
command to just execute the function.
Calling the function inside any expression is not supported in this iteration. To use the result of any function call, you first store the result in some variable, and then use that variable as a reference to the result in any expression. Example,
let number a be result of add(1, (result of add(2, 3)))
or evenlet number b be 1 + (result of add(2, 3))
are both illegal.
- Output will be printed all at once instead of printing when display is called.
- Indentation is extremely important (just like Python)
- 4-spaces or 1 tab character for indentation
- Comments are not supported in this iteration
- Errors may not be that helpful as of now, but it will at least try to point you to the line where the error is, or the starting line of the block, that has error.
- Escape character is not supported in this iteration
- Bitwise operators don't work
- Cannot take inputs from the user
- Cannot declare a variable as a constant
- Arithmetic expressions in boolean expressions are supported, only without spaces
- Ternary operators are not supported
- Lastly, you cannot do Object oriented programming in this language
-
I have tried to handle a lot of scenarios and tested a lot as well. But, I may have missed something, and I request you that if you find something which is not expected or is not documented, please let me know, so I can work on that.
-
If you are already familiar with programming, then you may often find some errors because the style of this language is a bit different from the popular programming languages like Python, Javascript, etc. You might miss out some punctuation mark, or maybe you forgot to add
resut of
operator before calling a function, though it is valid in other languages, but it won't be parsed in this language. I myself struggle to write a simple program in SPL. So, I recommend that instead of starting from scratch, choose from one of the examples, which can be found beside the editor, and modify them accordingly. This way, you will encounter fewer errors.