diff --git a/TODO b/TODO index c3159dc..7a8ffe1 100644 --- a/TODO +++ b/TODO @@ -1,6 +1,8 @@ unify/optimize ascii/asciiz/byte/halfword/word into BIN directives also lex strings to binary strings, why not +lex expressions in Lexer instead of its own separate lexer + directive aliases, are these right? DB = 'BYTE', DH = 'HALFWORD', diff --git a/lips/Expression.lua b/lips/Expression.lua index 022c765..0d1950a 100644 --- a/lips/Expression.lua +++ b/lips/Expression.lua @@ -144,21 +144,38 @@ function Expression:lex1(str, tokens) local here = " (#"..tostring(pos)..")" if consider(' +') then consume(#considered) - elseif consider('[0-9.]') then + elseif consider('[0-9.]') or consider('[%%$#]') then local num if consider('((0|[1-9][0-9]*)%.[0-9]*|%.[0-9]+)(e0|e[1-9][0-9]*)?') then num = tonumber(considered) elseif consider('(0|[1-9][0-9]*)e(0|[1-9][0-9]*)') then num = tonumber(considered) - elseif consider('[0-1]+b') then - num = tonumber(considered, 2) + elseif consider('%%[0-9]+') then + if considered:match('[2-9]') then + return "bad binary number: "..considered..here + end + num = tonumber(considered:sub(2), 2) + elseif consider('$[0-9A-Fa-f]+') then + num = tonumber(considered:sub(2), 16) elseif consider('0x[0-9A-Fa-f]+') then - num = tonumber(considered, 16) + num = tonumber(considered:sub(3), 16) + elseif consider('0o[0-9]+') then + if considered:match('[89]') then + return "bad octal number: "..considered..here + end + num = tonumber(considered:sub(3), 8) + elseif consider('0b[0-9]+') then + if considered:match('[2-9]') then + return "bad binary number: "..considered..here + end + num = tonumber(considered:sub(3), 2) elseif consider('0[0-9]+') then if considered:match('[89]') then return "bad octal number: "..considered..here end - num = tonumber(considered, 8) + num = tonumber(considered:sub(2), 8) + elseif consider('#[0-9]*') then + num = tonumber(considered:sub(2)) elseif consider('[0-9]*') then num = tonumber(considered) end