ast

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2025 License: LGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ArithPlus   = ArithOp(iota + 1) // +
	ArithMinus                      // -
	ArithMul                        // *
	ArithDiv                        // /
	ArithMod                        // %
	ArithLshift                     // <<
	ArithRshift                     // >>
	ArithAnd                        // &
	ArithOr                         // |
	ArithXor                        // ^
	ArithMax    = ArithXor
)

Variables

This section is empty.

Functions

func ErrLabelAlreadyDef

func ErrLabelAlreadyDef(firstDef, secondDef *LabelDefSt) error

func IsGlobal

func IsGlobal(name string) bool

IsGlobal returns true when 'name' is a global identifier.

Types

type ArithExpr

type ArithExpr struct {
	Op    ArithOp
	Left  Expr
	Right Expr
	// contains filtered or unexported fields
}

expression types

func (*ArithExpr) Position added in v0.3.0

func (e *ArithExpr) Position() Position

type ArithOp

type ArithOp byte

ArithOp is an arithmetic operation.

func (ArithOp) String

func (i ArithOp) String() string

type AssembleSt

type AssembleSt struct {
	Src      *Document
	Filename string
	// contains filtered or unexported fields
}

toplevel statement types

func (*AssembleSt) Description

func (inst *AssembleSt) Description() string

func (*AssembleSt) Position

func (inst *AssembleSt) Position() Position

type BytesSt added in v0.3.0

type BytesSt struct {
	Value Expr
	Label *LabelDefSt
	// contains filtered or unexported fields
}

toplevel statement types

func (*BytesSt) Description added in v0.3.0

func (inst *BytesSt) Description() string

func (*BytesSt) Position added in v0.3.0

func (inst *BytesSt) Position() Position

type Document

type Document struct {
	File       string
	Statements []Statement

	// The document that contains/encloses this document.
	Parent *Document

	// The statement that created this document.
	// This is filled in for instruction macros, #include/#assemble, etc.
	Creation Statement
	// contains filtered or unexported fields
}

Document is the toplevel of the AST. It represents a list of abstract instructions and macro definitions.

func (*Document) CreationString

func (doc *Document) CreationString() string

func (*Document) GlobalExprMacros

func (doc *Document) GlobalExprMacros() []*ExpressionMacroDef

GlobalExprMacros returns the list of global expression macro definitions in the docment.

func (*Document) GlobalInstrMacros

func (doc *Document) GlobalInstrMacros() []*InstructionMacroDef

GlobalInstrMacros returns the list of global instruction macro definitions in the docment.

func (*Document) GlobalLabels

func (doc *Document) GlobalLabels() []*LabelDefSt

GlobalLabels returns the list of global label definitions in the docment.

func (*Document) InstrMacros

func (doc *Document) InstrMacros() []*InstructionMacroDef

InstrMacros returns the list of all instruction macro definitions in the docment.

func (*Document) LookupExprMacro

func (doc *Document) LookupExprMacro(name string) (*ExpressionMacroDef, *Document)

LookupExprMacro finds the definition of an expression macro.

func (*Document) LookupInstrMacro

func (doc *Document) LookupInstrMacro(name string) (*InstructionMacroDef, *Document)

LookupInstrMacro finds the definition of an instruction macro.

func (*Document) LookupLabel

func (doc *Document) LookupLabel(lref *LabelRefExpr) (*LabelDefSt, *Document)

LookupLabel finds the definition of a label.

type Expr

type Expr interface {
	Position() Position
}

type ExpressionMacroDef

type ExpressionMacroDef struct {
	Name   string
	Params []string
	Body   Expr
	// contains filtered or unexported fields
}

definitions

func (*ExpressionMacroDef) Description

func (def *ExpressionMacroDef) Description() string

func (*ExpressionMacroDef) Position

func (def *ExpressionMacroDef) Position() Position

type IncludeSt

type IncludeSt struct {
	Src      *Document
	Filename string
	// contains filtered or unexported fields
}

toplevel statement types

func (*IncludeSt) Description

func (inst *IncludeSt) Description() string

func (*IncludeSt) Position

func (inst *IncludeSt) Position() Position

type InstructionMacroDef

type InstructionMacroDef struct {
	Name   string
	Params []string
	Body   *Document
	// contains filtered or unexported fields
}

definitions

func (*InstructionMacroDef) Description

func (def *InstructionMacroDef) Description() string

func (*InstructionMacroDef) Position

