This commit is contained in:
aljazbrodar. 2026-01-14 19:20:42 +01:00
parent decc8f3324
commit dadc137833
2 changed files with 16 additions and 21 deletions

View file

@ -1,6 +1,4 @@
arithr START 0 .komentar1 arithr START 0 .komentar1
TEST SHIFTR A, 10, X . testing 0
TEST SVC 10, X . testing
LDS #11 .komentar2 LDS #11 .komentar2
LDT #5 LDT #5
.komentar3 .komentar3

View file

@ -95,7 +95,6 @@ type format_F2_n struct {
format int format int
velikost int velikost int
n string n string
x bool // indeksno naslavljanje
} }
type format_F2_r struct { type format_F2_r struct {
@ -113,7 +112,6 @@ type format_F2_rn struct {
velikost int velikost int
r1 string r1 string
n string n string
x bool
} }
type format_F2_rr struct { type format_F2_rr struct {
@ -125,13 +123,6 @@ type format_F2_rr struct {
r2 string r2 string
} }
type format_F3 struct {
oznaka string
opcode int
format int
velikost int
}
type format_F3_m struct { type format_F3_m struct {
oznaka string oznaka string
opcode int opcode int
@ -139,6 +130,11 @@ type format_F3_m struct {
velikost int velikost int
naslov string naslov string
x bool x bool
b bool
p bool
e bool
n bool
i bool
} }
func remove_comments_and_empty_lines(el string) bool { func remove_comments_and_empty_lines(el string) bool {
@ -179,7 +175,7 @@ func check_F1(el string, AST *[]ukaz) bool {
} }
func check_F2_n(el string, AST *[]ukaz) bool { func check_F2_n(el string, AST *[]ukaz) bool {
match_F2_n, err := regexp.MatchString(`(?m)^[A-Za-z_]*[\t ]+SVC ((#?|@?)[0-9]+)(, X)?[\t ]*(\..*)?$\n`, el) match_F2_n, err := regexp.MatchString(`(?m)^[A-Za-z_]*[\t ]+SVC ([0-9]+)[\t ]*(\..*)?$\n`, el)
if err != nil { if err != nil {
fmt.Println("Error while matching string.") fmt.Println("Error while matching string.")
} }
@ -194,13 +190,11 @@ func check_F2_n(el string, AST *[]ukaz) bool {
} else { } else {
nov_ukaz.oznaka = "" nov_ukaz.oznaka = ""
} }
re_par := regexp.MustCompile(`[\t ]+(#?|@?)[0-9]+,?`) re_par := regexp.MustCompile(`[\t ]+[0-9]+,?`)
temp := strings.Trim(re_par.FindString(el), "\t ") temp := strings.Trim(re_par.FindString(el), "\t ")
if temp[len(temp) - 1] == ',' { if temp[len(temp) - 1] == ',' {
nov_ukaz.x = true
nov_ukaz.n = strings.TrimRight(temp, ",") nov_ukaz.n = strings.TrimRight(temp, ",")
} else { } else {
nov_ukaz.x = false
nov_ukaz.n = temp nov_ukaz.n = temp
} }
//fmt.Println("F2_n ", el[:len(el) - 1], nov_ukaz) //fmt.Println("F2_n ", el[:len(el) - 1], nov_ukaz)
@ -237,7 +231,7 @@ func check_F2_r(el string, AST *[]ukaz) bool {
} }
func check_F2_rn(el string, AST *[]ukaz) bool { func check_F2_rn(el string, AST *[]ukaz) bool {
match_F2_rn, err := regexp.MatchString(`(?m)^[A-Za-z_]*[\t ]+[A-Za-z]+ (`+register+`), ((#?|@?)[0-9]+)(, X)?[\t ]*(\..*)?$\n`, el) match_F2_rn, err := regexp.MatchString(`(?m)^[A-Za-z_]*[\t ]+[A-Za-z]+ (`+register+`), ([0-9]+)[\t ]*(\..*)?$\n`, el)
if err != nil { if err != nil {
fmt.Println("Error while matching string.") fmt.Println("Error while matching string.")
} }
@ -255,13 +249,11 @@ func check_F2_rn(el string, AST *[]ukaz) bool {
nov_ukaz.opcode = ukazna_tabela[strings.Trim(re_op.FindString(el), "\t ")] nov_ukaz.opcode = ukazna_tabela[strings.Trim(re_op.FindString(el), "\t ")]
re_par1 := regexp.MustCompile(`[\t ]+[A-Za-z]+ (`+register+`)`) re_par1 := regexp.MustCompile(`[\t ]+[A-Za-z]+ (`+register+`)`)
nov_ukaz.r1 = strings.Split(strings.Trim(re_par1.FindString(el), "\t \n"), " ")[1] nov_ukaz.r1 = strings.Split(strings.Trim(re_par1.FindString(el), "\t \n"), " ")[1]
re_par2 := regexp.MustCompile(`(`+register+`), ((#?|@?)[0-9]+),?`) re_par2 := regexp.MustCompile(`(`+register+`), ([0-9]+),?`)
temp := strings.Split(re_par2.FindString(el), " ")[1] temp := strings.Split(re_par2.FindString(el), " ")[1]
if temp[len(temp) - 1] == ',' { if temp[len(temp) - 1] == ',' {
nov_ukaz.x = true
nov_ukaz.n = strings.TrimRight(temp, ",") nov_ukaz.n = strings.TrimRight(temp, ",")
} else { } else {
nov_ukaz.x = false
nov_ukaz.n = temp nov_ukaz.n = temp
} }
//fmt.Println("F2_rn: ", el[:len(el) - 1], nov_ukaz) //fmt.Println("F2_rn: ", el[:len(el) - 1], nov_ukaz)
@ -299,6 +291,10 @@ func check_F2_rr(el string, AST *[]ukaz) bool {
return false return false
} }
func check_F3_m(el string, AST *[]ukaz) bool {
}
// Pregledovalnik bere vhodne vrstice in jih razgradi na posamezne enote. // Pregledovalnik bere vhodne vrstice in jih razgradi na posamezne enote.
// Razpoznane elemente okvalificira (oznaka / mnemonik / operand / komentar) // Razpoznane elemente okvalificira (oznaka / mnemonik / operand / komentar)
// //<zbirniski stavek> ::== [<oznaka stavka>] <ločilo> <mnemonik> <ločilo> {<operand> <ločilo>} [<komentar>] // //<zbirniski stavek> ::== [<oznaka stavka>] <ločilo> <mnemonik> <ločilo> {<operand> <ločilo>} [<komentar>]
@ -321,7 +317,6 @@ func main() {
if check_F1(el, &AST) { if check_F1(el, &AST) {
continue continue
} }
// TODO !!! odstrani # in @ in x naslalvljaje od F2 formata, saj nima bitov, da to podpre
if check_F2_n(el, &AST) { if check_F2_n(el, &AST) {
continue continue
} }
@ -334,6 +329,8 @@ func main() {
if check_F2_rr(el, &AST) { if check_F2_rr(el, &AST) {
continue continue
} }
//match_F2, err := regexp.MatchString(`(?m)^[A-Za-z_]*[\t ]+[A-Za-z_]+[\t ](((`+register+`), (`+register+`))|((`+register+`), (#?|@?)[0-9]+)|(`+register+`))[\t ]*(\..*)?$\n`, el) if check_F3_m(el, &AST) {
continue
}
} }
} }