minor fixes to lib

This commit is contained in:
Konarak 2024-09-14 21:15:51 -04:00
parent b7dee58454
commit c506fdd966
Signed by: konarak
GPG Key ID: DE5E99432B548849
2 changed files with 18 additions and 18 deletions

View File

@ -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

View File

@ -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) }
functioncall:
| 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) }
;