我为 APL 子集制作了一个语法。
grammar APL;
program: (statement NEWLINE)*;
statement: thing;
assignment: variable LARR thing;
thing: simpleThing
| complexThing;
escapedThing: simpleThing
| '(' complexThing ')';
simpleThing: variable # ThingVariable
| number # ThingNumber
;
complexThing: unary # ThingUOp
| binary # ThingBOp
| assignment # ThingAssignment
;
variable: CAPITAL;
number: DIGITS;
unary: iota # UOpIota
| negate # UOpNegate
;
iota: SMALL_IOTA number;
negate: TILDA thing;
binary: drop # BOpDrop
| select # BOpSelect
| outerProduct # BOpOuterProduct
| setInclusion # BOpSetInclusion
;
drop: left=number SPIKE right=thing;
select: left=escapedThing SLASH right=thing;
outerProduct: left=escapedThing OUTER_PRODUCT_OP right=thing;
setInclusion: left=escapedThing '∊' right=thing;
NEWLINE: [\r\n]+;
CAPITAL: [A-Z];
CAPITALS: (CAPITAL)+;
DIGITS: [0-9]+;
TILDA: '~';
SLASH: '/';
// greek
SMALL_IOTA: 'ι' | '@i';
// arrows
LARR: '←' | '@<-';
SPIKE: '↓' | '@Iv';
OUTER_PRODUCT_OP: '∘.×' | '@o.@x';
现在我想为它创建一个解释器。我正在尝试将clj-antlr与 Clojure 一起使用。我怎么做?