minor fixes to lib
This commit is contained in:
parent
b7dee58454
commit
c506fdd966
@ -22,7 +22,7 @@ let push_constant a = [ addr a; "D=A" ] @ push
|
|||||||
|
|
||||||
let push_pointer a = [ pointer a; "D=M" ] @ push
|
let push_pointer a = [ pointer a; "D=M" ] @ push
|
||||||
|
|
||||||
let push_static offset class_name=
|
let push_static offset class_name =
|
||||||
[ addr (class_name ^ ":" ^ offset); "D=M" ] @ push
|
[ addr (class_name ^ ":" ^ offset); "D=M" ] @ push
|
||||||
|
|
||||||
let push_temp a = [ addr a; "D=A"; "@5"; "A=D+A"; "D=M" ] @ push
|
let push_temp a = [ addr a; "D=A"; "@5"; "A=D+A"; "D=M" ] @ push
|
||||||
|
@ -30,19 +30,16 @@ open Ast
|
|||||||
|
|
||||||
|
|
||||||
prog:
|
prog:
|
||||||
| e = expr; EOF { e }
|
| e = expr; EOF { e }
|
||||||
;
|
;
|
||||||
|
|
||||||
expr:
|
expr:
|
||||||
| c = COMMENT { Comment c }
|
| c = COMMENT { Comment c }
|
||||||
| e = arithmetic { e }
|
| e = expr; COMMENT { e }
|
||||||
| POP; p = pop { p }
|
| e = arithmetic { e }
|
||||||
| PUSH; p = push { p }
|
| e = memoryaccess { e }
|
||||||
| b = branching { b }
|
| e = programflow { e }
|
||||||
| FUNCTION; f = function_definition { f }
|
| e = functioncall { e }
|
||||||
| CALL; c = function_call { c }
|
|
||||||
| RETURN { Return }
|
|
||||||
| e = expr; COMMENT { e }
|
|
||||||
;
|
;
|
||||||
|
|
||||||
arithmetic:
|
arithmetic:
|
||||||
@ -57,6 +54,11 @@ arithmetic:
|
|||||||
| NOT { ArithmeticCommand Not }
|
| NOT { ArithmeticCommand Not }
|
||||||
;
|
;
|
||||||
|
|
||||||
|
memoryaccess:
|
||||||
|
| POP; e = pop { e }
|
||||||
|
| PUSH; e = push { e }
|
||||||
|
;
|
||||||
|
|
||||||
pop:
|
pop:
|
||||||
| ARGUMENT; a = ADDRESS { MemoryAccessCommand (Pop, Argument, a) }
|
| ARGUMENT; a = ADDRESS { MemoryAccessCommand (Pop, Argument, a) }
|
||||||
| LOCAL; a = ADDRESS { MemoryAccessCommand (Pop, Local, a) }
|
| LOCAL; a = ADDRESS { MemoryAccessCommand (Pop, Local, a) }
|
||||||
@ -78,16 +80,14 @@ push:
|
|||||||
| CONSTANT; a = ADDRESS { MemoryAccessCommand (Push, Constant, a) }
|
| CONSTANT; a = ADDRESS { MemoryAccessCommand (Push, Constant, a) }
|
||||||
;
|
;
|
||||||
|
|
||||||
branching:
|
programflow:
|
||||||
| LABEL; i = ID { ProgramFlowCommand (Label, i) }
|
| LABEL; i = ID { ProgramFlowCommand (Label, i) }
|
||||||
| GOTO; i = ID { ProgramFlowCommand (Goto, i) }
|
| GOTO; i = ID { ProgramFlowCommand (Goto, i) }
|
||||||
| IFGOTO; i = ID { ProgramFlowCommand (Ifgoto, i) }
|
| IFGOTO; i = ID { ProgramFlowCommand (Ifgoto, i) }
|
||||||
;
|
;
|
||||||
|
|
||||||
function_definition:
|
functioncall:
|
||||||
| i = ID; a = ADDRESS { FunctionCallCommand (Function, i, a) }
|
| FUNCTION; i = ID; a = ADDRESS { FunctionCallCommand (Function, i, a) }
|
||||||
|
| CALL; i = ID; a = ADDRESS { FunctionCallCommand (Call, i, a) }
|
||||||
|
| RETURN { Return }
|
||||||
;
|
;
|
||||||
|
|
||||||
function_call:
|
|
||||||
| i = ID; a = ADDRESS { FunctionCallCommand (Call, i, a) }
|
|
||||||
;
|
|
Loading…
Reference in New Issue
Block a user