====== The Elements of Computing Systems, 2ed ======
%import common.WS
%import common.CPP_COMMENT
%import common.INT
%import common.WORD
%ignore WS
%ignore CPP_COMMENT
start: (LABEL | ainstr | cinstr)*
LABEL: "(" WORD ")"
ainstr: "@" SYMBOL
SYMBOL: WORD
| INT
| "R" "0".."15"
| "SP"
| "LCL"
| "ARG"
| "THIS"
| "THAT"
| "KBD"
| "SCREEN"
cinstr: (DEST "=")? COMP (";" JUMP)?
// not satisfied with this; could it be cleaner?
DEST: "A" "D"? "M"?
| "A"? "D" "M"?
| "A"? "D"? "M"
JUMP: "JGT"
| "JEQ"
| "JGE"
| "JLT"
| "JNE"
| "JLE"
| "JMP"
%import common.WS
%import common.CPP_COMMENT
%import common.INT
%import common.SIGNED_INT
%ignore WS
%ignore CPP_COMMENT
start: (stackop | arithop)*
stackop: (PUSH|POP) SEGMENT INDEX
PUSH: "push"
POP: "pop"
arithop: ADD
| SUB
| NEG
| EQ
| GT
| LT
| AND
| OR
| NOT
ADD: "add"
SUB: "sub"
NEG: "neg"
EQ: "eq"
GT: "gt"
LT: "lt"
AND: "and"
OR: "or"
NOT: "not"
SEGMENT: "argument"
| "local"
| "static"
| "constant"
| "this"
| "that"
| "pointer"
| "temp"
INDEX: INT
{{tag>compsci electronics programming}}