Cicada Scripting Language

A lightweight scripting language for C programs



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
 }
 Cinstance :: C, Cinstance(2,4,"",'c')

Inheritance
 C_child :: 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
 a := @C, sprint(a.data), a =@ *            | alias (no pointers in Cicada!)
 a2 :: *, a2 = @f1, a2 = @C, a2 = @s        | 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 from C
 #include <cicada.h>
 
 ccInt myF(argsType args) { ... }
 const Cfunction callbackFs[] = { { "myF", &myF } };
 
 int main(int argc, char **argv)
 {
  runCicada(callbackFs, "$myF(1, 2, 3)", false);  // run a script
  runCicada(callbackFs, NULL, true);              // run interactively
  return 0;
 }


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

Last update: November 3, 2025