Cicada Scripting Language

A minimal interpreted language that talks to C



Cicada download site     HTML docs     PDF docs    


Code examples


Primitive variables
x :: int, x = 5
d :: double, c :: char, b :: bool
x2 := 5.7             | will be double
(str :: string) = input()
str =! d, c =! b      | byte-wise copy

Arrays
A :: [3] double, A[] = 1
remove A[2], A[+3] = 4, A[^5]
A[<3, top>] = A[1]
print(str[<1, 3>], "...")

Structure variables
v :: { (d::double)=3.14, bool, char, string, "const" }
v2 :: v
print(v.d == v2[1])   | 'true'

Sets
s :: { x, x2, { v, 5 } }
sprint(s)

Functions
f1 :: {
  toAdd := 2
  code
  return args[1] + toAdd
}
print(f1(4))
f2 :: { toAdd := 2; return args[1] + toAdd }   | same as f1

Classes
C :: {
  data :: { int, int, string, char }
  fetchData :: { ; return data }
  code, data = args          | one way to write a constructor
}
Cvar :: C, Cvar(2,4,"",'c')

Inheritance
Cvar2 :: C : { data2 :: string }
f3 :: f1 : f2
s2 :: s : { int }   | set concatenation

Flow control
if x == x2 then print("eq")
else if x < x2 then ( print("lt"), x2 = x )
else ( ... )
for x in <1, x2> print(x)
while x < x2 do x = that + 1
exit

Cicada-specific
al1 := @Cvar, sprint(al1.data), al1 =@ *   | alias (no pointers in Cicada!)
al2 :: *, al2 =@ f1, al2 =@ C, al2 =@ s2   | universal alias
v3 :: { toAdd := 2.5 }, (v3 << f1)(4)      | code substitution
f4 :: {
  params :: { mult::int; mult=2 }          | function with optional parameters
  code
  params(), (params<<args)()
  return params.mult*args[1]
}
print(f4(2)), print(f4(2; mult = 3))
remove f4.params, f4#0()                   | rerun f4's 'constructor'

Run C from Cicada
userFunction UserFunctions[] = { ..., { "myF", &C_fn } };   // in userfn.c

int C_fn(int argc, char **argv) {
  int n1, n2, n3;
  getArgs(argc, argv, &n1, &n2, &n3);
  ...
}

rtrn := $myF(5, 7, 2)   | in Cicada

Run Cicada from C
#include "ccmain.h"
...
const char *fName = "myscript"
runCicada(0, NULL);     | run start.cicada (interactive prompt)
runCicada(1, &fName);   | run myscript.cicada


Cicada is free to use and distribute, under the terms of the MIT License.

Last update: September 28, 2025