Basic Syntax


The Spla language has many similarities to C, C++, Java and Python. However, there are some definite differences between the languages.

First Spla Program

Let us execute the programs in different modes of programming.

Interactive Mode Programming

Invoking the interpreter without passing a program file as a parameter brings up the following prompt −

Spla CLI for SPLA Developers, Version: 0.1.0, Build id: 190118-202 [32 bit] for Windows
>>help
1.cp  :: To change prompt, example 'cp >>'.
2.copyright :: To know copyright details.
3.license :: To know License details.
4.credits :: To know about contributors.
Visit http://splang.n-labs.org/docs/. for more help
>>cp ##
##<<'Welcome to spla...'
Welcome to spla...
##

Type the following text at the Spla prompt and press Enter −

## <<'Hello, I am Spla!';

This produces the following result −

Hello, I am Spla!

File mode programming

Invoking the interpreter with a file parameter begins execution of the file. When the file is finished, the interpreter is no longer active.

Let us write a simple Spla program in a file. Spla files have the extension .spla. Type the following source code in a FirstProgram.spla file −

<<'Hello, I am Spla!';

We assume that you have the Spla interpreter set in PATH variable. Now, try to run this program as follows −

On Windows

C:\Spla>Spla FirstProgram.spla

This produces the following result −

Hello, I am Spla!

Spla Identifiers

A Spla identifier is a name used to identify a variable, method, class, module or other object. An identifier starts with a letter A to Z or a to z or an underscore (_) followed by zero or more letters, underscores and digits (0 to 9).

Spla does not allow punctuation characters such as @, $, and % within identifiers. Spla is a case sensitive programming language. Thus, Manpower and manpower are two different identifiers in Spla.

Here are naming conventions for Spla identifiers −

  • Class names start with an uppercase letter. All other identifiers start with a lowercase letter.

  • Starting an identifier with two star(*) indicates that the identifier is private.

  • Starting an identifier with three star(*) indicates a public identifier.

Reserved Words/Symbols

The following list shows the Spla keywords. These are reserved words and you cannot use them as constants or variables or any other identifier names. All the Spla keywords contain lowercase letters only.

&& || !!
~~ $ #
* ** ***
?? @@ continue
break to try
catch <- ->
## // /?
>> << bool
int str flt

Lines and Indentation

Spla does not use braces({}) to indicate blocks of code for class and function definitions or flow control. Blocks of code are denoted by line indentation, which is rigidly enforced.

The number of Tab in the indentation is variable, but all statements within the block must be indented the same amount. For example −

?? true:
   <<'True';

//
   <<'False';

However, the following block generates an error −

?? true:
   <<'Answer';
<<'Answer';

//
   <<'Answer';
<<'Answer';

Quotation in Spla

Spla accepts single (') denote string literals, as long as the same type of quote starts and ends the string.

word = 'word'Answer
sentence = 'This is a sentence.';

Comments in Spla

Two hash sign (!) that is not inside a string literal is the beginning of a comment. All characters after the !!, up to the end of the physical line, are part of the comment and the Spla interpreter ignores them.

!! First comment
<<'Hello, I am Spla!';!! second comment

This produces the following result −

Hello, Spla!

You can type a comment on the same line after a statement or expression −

name = 'This is string'; !! This is again comment

You can comment multiple lines as follows −

!! This is a comment.
!! This is a comment, too.
!! This is a comment, too.
!! I said that already.

Following string is also ignored by Spla interpreter and can be used as a multiline comments:

~~
This is a multiline
comment.
~~

Using Blank Lines

A line containing only whitespace or tab, is known as a blank line and Spla totally ignores it.

Waiting for the User

The following line of the program displays the prompt and, the statement saying “Press the enter key to exit”, and then waits for the user to take action −


<<'\n\nPress the enter key to exit.';
>> a

Here, "\n\n" is used to create two new lines before displaying the actual line. Once the user presses the key, the program ends. This is a nice trick to keep a console window open until the user is done with an application.

Multiple Statements on a Single Line

The semicolon ( ; ) allows multiple statements on a single line given that no statement starts a new code block. Here is a sample snip using the semicolon −

int i=44; str y= 'foo';

Multiple Statement Groups as Suites

Groups of individual statements, which make a single code block are called suites in Spla. Compound or complex statements, such as if, while, def, and class require a header line and a suite.

Header lines begin the statement (with the keyword) and terminate with a colon ( : ) and are followed by one or more lines which make up the suite. For example −

?? expression : 
   suite
/? expression : 
   suite 
//  
   suite