Skip to content

Commit

Permalink
Refactor instruction parsing.
Browse files Browse the repository at this point in the history
  • Loading branch information
aleury committed Jan 20, 2024
1 parent 1d33e0a commit 38319aa
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
7 changes: 0 additions & 7 deletions ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
14 changes: 6 additions & 8 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand All @@ -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
Expand Down

0 comments on commit 38319aa

Please sign in to comment.