From 38319aaf671b56c639cc244b8ebaa549abbab86b Mon Sep 17 00:00:00 2001 From: Adam Eury Date: Sat, 20 Jan 2024 13:50:40 -0500 Subject: [PATCH] Refactor instruction parsing. --- ast/ast.go | 7 ------- parser/parser.go | 14 ++++++-------- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/ast/ast.go b/ast/ast.go index 392cd71..b9dd226 100644 --- a/ast/ast.go +++ b/ast/ast.go @@ -99,10 +99,3 @@ type StringLiteral struct { func (sl StringLiteral) expressionNode() {} func (sl StringLiteral) TokenLiteral() string { return sl.Token.Literal } - -type Any struct { - Token token.Token -} - -func (e Any) expressionNode() {} -func (e Any) TokenLiteral() string { return e.Token.Literal } diff --git a/parser/parser.go b/parser/parser.go index a0fbf15..7322ebf 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -148,7 +148,7 @@ func (p *Parser) expectOneOf(tokTypes ...token.TokenType) ast.Expression { case token.IDENT: return ast.Identifier{Token: p.curToken} default: - return ast.Any{Token: p.curToken} + return nil } } @@ -157,15 +157,13 @@ func (p *Parser) parseInstructionStatement() ast.Statement { if stmt.TokenLiteral() == "MOVE" { stmt.Operand1 = p.expectOneOf(token.REGISTER, token.IDENT) - p.expectOneOf(token.ARROW) - stmt.Operand2 = p.expectOneOf(token.REGISTER, token.IDENT) - } else { - if exprParser, ok := p.exprParsers[p.peekToken.Type]; ok { - p.nextToken() - stmt.Operand1 = exprParser() - } + } + + if exprParser, ok := p.exprParsers[p.peekToken.Type]; ok { + p.nextToken() + stmt.Operand1 = exprParser() } return stmt