diff options
Diffstat (limited to 'asm/asmlex.mll')
-rw-r--r-- | asm/asmlex.mll | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/asm/asmlex.mll b/asm/asmlex.mll index fc77c93..b2c7718 100644 --- a/asm/asmlex.mll +++ b/asm/asmlex.mll @@ -54,8 +54,8 @@ let valh d = let c = Char.code d 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') + else if c >= Char.code 'a' && c <= Char.code 'f' then c - (Char.code 'a') + 10 + else c - (Char.code 'A') + 10 let read_16 n = let res = ref 0 in @@ -94,9 +94,13 @@ rule token = parse with Not_found -> ID id } | "0x" (((hexdigit)+) as n) { INT (read_16 n) } + | "'\\n'" { INT (Char.code '\n') } + | "'\\t'" { INT (Char.code '\t') } + | "'\\r'" { INT (Char.code '\r') } + | "'" (_ as c) "'" { INT (Char.code c) } | (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) } + | ['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 } @@ -127,3 +131,4 @@ and comment = parse | eof { EOF } | '\n' { Lexing.new_line lexbuf; token lexbuf } | _ { comment lexbuf } + |