-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(lexer): adds skeleton for lexical analyser
- Loading branch information
1 parent
bcc0aeb
commit b3766bb
Showing
2 changed files
with
66 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,41 @@ | ||
package main | ||
|
||
// import "github.com/lukepeterson/go8080assembler/assembler" | ||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/lukepeterson/go8080assembler/assembler" | ||
"github.com/lukepeterson/go8080assembler/pkg/lexer" | ||
) | ||
|
||
func main() { | ||
code := ` | ||
MVI A, 34h | ||
MOV B, C | ||
LDA, 1234h | ||
HLT | ||
` | ||
|
||
assembler := assembler.New() | ||
|
||
err := assembler.Assemble(code) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
for _, instruction := range assembler.ByteCode { | ||
fmt.Printf("%02X ", instruction) | ||
} | ||
// code := ` | ||
// MVI A, 34h | ||
// MOV B, C | ||
// LDA, 1234h | ||
// HLT | ||
// ` | ||
|
||
// assembler := assembler.New() | ||
|
||
// err := assembler.Assemble(code) | ||
// if err != nil { | ||
// log.Fatal(err) | ||
// } | ||
|
||
// for _, instruction := range assembler.ByteCode { | ||
// fmt.Printf("%02X ", instruction) | ||
// } | ||
|
||
input := ` | ||
MVI A, 0x33 | ||
TEST: MOV B, C ; The first comment | ||
LDA, 1234h ; The second comment | ||
JMP TEST | ||
; The Third comment with a colon ; here | ||
` | ||
|
||
myLexer := lexer.New(input) | ||
fmt.Printf("myLexer: %v\n", myLexer) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package lexer | ||
|
||
type TokenType string | ||
|
||
const ( | ||
COMMA TokenType = "COMMA" | ||
COLON TokenType = "COLON" | ||
|
||
IDENT TokenType = "IDENT" | ||
NUMBER TokenType = "NUMBER" | ||
REGISTER TokenType = "REGISTER" | ||
MNEMONIC TokenType = "MNEMONIC" | ||
|
||
COMMENT TokenType = "COMMENT" | ||
EOF TokenType = "EOF" | ||
|
||
UNKNOWN TokenType = "UNKNOWN" | ||
) | ||
|
||
type Token struct { | ||
Type TokenType | ||
Literal string | ||
} | ||
|
||
type Lexer struct { | ||
input string | ||
// position int | ||
} | ||
|
||
func New(input string) *Lexer { | ||
lexer := &Lexer{input: input} | ||
// lexer.readChar() | ||
return lexer | ||
} |