Grammar as a Service — contract cgt-gaas/0.1

A request names a versioned grammar (or an algorithm with declared capabilities), an operation expression, and limits; the response carries values, a layered rejection if any (syntax · semantics · execution), a cost report and provenance hashes. The reference implementation is a pure function you can call in-process — no account, key or network is needed for anything in the curriculum. Design rationale:  the GaaS chapter.

Structures

NameVersionDescriptionMoves
array1dynamic arrayappend(x) delete(i) get(i) insert(i, x) len pop set(i, x)
linked_list1singly linked listdelete(i) get(i) insert(i, x) len pop_front push_front(x) set(i, x)
stack1array-backed stackempty pop push(x) top
queue1circular queuedequeue enqueue(x) front len
deque1circular dequelen pop_back pop_front push_back(x) push_front(x)
hash_table1open addressing, linear probingcontains(k) delete(k) get(k) len put(k, v)
heap1binary min-heaplen peek pop_min push(x)
trie1character triecontains(w) count_prefix(p) insert(w)
bst1BST / AVLcontains(k) delete(k) insert(k) min
binary_tree1complete binary tree, pointer or heap representationL R U goto(addr) here read root
graph1edge-labelled digraph, relational semanticsedge labels + at(v), here

Algorithms

NameExactnessDeclared costDescription
pagerankapproximate (certified bound)O(k·(n+m)), k ≤ log(tol)/log(α) iterationsPageRank by power iteration; approximate with certified L1 error bound
constrained_pagerankapproximate (certified bound)O(k·|Q|·(n+m))grammar-constrained random surfer (CGT proposal)
reachexactO(n+m), or O(|Q|(|Σ|n+m)) with a languagereachability, optionally language-constrained (THM-001)
ssspexactO((n+m) log n)Dijkstra single-source shortest paths
sccexactO(n+m)Tarjan strongly connected components

Hard limits

A request may lower any limit and never raise one.

Example

{
 "contract": "cgt-gaas/0.1",
 "grammar": {
  "structure": "array",
  "version": "1"
 },
 "init": {
  "values": [
   5,
   3,
   8
  ]
 },
 "expression": "get(2); set(0, 9); get(0)"
}
{
 "contract": "cgt-gaas/0.1",
 "status": "ok",
 "exact": true,
 "values": [
  8,
  null,
  9
 ],
 "cost": {
  "total": 9,
  "counts": {
   "arith": 3,
   "compare": 3,
   "read": 2,
   "write": 1
  }
 },
 "provenance": {
  "sdk": "0.1.0",
  "request_sha256": "43fea76542d15e22df05f6b1f750939b1b72d3f5444e1185e9049afec390e0c9",
  "result_sha256": "841664233f6c8d98809381bb52f967b1e22289a050a1be3c8a9d1826cced3f33",
  "deterministic": true
 }
}