Skip to content

Commit

Permalink
Implement multiplication
Browse files Browse the repository at this point in the history
  • Loading branch information
DQNEO committed Aug 29, 2019
1 parent 5347518 commit 3f9f629
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ func tokenize() []*Token {

tokens = append(tokens, token)
fmt.Printf(" '%s'", token.value)
case ';', '+', '-':
case ';', '+', '-', '*':
token := &Token{
kind: "punct",
kind: "punct",
value: string([]byte{char}),
}
tokens = append(tokens, token)
Expand Down Expand Up @@ -139,7 +139,7 @@ func parse() *Expr {
}

switch token.value {
case "+", "-":
case "+", "-", "*":
left := expr
right := parseUnaryExpr()
return &Expr{
Expand Down Expand Up @@ -176,6 +176,8 @@ func generateExpr(expr *Expr) {
fmt.Printf(" addq %%rcx, %%rax\n")
case "-":
fmt.Printf(" subq %%rcx, %%rax\n")
case "*":
fmt.Printf(" imulq %%rcx, %%rax\n")
default:
panic("generator: Unknown binary operator:" + expr.operator)
}
Expand Down

0 comments on commit 3f9f629

Please sign in to comment.