Soplang Syntax
Learn Soplang syntax, comments, declarations, blocks, strings, and the structure of a program.
Soplang Syntax
Soplang uses Somali words for familiar programming concepts. This guide introduces the syntax for declarations, functions, control flow, and other language features.
Hello World
This program uses the built-in qor() function to print a message.
hello-world.sop
qor("Hello, Adduun!")
Structure
Soplang programs use these building blocks:
- Declarations –
door,abn,jajab,qoraal,bool,teed,walax, andmadoor - Functions –
hawlandceli - Control flow –
haddii,kale,dooro,kuceli, andintay - Classes –
qaab,dhaxal,cusub, andnafta - Error handling and modules –
tijaabi/qaboandkeen - Built-ins – functions such as
qor(),gelin(), andnooc()
Curly braces ({}) enclose blocks. Statements execute in sequence.
Comments
Comments are not executed. Soplang supports single-line comments (//) and multiline comments (/* ... */).
// A single-line comment /* A multiline comment */ qor("Faallooyinka lama fuliyo") // Comment: an end-of-line comment
Basic Rules
- Statement separators: one statement per line is the usual style. Semicolons (
;) are optional;door x = 1; qor(x);is also valid. - Blocks:
{}enclose the bodies of conditionals, loops, functions, and classes. Indentation improves readability but does not define blocks. - Conditions:
haddii,intay, anddoororequire parentheses()around their condition or expression. - Case sensitivity:
magacandMagacare different variable names. - Strings: use double quotes (
"...") or single quotes ('...'). Plain strings preserve backslashes. Usee"..."for escapes such as\n, orf"...{name}..."for interpolation. - Concatenation with
+: when either operand is a string, the other value is converted to text.
door a = "Salaan" door b = 'Salaan' qor(a == b) // run door Magac = "Ali" door magac = "Xasan" qor(Magac + " iyo " + magac) // Ali iyo Xasan qor("Tirada: " + 5) // Tirada: 5
Example Program
This example reads a name and prints a greeting. It combines a function definition, a variable, and built-in functions.
example.sop
hawl salaan(magac) { qor("Asalaamu calaykum, " + magac) } door magaca = gelin("Magacaaga qor: ") salaan(magaca)
File Extension
Soplang source files use the .sop extension. Run a file from the command line, or experiment in the interactive REPL.
run.sh
soplang file.sop