From 122c244abc34fa3a7d7684372135deb31ad02225 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Thu, 22 Dec 2022 16:44:00 +0100 Subject: [PATCH] remove J instr --- compiler.ml | 2 +- lexer.mll | 2 +- mips.ml | 2 -- parser.mly | 7 ++++++- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/compiler.ml b/compiler.ml index df237fd..e13063e 100644 --- a/compiler.ml +++ b/compiler.ml @@ -68,7 +68,7 @@ let rec compile_instr info = function @ compile_expr info.env e @ [ Beqz (V0, "endwhile" ^ uniq) ] @ cb.asm - @ [ J ("while" ^ uniq) ] + @ [ B ("while" ^ uniq) ] @ [ Label ("endwhile" ^ uniq) ] ; cnt = cb.cnt } diff --git a/lexer.mll b/lexer.mll index af4915d..83d6aba 100644 --- a/lexer.mll +++ b/lexer.mll @@ -5,7 +5,7 @@ } let alpha = ['a'-'z' 'A'-'Z'] -let num = '-'? ['0'-'9'] +let num = ['0'-'9'] let bool = "true" | "false" let ident = alpha (alpha | num | '-' | '_')* diff --git a/mips.ml b/mips.ml index c1d8c5e..7b9f14d 100644 --- a/mips.ml +++ b/mips.ml @@ -58,7 +58,6 @@ type instr = | Beq of reg * reg * label | Beqz of reg * label | Jal of label - | J of label | Jr of reg type directive = Asciiz of string @@ -150,7 +149,6 @@ let fmt_instr ?(indent = " ") = function Printf.sprintf "%sbeq %s, %s, %s" indent (fmt_reg rs) (fmt_reg rt) l | Beqz (r, l) -> Printf.sprintf "%sbeqz %s, %s" indent (fmt_reg r) l | Jal l -> Printf.sprintf "%sjal %s" indent l - | J l -> Printf.sprintf "%sj %s" indent l | Jr r -> Printf.sprintf "%sjr %s" indent (fmt_reg r) ;; diff --git a/parser.mly b/parser.mly index 95faf63..8cc6858 100644 --- a/parser.mly +++ b/parser.mly @@ -14,7 +14,7 @@ %token Ladd Lsub Lmul Ldiv Lseq Lsge Lsgt Lsle Lslt Lsne %token Lif Lelse Lwhile -%left Ladd Lsub Lmul Ldiv Lbigger Lseq Lsge Lsgt Lsle Lslt Lsne +%left Ladd Lsub Lmul Ldiv Lseq Lsge Lsgt Lsle Lslt Lsne %left Lbracedeb Lparfin Lbracefin Lreturn %left Ltype Lbool Lint Lvar Lstr @@ -131,6 +131,11 @@ instr: } expr: + /* -int */ + | Lsub ; n = Lint { + Val { value = Int (-n) ; pos = $startpos(n) } + } + /* int */ | n = Lint { Val { value = Int (n) ; pos = $startpos(n) }