regexp
This commit is contained in:
parent
acce30cea1
commit
ad4eba0796
3 changed files with 114 additions and 0 deletions
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>]
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue