⚔️ RPG WARD DIFFICULTY: Archmage Behavioral

Interpreter: The Arcane Lexicon

Given a language, define a representation for its grammar along with an interpreter.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Interpreter
ARCANUM SCHOOL: Divination // Comprehension
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// RPG PATTERN //
**FREE
Ctl-Opt NoMain;

// A simplistic grammar parser rune
Dcl-Proc InterpretCommand Export;
  Dcl-Pi *N Ind;
    Expression Char(50) Const;
  End-Pi;

  Dcl-S Op Char(10);
  Dcl-S Arg Char(40);

  Op = %Subst(Expression: 1: %Scan(' ': Expression)-1);
  Arg = %Subst(Expression: %Scan(' ': Expression)+1);

  Select;
    When Op = 'CAST';
      Return CastSpell(Arg);
    When Op = 'BIND';
      Return BindWard(Arg);
    Other;
      Return *Off;
  EndSl;
End-Proc;

Interpreter

RPG is a language of fixed forms and business logic, but sometimes users need a tiny Domain Specific Language (DSL). The Interpreter parses these text strings and maps them directly into subsystem calls, translating user intent into mainframe action.

Runic Tags: #behavioral #ibm-i #runes #interpreter