Interpreter
Parse and evaluate astromantic runic syntax utilizing the Interpreter pattern in Julia.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Interpreter
ARCANUM SCHOOL: Divination // Linguistics
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// JULIA PATTERN //
# Interpreter in Julia: Parsing Astromancy Runes
abstract type RuneExpression end
struct StarDustRune <: RuneExpression
amount::Float64
end
interpret(r::StarDustRune, context::Dict) = r.amount
struct CombineRune <: RuneExpression
left::RuneExpression
right::RuneExpression
end
interpret(r::CombineRune, context::Dict) = interpret(r.left, context) + interpret(r.right, context)
struct MultiplyRune <: RuneExpression
left::RuneExpression
right::RuneExpression
end
interpret(r::MultiplyRune, context::Dict) = interpret(r.left, context) * interpret(r.right, context)
# Usage
# Evaluating: (2.0 + 3.0) * 4.0 in runic form
dust1 = StarDustRune(2.0)
dust2 = StarDustRune(3.0)
dust3 = StarDustRune(4.0)
combo = CombineRune(dust1, dust2)
spell = MultiplyRune(combo, dust3)
result = interpret(spell, Dict())
println("Spell yields cosmic power of: ", result)
Runic Tags:
#behavioral
#interpreter
#julia
#astromancy