ch
This commit is contained in:
parent
3856635345
commit
1055ccd52f
6 changed files with 112 additions and 13 deletions
|
|
@ -158,12 +158,14 @@ type format_F4_m struct {
|
|||
|
||||
type format_D struct {
|
||||
oznaka string
|
||||
ime string //NOBASE
|
||||
format int // 6
|
||||
velikost int
|
||||
}
|
||||
|
||||
type format_D_n struct {
|
||||
oznaka string
|
||||
ime string
|
||||
format int // 7
|
||||
velikost int
|
||||
operand string
|
||||
|
|
@ -171,6 +173,7 @@ type format_D_n struct {
|
|||
|
||||
type format_M_r struct {
|
||||
oznaka string
|
||||
ime string
|
||||
format int // 8
|
||||
velikost int
|
||||
operand string
|
||||
|
|
@ -178,11 +181,12 @@ type format_M_r struct {
|
|||
|
||||
type format_M_i struct {
|
||||
oznaka string
|
||||
ime string
|
||||
format int // 9
|
||||
velikost int
|
||||
operand string
|
||||
}
|
||||
|
||||
|
||||
func remove_comments_and_empty_lines(el string) bool {
|
||||
match_pure_comment, err := regexp.MatchString(`(?m)^[\t ]*\..*$\n`, el)
|
||||
if err != nil {
|
||||
|
|
@ -456,32 +460,78 @@ func check_F4_m(el string, AST *[]ukaz) bool {
|
|||
nov_ukaz.x = false
|
||||
}
|
||||
nov_ukaz.e = true
|
||||
fmt.Println(el, nov_ukaz)
|
||||
//fmt.Println(el, nov_ukaz)
|
||||
*AST = append(*AST, nov_ukaz)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func check_D(el string, AST *[]ukaz) {
|
||||
func check_D(el string, AST *[]ukaz) bool {
|
||||
match_D, err := regexp.MatchString(`(?m)^[A-Za-z_]*[\t ]+NOBASE[\t ]*(\..*)?$\n`, el)
|
||||
if err != nil {
|
||||
fmt.Println("Error while matching string.")
|
||||
}
|
||||
if match_D {
|
||||
var nova_direktiva format_D
|
||||
nova_direktiva.ime = "NOBASE"
|
||||
nova_direktiva.format = 6
|
||||
nova_direktiva.velikost = 0
|
||||
if !(strings.HasPrefix(el, " ") || strings.HasPrefix(el, "\t")) {
|
||||
re := regexp.MustCompile(`(?m)^[A-Za-z]+`)
|
||||
nov_direktiva.oznaka = re.FindString(el)
|
||||
nova_direktiva.oznaka = re.FindString(el)
|
||||
} else {
|
||||
nov_direktiva.oznaka = ""
|
||||
nova_direktiva.oznaka = ""
|
||||
}
|
||||
*AST = append(*AST, nova_direktiva)
|
||||
//fmt.Println(el, nova_direktiva)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func check_D_n(el string, AST *[]ukaz) bool {
|
||||
match_D_n, err := regexp.MatchString(`(?m)^[A-Za-z]*[\t ]+(START|END|ORG|EQU|BASE) ([A-Za-z\+\-\*]+|[0-9\+\-\*]+)[\t ]*(\..*)?$\n`, el)
|
||||
if err != nil {
|
||||
fmt.Println("Error while matching string.")
|
||||
}
|
||||
if match_D_n {
|
||||
var nova_direktiva format_D_n
|
||||
re_ime := regexp.MustCompile(`START|END|ORG|EQU|BASE`)
|
||||
nova_direktiva.ime = re_ime.FindString(el)
|
||||
nova_direktiva.format = 7
|
||||
nova_direktiva.velikost = 0
|
||||
if !(strings.HasPrefix(el, " ") || strings.HasPrefix(el, "\t")) {
|
||||
re := regexp.MustCompile(`(?m)^[A-Za-z]+`)
|
||||
nova_direktiva.oznaka = re.FindString(el)
|
||||
} else {
|
||||
nova_direktiva.oznaka = ""
|
||||
}
|
||||
re_ope := regexp.MustCompile(`(START|END|ORG|EQU|BASE) ([A-Za-z\+\-\*]+|[0-9\+\-\*]+)`)
|
||||
nova_direktiva.operand = strings.Split(re_ope.FindString(el), " ")[1]
|
||||
*AST = append(*AST, nova_direktiva)
|
||||
//fmt.Println(el, nova_direktiva)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func check_M_r(el string, AST *[]ukaz) bool {
|
||||
match_M_r, err := regexp.MatchString(`(?m)^[A-Za-z]*[\t ]+(RESW|RESB) ([0-9]+)[\t ]*(\..*)?$\n`, el)
|
||||
if err != nil {
|
||||
fmt.Println("Error while matching string.")
|
||||
}
|
||||
if match_M_r {
|
||||
var nova_direktiva format_D_n
|
||||
re_ime := regexp.MustCompile(`RESW|RESB`)
|
||||
nova_direktiva.ime = re_ime.FindString(el)
|
||||
nova_direktiva.format = 8
|
||||
//predpostavi celostevilski operand in doloci velikost
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Pregledovalnik bere vhodne vrstice in jih razgradi na posamezne enote.
|
||||
// Razpoznane elemente okvalificira (oznaka / mnemonik / operand / komentar)
|
||||
// //<zbirniski stavek> ::== [<oznaka stavka>] <ločilo> <mnemonik> <ločilo> {<operand> <ločilo>} [<komentar>]
|
||||
|
|
@ -504,6 +554,12 @@ func main() {
|
|||
if check_D(el, &AST) {
|
||||
continue
|
||||
}
|
||||
if check_D_n(el, &AST) {
|
||||
continue
|
||||
}
|
||||
if check_M_r(el, &AST) {
|
||||
continue
|
||||
}
|
||||
if check_F1(el, &AST) {
|
||||
continue
|
||||
}
|
||||
|
|
@ -519,7 +575,6 @@ func main() {
|
|||
if check_F2_rr(el, &AST) {
|
||||
continue
|
||||
}
|
||||
// !!! direktivo START je treba preveriti pred F3, sicer jo bo dalo sem
|
||||
if check_F3_m(el, &AST) {
|
||||
continue
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue