vighnesh153 / spl

SPL (Simple Programming Language), a friendly neighborhood programming language.
https://vighnesh153.dev/projects/spl
4 stars 1 forks source link

PERMANENTLY MOVED HERE: Repository Link


SPL

Simple Programming Language

SPL is a small friendly neighbourhood programming language which is developed with the intention of helping people start with their programming journey. Live Demo

Why SPL?

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.

Syntax

Fun Fact: The syntax is influenced by Python's and Javascript's syntax.

Primitive data-types

You can use three different types of primitive data:

string can only be defined using single quotes.

Non-primitive data-types

  • Supports only 3 types of arrays namely of type number or string or boolean.
  • Jagged or multi-dimensional arrays are not supported in this version.
  • Indexing of non-numeric arrays is not supported in this version.
Operations on array

Imgur

  • 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 with length of.

Variable Declaration

You can declare variables as shown below.

Imgur

  • Don't forget the punctuation mark, comma, in declaration of an array.
  • You must initialize the variable to some value when declaring it.

Variable Modification

To modify the values in the variables, you use the set keyword.

Imgur

Output

To output data, use the display keyword. By default, a new line character will be added by the display command at the end.

Imgur

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.

Arithmetic operations

Supports +, -, *, / and % operators.

Imgur

Conditionals

Notice the punctuation, comma, after the boolean expression.

Imgur

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 but 1+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.

Now, the fun begins.

Loops

Repeated Execution

Three variations

Imgur

Iterating over arrays

Two variations

Imgur

Functions

Imgur

To invoke a function, use the result of command if the function returns something, else, use execute command to just execute the function.

Imgur

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 even let number b be 1 + (result of add(2, 3)) are both illegal.

Language Notes and Caveats

Notes for people, who are familiar with programming