An algebra is the indirection at the heart of the parser zoo: a grammar builder takes an algebra alg and its actions call
alg["Binary"][op,l,r]
,
alg["Leaf"][kind,src]
, and so on, never naming a node head directly. Feed the grammar
ASTAlgebra
and it builds a standard tree; feed it the language's own semantic algebra and the same grammar yields a meaningful value. The grammar is untouched; only the algebra is swapped.
▪
The keys are the node constructors:
"Leaf"
,
"Prefix"
,
"Postfix"
,
"Binary"
,
"Infix"
,
"Ternary"
,
"Call"
,
"Group"
,
"Container"
. Each maps to a function that returns the matching node with empty
metadata.
▪
The standard nodes mirror Wolfram's own
CodeParser
shape - a 3-slot
Head[descriptor,children,meta]
triple - but operator descriptors stay language-native strings (