parser

package
v0.0.0-...-8d130a8 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidCommand = errors.New("invalid command")

ErrInvalidCommand is an error represenitng a command is invalid.

Functions

This section is empty.

Types

type CommandType

type CommandType int

CommandType represents a type of VM command.

const (
	Arithmetic CommandType
	Push
	Pop
	Label
	Goto
	If
	Function
	Return
	Call
)

A list of command types.

type Parser

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

Parser is a parser for VM code. Parser is not thread safe, so it should NOT be used in multiple goroutines.

func New

func New(src io.Reader) *Parser

New creates a new parser object that reads and parses r.

func (*Parser) Advance

func (p *Parser) Advance() error

Advance reads next command from source and set the command to current one. If the next command is invalid, it returns an error. This method should be called only if HasMoreCommands() returns true.

func (*Parser) Arg1

func (p *Parser) Arg1() string

Arg1 returns the first argument in a current command. If a type of the current command is Arithmetic, it returns the command itself. This method should NOT be called if CommandType() returns Return.

func (*Parser) Arg2

func (p *Parser) Arg2() uint

Arg2 returns the second argument in a current command. This method should be called only if CommandType() returns Push, Pop, Function or Call.

func (*Parser) CommandType

func (p *Parser) CommandType() CommandType

CommandType returns a type of a current VM command. In all arithmetic commands it returns Arithmetic.

func (*Parser) HasMoreCommands

func (p *Parser) HasMoreCommands() bool

HasMoreCommands reports whether there exist more commands in input.

Jump to

Keyboard shortcuts

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