parser

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package parser provides the parsing and execution of BF code.

Index

Constants

View Source
const DataMask int = math.MaxUint16

DataMask is the mask to match the size

View Source
const DataSize int = math.MaxUint16 + 1

DataSize is the size of the input data

Variables

This section is empty.

Functions

func Execute

func Execute[T Number](data []T, program []Instruction, reader io.ByteReader, writer *bufio.Writer) []T

Execute a compiled program

func Instructions added in v0.1.3

func Instructions(input io.ByteReader) iter.Seq[Instruction]

Instructions returns an iterator of the instructions.

func Print added in v0.1.0

func Print(program []Instruction, writer *bufio.Writer)

Print pretty prints out the parsed program.

Types

type Instruction

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

Instruction structure for intermediate program

func NewInstruction

func NewInstruction(chr byte) Instruction

NewInstruction created from a sourcecode byte

func Tokenise

func Tokenise(input io.ByteReader) (program []Instruction, err error)

Tokenise sourcecode into an array of operators

func (Instruction) IsZeroOp added in v0.1.0

func (inst Instruction) IsZeroOp() bool

IsZeroOp returns true for ops that have left the pointer on a zero

func (Instruction) SameOp

func (inst Instruction) SameOp(instTwo Instruction) bool

SameOp compares Instructions operator but not operand

type Number added in v0.0.2

type Number interface {
	byte | int | int8 | int16 | int32 | int64
}

Number interface defines different types that can be used in execution

type Opcode

type Opcode int

Opcode type for instructions.

Jump to

Keyboard shortcuts

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