vm

package
v0.0.0-...-2c802aa Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 26, 2019 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package vm provides a Virtual Machine to execute regular expression matching. For Details: https://swtch.com/~rsc/regexp/regexp2.html

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Thread

type Thread struct {
	PC int
	SP int
}

Thread represents a thread which has two pointers(program counter/string pointer). A program counter (PC) is a register has the information where a instruction which being executed by VM. A string pointer (SP) is a register has the information where a character that the VM is looking at.

func NewThread

func NewThread(pc int, sp int) *Thread

NewThread returns a new Thread which has the PC and SP set to the value specified by the argument.

type VM

type VM struct {
	// contains filtered or unexported fields
}

VM represents a Virtual Machine which executes regular expression matching. The VM has a bytecode and one or more threads.

func NewVM

func NewVM(bc *bytecode.BC) *VM

NewVM returns a new VM for executing argument bytecode.

func (*VM) AddThread

func (v *VM) AddThread(t *Thread)

AddThread adds a new Thread to the stack of threads in VM.

func (*VM) Run

func (v *VM) Run(input string) int

Run starts to execute regular expression matching for the input string. If the matching was success the return value would be the matched position in the string. The matched position is the number of characters from the top of matched string to the end.

Directories

Path Synopsis
Package instruction provides the instruction structure and some its methods.
Package instruction provides the instruction structure and some its methods.
Package opcode provides the type Opcode to identify the type of operation code.
Package opcode provides the type Opcode to identify the type of operation code.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL