From 30c2693812076286b0405424d71b7dfe759c2923 Mon Sep 17 00:00:00 2001 From: "aljazbrodar." Date: Tue, 30 Dec 2025 15:58:00 +0100 Subject: [PATCH] interface command impl. --- ass3/zbirnik/parsing/pregledovalnik.go | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/ass3/zbirnik/parsing/pregledovalnik.go b/ass3/zbirnik/parsing/pregledovalnik.go index 81b4253..22cb8dc 100644 --- a/ass3/zbirnik/parsing/pregledovalnik.go +++ b/ass3/zbirnik/parsing/pregledovalnik.go @@ -7,8 +7,13 @@ import ( "strings" ) +type ukaz interface { + Temp() +} -type ukaz struct { +func (f format_F1) Temp() {} + +type format_F1 struct { opcode int st_operandov int format int // F1 - 1, F2 - 2, F3 - 3, F4 - 4, SIC - 5 @@ -74,7 +79,7 @@ var ukazna_tabela = map[string]int{ "TIO": 0xF8, "TIX": 0x2C, "TIXR": 0xB8, - "WD": 0xDC + "WD": 0xDC, } // Pregledovalnik bere vhodne vrstice in jih razgradi na posamezne enote. @@ -84,7 +89,7 @@ var ukazna_tabela = map[string]int{ func main() { - //register, _ := regexp.Compile("A|X|L|B|S|T|F") + register = `A|X|L|B|S|T|F` inputbyte, err := os.ReadFile("input_invalid.asm") if err != nil { @@ -94,7 +99,7 @@ func main() { input := string(inputbyte) pattern := regexp.MustCompile(`.*\n`) matches := pattern.FindAllString(input, -1) - //var AST []ukaz + var AST []ukaz for _, el := range matches { match_pure_comment, err := regexp.MatchString(`(?m)^[\t ]*\..*$\n`, el) if err != nil { @@ -115,14 +120,20 @@ func main() { fmt.Println("Error while matching string.") } if match_F1 { - var nov_ukaz ukaz + var nov_ukaz format_F1 nov_ukaz.format = 1 nov_ukaz.st_operandov = 0 nov_ukaz.velikost = 1 pattern := regexp.MustCompile(`[\t ]+[A-Za-z]+`) - mnemonik := strings.Trim(re.FindString(el), " \n") + mnemonik := strings.Trim(pattern.FindString(el), " \n") nov_ukaz.opcode = ukazna_tabela[mnemonik]; - fmt.Print(mnemonik) + fmt.Println(mnemonik, nov_ukaz.opcode) + AST = append(AST, nov_ukaz) + continue } + match_F2, err := regexp.MatchString(`^[A-Za-z_]*[\t ]+[A-Za-z_]+[\t ](((`+register+`), `+register+`)|(`+register+`))[\t ]*(\..*)?$\n`) + if err != nil { + fmt.Println("Error while matching string.") + } } }