Syntax Reference
This page details the complete syntax rules for the Animal language.
Code Structure
Animal programs consist of statements, separated implicitly by newlines or explicitly by semicolons (;).
Variables
Variable Naming
Variable names:
Must start with a letter or underscore
Can contain letters, numbers, and underscores
Are case-sensitive
Cannot be a reserved keyword
valid_name -> 10
_also_valid -> 20
ThisIsValid -> 30
:: Invalid examples:
:: 1name -> 40 (starts with number)
:: name-with-dash -> 50 (contains dash)
:: growl -> 60 (reserved keyword)
Variable Assignment
The assignment operator is ->:
name -> "Luna"
age -> 5
:: Multiple assignments
a -> b -> c -> 10 :: All variables get value 10
Variable Type Annotations
Optional type annotations use a colon after the variable name:
count: int -> 5
name: string -> "Buddy"
is_active: bool -> true
Data Types
Animal supports the following primitive data types:
Integers
Whole numbers:
a -> 42
b -> -7
Floats
Numbers with decimal points:
pi -> 3.14159
half -> 0.5
Booleans
true or false values:
is_valid -> true
has_error -> false
Strings
Text enclosed in single or double quotes:
name -> "Alice"
message -> 'Hello, world!'
Lists
Ordered collections of items, enclosed in square brackets:
numbers -> [1, 2, 3, 4]
mixed -> ["apple", 5, true]
Operators
Arithmetic Operators
Animal Operator |
Equivalent |
Description |
|---|---|---|
|
|
Addition |
|
|
Subtraction |
|
|
Multiplication |
|
|
Division |
|
|
Modulo (remainder) |
|
|
Exponentiation |
|
|
String concatenation |
Comparison Operators
Operator |
Description |
|---|---|
|
Equal to |
|
Not equal to |
|
Greater than |
|
Less than |
|
Greater than or equal to |
|
Less than or equal to |
Logical Operators
Operator |
Description |
|---|---|
|
Logical AND |
|
Logical OR |
|
Logical NOT |
Precedence
Operators follow this precedence order (highest to lowest):
Parentheses
()Exponentiation
soarUnary plus/minus
+,-Multiplication, Division, Modulo
moo,drone,squeakAddition, Subtraction
meow,woofComparison operators
>,<,>=,<=,==,!=Logical operators
and,orAssignment
->
Parentheses can be used to override the default precedence:
:: Default precedence: multiplication before addition
result -> 2 meow 3 moo 4 :: 2 + (3 * 4) = 14
:: Override with parentheses
result -> (2 meow 3) moo 4 :: (2 + 3) * 4 = 20
Reserved Keywords
The following are reserved keywords in Animal and cannot be used as variable names:
:: Control flow
growl, sniff, wag, pounce, leap
:: Functions/structures
howl, nest
:: Input/output
roar, listen
:: Return
sniffback
:: File operations
fetch, drop, drop_append, sniff_file, fetch_json, fetch_csv
:: Control
whimper, hiss
:: Other
mimic, _
Identifiers that match these keywords cannot be used as variable or function names.
Comments
Comments in Animal start with
::and continue to the end of the line: