lex

package
v0.0.0-...-313ecc2 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2019 License: BSD-3-Clause, MIT Imports: 11 Imported by: 0

Documentation

Overview

Package lex implements lexical analysis for the assembler.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HistLine

func HistLine() int32

HistLine reports the cumulative source line number of the token, for use in the Prog structure for the linker. (It's always handling the instruction from the current lex line.) It returns int32 because that's what type ../asm prefers.

func InitHist

func InitHist()

InitHist sets the line count to 1, for reproducible testing.

func IsRegisterShift

func IsRegisterShift(r ScanToken) bool

IsRegisterShift reports whether the token is one of the ARM register shift operators.

Types

type Input

type Input struct {
	Stack
	// contains filtered or unexported fields
}

Input is the main input: a stack of readers and some macro definitions. It also handles #include processing (by pushing onto the input stack) and parses and instantiates macro definitions.

func NewInput

func NewInput(name string) *Input

NewInput returns an Input from the given path.

func (*Input) Close

func (in *Input) Close()

func (*Input) Error

func (in *Input) Error(args ...interface{})

func (*Input) Next

func (in *Input) Next() ScanToken

func (*Input) Push

func (in *Input) Push(r TokenReader)

func (*Input) Text

func (in *Input) Text() string

type Macro

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

A Macro represents the definition of a #defined macro.

type ScanToken

type ScanToken rune

A ScanToken represents an input item. It is a simple wrapping of rune, as returned by text/scanner.Scanner, plus a couple of extra values.

const (
	// Asm defines some two-character lexemes. We make up
	// a rune/ScanToken value for them - ugly but simple.
	LSH ScanToken = -1000 - iota // << Left shift.
	RSH                          // >> Logical right shift.
	ARR                          // -> Used on ARM for shift type 3, arithmetic right shift.
	ROT                          // @> Used on ARM for shift type 4, rotate right.

)

func (ScanToken) String

func (t ScanToken) String() string

type Slice

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

A Slice reads from a slice of Tokens.

func NewSlice

func NewSlice(fileName string, line int, tokens []Token) *Slice

func (*Slice) Close

func (s *Slice) Close()

func (*Slice) Col

func (s *Slice) Col() int

func (*Slice) File

func (s *Slice) File() string

func (*Slice) Line

func (s *Slice) Line() int

func (*Slice) Next

func (s *Slice) Next() ScanToken

func (*Slice) SetPos

func (s *Slice) SetPos(line int, file string)

func (*Slice) Text

func (s *Slice) Text() string

type Stack

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

A Stack is a stack of TokenReaders. As the top TokenReader hits EOF, it resumes reading the next one down.

func (*Stack) Close

func (s *Stack) Close()

func (*Stack) Col

func (s *Stack) Col() int

func (*Stack) File

func (s *Stack) File() string

func (*Stack) Line

func (s *Stack) Line() int

func (*Stack) Next

func (s *Stack) Next() ScanToken

func (*Stack) Push

func (s *