1
0
Fork 0
mirror of https://github.com/notwa/lips synced 2024-11-14 10:09:03 -08:00

handle parenthesis after lexing instead

This commit is contained in:
Connor Olding 2016-01-15 07:49:43 -08:00
parent 659bec36f8
commit c0c4d81b5a
3 changed files with 15 additions and 15 deletions

View file

@ -318,18 +318,14 @@ function Lexer:lex(_yield)
end
self:nextc()
yield('DEF', buff)
elseif self.chr == ']' then
self:error('unmatched closing bracket')
elseif self.chr == '(' then
self:nextc()
local buff = self:read_chars('[%w_]')
if self.chr ~= ')' then
self:error('invalid register name')
end
yield('OPEN', '(')
elseif self.chr == ')' then
self:nextc()
local up = buff:upper()
if not data.all_registers[up] then
self:error('not a register')
end
yield('DEREF', up)
yield('CLOSE', ')')
elseif self.chr == '.' then
self:nextc()
local buff = self:read_chars('[%w]')
@ -373,10 +369,6 @@ function Lexer:lex(_yield)
end
yield('LABELSYM', buff)
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
local sign_chr = self.chr
local sign = sign_chr == '+' and 1 or -1

View file

@ -68,11 +68,19 @@ function Muncher:register(t)
end
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')
end
local reg = self.tok
self:advance()
if self.tt ~= 'CLOSE' then
self:error('expected closing parenthesis for dereferencing')
end
self:advance()
return reg
end

View file

@ -182,7 +182,7 @@ function Parser:instruction()
local args = {}
args.rt = self:register()
self:optional_comma()
if self.tt == 'DEREF' then
if self.tt == 'OPEN' then
args.offset = {'NUM', 0}
args.base = self:deref()
else -- NUM or LABELSYM