mirror of
https://github.com/notwa/lips
synced 2024-05-18 16:33:22 -07:00
handle parenthesis after lexing instead
This commit is contained in:
parent
659bec36f8
commit
c0c4d81b5a
|
@ -318,18 +318,14 @@ function Lexer:lex(_yield)
|
||||||
end
|
end
|
||||||
self:nextc()
|
self:nextc()
|
||||||
yield('DEF', buff)
|
yield('DEF', buff)
|
||||||
|
elseif self.chr == ']' then
|
||||||
|
self:error('unmatched closing bracket')
|
||||||
elseif self.chr == '(' then
|
elseif self.chr == '(' then
|
||||||
self:nextc()
|
self:nextc()
|
||||||
local buff = self:read_chars('[%w_]')
|
yield('OPEN', '(')
|
||||||
if self.chr ~= ')' then
|
elseif self.chr == ')' then
|
||||||
self:error('invalid register name')
|
|
||||||
end
|
|
||||||
self:nextc()
|
self:nextc()
|
||||||
local up = buff:upper()
|
yield('CLOSE', ')')
|
||||||
if not data.all_registers[up] then
|
|
||||||
self:error('not a register')
|
|
||||||
end
|
|
||||||
yield('DEREF', up)
|
|
||||||
elseif self.chr == '.' then
|
elseif self.chr == '.' then
|
||||||
self:nextc()
|
self:nextc()
|
||||||
local buff = self:read_chars('[%w]')
|
local buff = self:read_chars('[%w]')
|
||||||
|
@ -373,10 +369,6 @@ function Lexer:lex(_yield)
|
||||||
end
|
end
|
||||||
yield('LABELSYM', buff)
|
yield('LABELSYM', buff)
|
||||||
end
|
end
|
||||||
elseif self.chr == ']' then
|
|
||||||
self:error('unmatched closing bracket')
|
|
||||||
elseif self.chr == ')' then
|
|
||||||
self:error('unmatched closing parenthesis')
|
|
||||||
elseif self.chr == '+' or self.chr == '-' then
|
elseif self.chr == '+' or self.chr == '-' then
|
||||||
local sign_chr = self.chr
|
local sign_chr = self.chr
|
||||||
local sign = sign_chr == '+' and 1 or -1
|
local sign = sign_chr == '+' and 1 or -1
|
||||||
|
|
|
@ -68,11 +68,19 @@ function Muncher:register(t)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Muncher:deref()
|
function Muncher:deref()
|
||||||
if self.tt ~= 'DEREF' then
|
if self.tt ~= 'OPEN' then
|
||||||
|
self:error('expected opening parenthesis for dereferencing')
|
||||||
|
end
|
||||||
|
self:advance()
|
||||||
|
if self.tt ~= 'REG' then
|
||||||
self:error('expected register to dereference')
|
self:error('expected register to dereference')
|
||||||
end
|
end
|
||||||
local reg = self.tok
|
local reg = self.tok
|
||||||
self:advance()
|
self:advance()
|
||||||
|
if self.tt ~= 'CLOSE' then
|
||||||
|
self:error('expected closing parenthesis for dereferencing')
|
||||||
|
end
|
||||||
|
self:advance()
|
||||||
return reg
|
return reg
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -182,7 +182,7 @@ function Parser:instruction()
|
||||||
local args = {}
|
local args = {}
|
||||||
args.rt = self:register()
|
args.rt = self:register()
|
||||||
self:optional_comma()
|
self:optional_comma()
|
||||||
if self.tt == 'DEREF' then
|
if self.tt == 'OPEN' then
|
||||||
args.offset = {'NUM', 0}
|
args.offset = {'NUM', 0}
|
||||||
args.base = self:deref()
|
args.base = self:deref()
|
||||||
else -- NUM or LABELSYM
|
else -- NUM or LABELSYM
|
||||||
|
|
Loading…
Reference in New Issue
Block a user