✨ ARCANUM RUNE DIFFICULTY: Archmage Behavioral

The Interpreter's Lexicon

Defining a grammar for a language and parsing its syntax.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Interpreter
ARCANUM SCHOOL: Evocation // Linguistics
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
# Defining an Abstract Syntax Tree (AST) within the Schema
union Expression = Literal | Variable | Operation

type Literal {
  value: Int!
}

type Variable {
  name: String!
}

type Operation {
  operator: OperatorEnum!
  left: Expression!
  right: Expression!
}

enum OperatorEnum {
  ADD
  SUBTRACT
  MULTIPLY
}

type Query {
  # The Oracle interprets the nested expression structure
  evaluate(expression: Expression!): Int!
}

While GraphQL itself is an interpreter of its query language, we can also model the Interpreter pattern within the schema using Unions and recursive types. This allows the client to send abstract syntax trees (ASTs) of custom magical languages for the Oracle to evaluate and execute.

Runic Tags: #graphql #behavioral #interpreter #ast #unions