mirror of
https://github.com/notwa/lips
synced 2024-05-02 01:33:22 -07:00
lex the same number syntax in expressions
This commit is contained in:
parent
9f6252117e
commit
63644df1bc
2
TODO
2
TODO
|
@ -1,6 +1,8 @@
|
||||||
unify/optimize ascii/asciiz/byte/halfword/word into BIN directives
|
unify/optimize ascii/asciiz/byte/halfword/word into BIN directives
|
||||||
also lex strings to binary strings, why not
|
also lex strings to binary strings, why not
|
||||||
|
|
||||||
|
lex expressions in Lexer instead of its own separate lexer
|
||||||
|
|
||||||
directive aliases, are these right?
|
directive aliases, are these right?
|
||||||
DB = 'BYTE',
|
DB = 'BYTE',
|
||||||
DH = 'HALFWORD',
|
DH = 'HALFWORD',
|
||||||
|
|
|
@ -144,21 +144,38 @@ function Expression:lex1(str, tokens)
|
||||||
local here = " (#"..tostring(pos)..")"
|
local here = " (#"..tostring(pos)..")"
|
||||||
if consider(' +') then
|
if consider(' +') then
|
||||||
consume(#considered)
|
consume(#considered)
|
||||||
elseif consider('[0-9.]') then
|
elseif consider('[0-9.]') or consider('[%%$#]') then
|
||||||
local num
|
local num
|
||||||
if consider('((0|[1-9][0-9]*)%.[0-9]*|%.[0-9]+)(e0|e[1-9][0-9]*)?') then
|
if consider('((0|[1-9][0-9]*)%.[0-9]*|%.[0-9]+)(e0|e[1-9][0-9]*)?') then
|
||||||
num = tonumber(considered)
|
num = tonumber(considered)
|
||||||
elseif consider('(0|[1-9][0-9]*)e(0|[1-9][0-9]*)') then
|
elseif consider('(0|[1-9][0-9]*)e(0|[1-9][0-9]*)') then
|
||||||
num = tonumber(considered)
|
num = tonumber(considered)
|
||||||
elseif consider('[0-1]+b') then
|
elseif consider('%%[0-9]+') then
|
||||||
num = tonumber(considered, 2)
|
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
|
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
|
elseif consider('0[0-9]+') then
|
||||||
if considered:match('[89]') then
|
if considered:match('[89]') then
|
||||||
return "bad octal number: "..considered..here
|
return "bad octal number: "..considered..here
|
||||||
end
|
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
|
elseif consider('[0-9]*') then
|
||||||
num = tonumber(considered)
|
num = tonumber(considered)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user