func (def *InstructionMacroDef) Position() Position

type LabelDefSt

type LabelDefSt struct {
	Src    *Document
	Dotted bool
	Global bool
	// contains filtered or unexported fields
}

toplevel statement types

func (*LabelDefSt) Description

func (inst *LabelDefSt) Description() string

func (*LabelDefSt) Name

func (l *LabelDefSt) Name() string

func (*LabelDefSt) Position

func (inst *LabelDefSt) Position() Position

func (*LabelDefSt) String

func (l *LabelDefSt) String() string

type LabelRefExpr

type LabelRefExpr struct {
	Ident  string
	Dotted bool
	Global bool
	// contains filtered or unexported fields
}

expression types

func (*LabelRefExpr) Position added in v0.3.0

func (l *LabelRefExpr) Position() Position

func (*LabelRefExpr) String

func (l *LabelRefExpr) String() string

type LiteralExpr

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

expression types

func MakeNumber added in v0.3.0

func MakeNumber(v *lzint.Value) *LiteralExpr

MakeNumber creates a number literal with the given value.

func MakeString added in v0.3.0

func MakeString(v string) *LiteralExpr

MakeString creates a string literal with the given value.

func (*LiteralExpr) Position added in v0.3.0

func (l *LiteralExpr) Position() Position

func (*LiteralExpr) Text

func (e *LiteralExpr) Text() string

Text returns the text content of the literal as-written. Note this does not include the quotes for string literals.

func (*LiteralExpr) Value

func (e *LiteralExpr) Value() *lzint.Value

Value returns the parsed value of the literal.

type MacroCallExpr

type MacroCallExpr struct {
	Ident   string
	Builtin bool
	Args    []Expr
	// contains filtered or unexported fields
}

expression types

func (*MacroCallExpr) Position added in v0.3.0

func (e *MacroCallExpr) Position() Position

type MacroCallSt

type MacroCallSt struct {
	Ident string
	Src   *Document
	Args  []Expr
	// contains filtered or unexported fields
}

toplevel statement types

func (*MacroCallSt) Description

func (inst *MacroCallSt) Description() string

func (*MacroCallSt) Position

func (inst *MacroCallSt) Position() Position

type OpcodeSt

type OpcodeSt struct {
	Op       string
	Src      *Document
	Arg      Expr // Immediate argument for PUSH* / JUMP*.
	PushSize byte // For PUSH<n>, this is n+1.
	// contains filtered or unexported fields
}

toplevel statement types

func (*OpcodeSt) Description

func (inst *OpcodeSt) Description() string

func (*OpcodeSt) Position

func (inst *OpcodeSt) Position() Position

type ParseError

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

ParseError is an error that happened during parsing.

func (*ParseError) Error

func (e *ParseError) Error() string

func (*ParseError) IsWarning

func (e *ParseError) IsWarning() bool

func (*ParseError) Position

func (e *ParseError) Position() Position

func (*ParseError) Unwrap

func (e *ParseError) Unwrap() error

type Parser

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

Parser performs parsing of the token stream.

func NewParser

func NewParser(file string, content []byte, debug bool) *Parser

NewParser creates a parser.

func (*Parser) Parse

func (p *Parser) Parse() (*Document, []*ParseError)

Parse runs the parser, outputting a document.

func (*Parser) ParseExpression

func (p *Parser) ParseExpression() (expr Expr, err error)

ParseExpression parses the input as a single expression. This is used in evaluator tests.

type Position

type Position struct {
	File string
	Line int
}

Position represents a line in a file.

func (Position) String

func (p Position) String() string

type PragmaSt

type PragmaSt struct {
	Option string
	Value  string
	// contains filtered or unexported fields
}

toplevel statement types

func (*PragmaSt) Description

func (inst *PragmaSt) Description() string

func (*PragmaSt) Position

func (inst *PragmaSt) Position() Position

type Statement

type Statement interface {
	Position() Position
	Description() string
}

type UnaryArithExpr added in v0.3.0

type UnaryArithExpr struct {
	Op  ArithOp
	Arg Expr
	// contains filtered or unexported fields
}

expression types

func (*UnaryArithExpr) Position added in v0.3.0

func (e *UnaryArithExpr) Position() Position

type VariableExpr

type VariableExpr struct {
	Ident string
	// contains filtered or unexported fields
}

expression types

func (*VariableExpr) Position added in v0.3.0

func (e *VariableExpr) Position() Position

Jump to

Keyboard shortcuts

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