regexp
This commit is contained in:
parent
acce30cea1
commit
ad4eba0796
3 changed files with 114 additions and 0 deletions
42
ass3/zbirnik/parsing/input.asm
Normal file
42
ass3/zbirnik/parsing/input.asm
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
arithr START 0 .komentar1
|
||||
LDS #11 .komentar2
|
||||
LDT #5
|
||||
.komentar3
|
||||
LDA ZERO
|
||||
ADDR S, A
|
||||
ADDR T, A
|
||||
STA sum
|
||||
|
||||
.komentar4
|
||||
LDA ZERO
|
||||
ADDR S, A
|
||||
SUBR T, A
|
||||
STA diff
|
||||
|
||||
LDA ZERO
|
||||
ADDR S, A
|
||||
MULR T, A
|
||||
STA prod
|
||||
|
||||
LDA ZERO
|
||||
ADDR S, A
|
||||
DIVR T, A
|
||||
STA quot
|
||||
|
||||
LDA ZERO
|
||||
ADDR S, A
|
||||
LOOP SUBR T, A .komentar5
|
||||
COMPR A, T
|
||||
JGT LOOP
|
||||
JEQ LOOP
|
||||
STA mod
|
||||
HALT J HALT
|
||||
END arithr
|
||||
|
||||
ZERO WORD 0
|
||||
sum RESW 1
|
||||
diff RESW 1
|
||||
prod RESW 1
|
||||
quot RESW 1 .komentar6
|
||||
mod RESW 1
|
||||
.komentar7
|
||||
55
ass3/zbirnik/parsing/pregledovalnik.go
Normal file
55
ass3/zbirnik/parsing/pregledovalnik.go
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
/*
|
||||
type ukaz struct {
|
||||
opcode int
|
||||
st_operandov int
|
||||
format int
|
||||
}
|
||||
|
||||
var ukazna_tabela = map[string]ukaz{
|
||||
"LDA":
|
||||
}*/
|
||||
|
||||
func main() {
|
||||
inputbyte, err := os.ReadFile("input.asm")
|
||||
if err != nil {
|
||||
fmt.Println("Error reading input file: ", err)
|
||||
return
|
||||
}
|
||||
input := string(inputbyte)
|
||||
pattern := regexp.MustCompile(`.*\n`)
|
||||
matches := pattern.FindAllString(input, -1)
|
||||
//var cleared_matches []string
|
||||
for _, el := range matches {
|
||||
match_pure_comment, err := regexp.MatchString(`(?m)^[\t ]*\..*$\n`, el)
|
||||
if err != nil {
|
||||
fmt.Println("Error while matching string.")
|
||||
}
|
||||
if match_pure_comment {
|
||||
continue
|
||||
}
|
||||
match_empty, err := regexp.MatchString(`(?m)^[\t ]*$\n`, el)
|
||||
if err != nil {
|
||||
fmt.Println("Error while matching string.")
|
||||
}
|
||||
if match_empty {
|
||||
continue
|
||||
}
|
||||
match_command, err := regexp.MatchString(``, el)
|
||||
fmt.Print(el)
|
||||
}
|
||||
//Zbirnik mora opraviti naslednje naloge:
|
||||
//1) Pregledati in razčleniti zbirniški stavek (pregledovalnik)
|
||||
//2) Mnemonike nadomestiti z operacijskimi kodami
|
||||
//3) Simbolična imena nadomestiti z ustreznimi številskimi ekvivalenti
|
||||
//4) Razrešiti simbolične operande
|
||||
//...
|
||||
//<zbirniski stavek> ::== [<oznaka stavka>] <ločilo> <mnemonik> <ločilo> {<operand> <ločilo>} [<komentar>]
|
||||
}
|
||||
17
ass3/zbirnik/parsing/test.go
Normal file
17
ass3/zbirnik/parsing/test.go
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
func main() {
|
||||
pattern := regexp.MustCompile(`o\w*g`)
|
||||
fmt.Println(pattern.FindString("oogenesis")) // returns ""
|
||||
fmt.Println(pattern.FindString("ck")) // returns "ook"
|
||||
fmt.Println(pattern.FindString("oocyst")) // returns ""
|
||||
fmt.Println(pattern.FindString("book")) // returns "ook"}
|
||||
match, what := regexp.MatchString("p([a-z]+)ch", "peach")
|
||||
fmt.Println(match)
|
||||
fmt.Println(what)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue