summaryrefslogtreecommitdiff
path: root/asm/asmlex.mll
diff options
context:
space:
mode:
Diffstat (limited to 'asm/asmlex.mll')
-rw-r--r--asm/asmlex.mll17
1 files changed, 14 insertions, 3 deletions
diff --git a/asm/asmlex.mll b/asm/asmlex.mll
index 2bd52fc..1c7e3e7 100644
--- a/asm/asmlex.mll
+++ b/asm/asmlex.mll
@@ -23,10 +23,12 @@
"liu",LIU;
"liuz",LIUZ;
"lra",LRA;
+ "la",LA;
"li",LI;
"move",MOVE;
"jz",JZ;
"jnz",JNZ;
+ "asciiz",ASCIIZ;
"_clock",INT 0x4000;
"_input",INT 0x4100;
"_output",INT 0x4102;
@@ -54,8 +56,8 @@
let v =
let c = Char.code n.[i] in
if c >= Char.code '0' && c <= Char.code '9' then c - (Char.code '0')
- else if c >= Char.code 'a' && c <= Char.code 'f' then c - (Char.code 'a')
- else c - (Char.code 'A') in
+ else if c >= Char.code 'a' && c <= Char.code 'f' then c - (Char.code 'a') + 10
+ else c - (Char.code 'A') + 10 in
res := !res + v
done;
!res
@@ -89,7 +91,8 @@ rule token = parse
{ INT (read_16 n) }
| (digit)+ as n { INT (int_of_string n) }
| "0b" (['0' '1']+ as n) { INT (read_2 n) }
- | ['A'-'Z']+ as name { REG (List.assoc name regs) }
+ | '"' { STR (lex_str "" lexbuf) }
+ | ['A'-'Z']+ as name { try REG (List.assoc name regs) with Not_found -> raise (Asm_error ("no reg " ^ name))}
| '$' (['0'-'7'] as n) { REG (Char.code n - (Char.code '0')) }
| ".text" { TEXT }
| ".data" { DATA }
@@ -101,3 +104,11 @@ and comment = parse
| eof { EOF }
| '\n' { Lexing.new_line lexbuf; token lexbuf }
| _ { comment lexbuf }
+
+and lex_str q = parse
+ | eof { q }
+ | '"' { q }
+ | "\\\"" { lex_str (q ^ "\"") lexbuf }
+ | "\\\\" { lex_str (q ^ "\\") lexbuf }
+ | "\\n" { lex_str (q ^ "\n") lexbuf }
+ | _ as c { lex_str (q ^ String.make 1 c) lexbuf }