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_static offset class_name=
|
||||
let push_static offset class_name =
|
||||
[ addr (class_name ^ ":" ^ offset); "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:
|
||||
| e = expr; EOF { e }
|
||||
| e = expr; EOF { e }
|
||||
;
|
||||
|
||||
expr:
|
||||
| c = COMMENT { Comment c }
|
||||
| e = arithmetic { e }
|
||||
| POP; p = pop { p }
|
||||
| PUSH; p = push { p }
|
||||
| b = branching { b }
|
||||
| FUNCTION; f = function_definition { f }
|
||||
| CALL; c = function_call { c }
|
||||
| RETURN { Return }
|
||||
| e = expr; COMMENT { e }
|
||||
| c = COMMENT { Comment c }
|
||||
| e = expr; COMMENT { e }
|
||||
| e = arithmetic { e }
|
||||
| e = memoryaccess { e }
|
||||
| e = programflow { e }
|
||||
| e = functioncall { e }
|
||||
;
|
||||
|
||||
arithmetic:
|
||||
@ -57,6 +54,11 @@ arithmetic:
|
||||
| NOT { ArithmeticCommand Not }
|
||||
;
|
||||
|
||||
memoryaccess:
|
||||
| POP; e = pop { e }
|
||||
| PUSH; e = push { e }
|
||||
;
|
||||
|
||||
pop:
|
||||
| ARGUMENT; a = ADDRESS { MemoryAccessCommand (Pop, Argument, a) }
|
||||
| LOCAL; a = ADDRESS { MemoryAccessCommand (Pop, Local, a) }
|
||||
@ -78,16 +80,14 @@ push:
|
||||
| CONSTANT; a = ADDRESS { MemoryAccessCommand (Push, Constant, a) }
|
||||
;
|
||||
|
||||
branching:
|
||||
programflow:
|
||||
| LABEL; i = ID { ProgramFlowCommand (Label, i) }
|
||||
| GOTO; i = ID { ProgramFlowCommand (Goto, i) }
|
||||
| IFGOTO; i = ID { ProgramFlowCommand (Ifgoto, i) }
|
||||
;
|
||||
|
||||
function_definition:
|
||||
| i = ID; a = ADDRESS { FunctionCallCommand (Function, i, a) }
|
||||
;
|
||||
|
||||
function_call:
|
||||
| i = ID; a = ADDRESS { FunctionCallCommand (Call, i, a) }
|
||||
functioncall:
|
||||
| FUNCTION; i = ID; a = ADDRESS { FunctionCallCommand (Function, i, a) }
|
||||
| CALL; i = ID; a = ADDRESS { FunctionCallCommand (Call, i, a) }
|
||||
| RETURN { Return }
|
||||
;
|
Loading…
Reference in New Issue
Block a user