The Interpreter
Parsing a string of ancient characters to evaluate a logical truth.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Interpreter
ARCANUM SCHOOL: Divination // Glyph Parsing
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
NB. A simple interpreter for a custom arcane math language
NB. Language: 'A' means add, 'M' means multiply
interpret =: 3 : 0
tokens =. ;: y
ops =. ('A';'M') ,: ('+';'*')
translated =. (tokens i. {."1 ops) { {:"1 ops , tokens
". ; translated
)
NB. Usage: interpret '3 A 4 M 2'
Taking advantage of J’s sequential machine and ". (do) to interpret DSLs dynamically.
Runic Tags:
#interpreter
#evaluation
#strings
#parsing