Skip to content

Commit

Permalink
fix(lexer): adds readChar() functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
lukepeterson committed Sep 17, 2024
1 parent b3766bb commit 55d9126
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package main

// import "github.com/lukepeterson/go8080assembler/assembler"
import (
"fmt"

// import "github.com/lukepeterson/go8080assembler/assembler"
"github.com/lukepeterson/go8080assembler/pkg/lexer"
)

Expand Down Expand Up @@ -32,7 +32,7 @@ func main() {
LDA, 1234h ; The second comment
JMP TEST
; The Third comment with a colon ; here
; The third comment with another colon ; here
`

myLexer := lexer.New(input)
Expand Down
26 changes: 21 additions & 5 deletions pkg/lexer/lexer.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package lexer

import "fmt"

type TokenType string

const (
Expand All @@ -23,12 +25,26 @@ type Token struct {
}

type Lexer struct {
input string
// position int
input string
position int
readPosition int
currentChar byte
}

func New(input string) *Lexer {
lexer := &Lexer{input: input}
// lexer.readChar()
return lexer
l := &Lexer{input: input}
l.readChar()
return l
}

func (l *Lexer) readChar() {
if l.readPosition >= len(l.input) {
l.currentChar = 0
} else {
l.currentChar = l.input[l.readPosition]
}
l.position = l.readPosition
l.readPosition++

fmt.Printf("l.readPosition: %v\n", l.readPosition)
}

0 comments on commit 55d9126

Please sign in to comment.