Language Reference

Complete syntax reference for the Layman programming language

Statement Types

Variable Assignment

Syntax: the variable <id> [of type <Type>] is <expr>

# With type annotation
the variable name of type String is 'Alice'
the variable count of type Number is 5

# Without type (inferred)
name is 'Alice'
count is 5

# Multi-word variable names
the variable user name of type String is 'Bob'
the variable total count of type Number is 100

Function Call

Syntax: call function <name> with <args>

# Single argument
call function greet with argument 'World'

# Multiple arguments
call function add with argument 5 and argument 3
call function process with first number 10 and second number 20

# Method call on object
call function greet on person

Print Statement

Syntax: print <expr> or print the variable <id>

print 'Hello, World!'
print the variable name
print concatenate 'name: ' with name

Conditional

Syntax: if <expr> then <stmt> [else <stmt>]

if condition then
  print "true"
else
  print "false"
end if

# Else-if chains
if x is 1 then
  print "one"
else if x is 2 then
  print "two"
else
  print "other"
end if

For Loop

Syntax: for each <id> [in] <expr> do <stmt>

for each item in list do
  print item
end for

# 'in' is optional
for each number numbers do
  print number
end for

While Loop

Syntax: while <expr> do <stmt>

while count is less than 10 do
  count is count plus 1
  print count
end while

Return Statement

Syntax: return [<expr>]

# Return a value
return result

# Return nothing (Void)
return nothing
return

Function Definition

Syntax: define function <name> that takes <params> and returns <type>

define function add that takes first as Number and second as Number and returns Number
  return first plus second
end function

# Void return type
define function greet that takes name as String and returns Void
  greeting is 'Hello, ' plus name
  print greeting
end function

Class Definition

Syntax: define class <Name> [extends <Parent>] that has <members>

define class Person that has
  property name of type String
  property age of type Number

  define function greet that returns Void
    print "Hello, I am " plus name
  end function
end class

# Inheritance
define class Student that extends Person
  property school of type String
end class

Object Creation

Syntax: is a new <ClassName> with <props>

person is a new Person with
  name which is 'Alice'
  age which is 30

# Can also use explicit variable declaration
the variable student of type Student is a new Student with
  name which is 'Bob'
  age which is 20
  school which is 'University'

Expression Types

Literals

# Numbers
5
10
3.14
-5

# Strings
'hello'
"world"

# Booleans
true
false

# Nothing
nothing
void

Variable References

# Single-word identifiers
x
name
count

# Multi-word identifiers
user name
total count
first item

Operations

# Arithmetic
a plus b
a minus b
a times b
a divided by b
a modulo b

# Comparison
x is 5
x is greater than 10
x is less than 5
x equals 5

# Logical
condition1 and condition2
condition1 or condition2
not condition

Type System

Primitive Types

  • Number - numeric values (integers and floats)
  • String - text values (also accepts Text)
  • Bool - boolean values (also accepts Boolean)
  • Void - no return value (also accepts Nothing)

Optional Types

# Optional type with 'maybe'
optional_value of type maybe Number is nothing
optional_value of type maybe Number is 10

Type Inference

Types can be inferred from values. Explicit type annotations are optional but recommended for clarity.

Standard Library Functions

String Functions

# Concatenate strings
result is call function concatenate with argument 'Hello, ' and argument name

# Convert to string
text_value is convert number to text

Error Handling

# Try-catch
try
  result is 10 divided by 0
catch error
  print "error: " plus error
end try

# Throw
if count is less than 0 then
  throw "count cannot be negative"
end if

Imports

# Import from path
import math from 'std/math'

# Import from standard location
import collections

# Use imported functions
result is call function math.square with 5

Grammar Rules

Whitespace

  • Spaces and tabs are allowed between tokens
  • Newlines separate statements
  • Indentation (2 spaces) is semantically meaningful
  • Empty lines are ignored

Comments

Comments start with # and continue to the end of the line.

Case Sensitivity

  • Type names are capitalized: Number, String
  • Variable and function names are lowercase: name, count
  • Keywords are case-insensitive: if, then, else