ast

package
v0.0.0-...-d5e0ede Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2025 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExpToString

func ExpToString(e Exp) string

func FactorToString

func FactorToString(f Factor) string

Types

type AddExp

type AddExp struct {
	BaseExp
	HeadExp   *MultExp
	Operators []string
	TailExps  []*MultExp
}

func NewAddExp

func NewAddExp(baseExp BaseExp, headExp *MultExp, operators []string, tailExps []*MultExp) *AddExp

NewAddExp Create a new AddExp

func (*AddExp) Eval

func (a *AddExp) Eval(env Env) (Exp, bool)

Eval は AddExp の定数畳み込みを実行します。 すべての定数項を合計し、非定数項を保持します。 非定数項を最初に保持するように変更されました。

func (*AddExp) TokenLiteral

func (a *AddExp) TokenLiteral() string

type BaseExp

type BaseExp struct{}

BaseExp は基本実装を提供しますが、Type() は具象型によって実装される必要があります。

func (BaseExp) Type

func (b BaseExp) Type() string

Type は具象式の型の名前を返します。 注意: リフレクションを使用したこの汎用実装は信頼できない可能性があります。 各具象 Exp 型が独自の Type() メソッドを実装することを推奨します。

type BaseFactor

type BaseFactor struct{}

func (BaseFactor) Type

func (b BaseFactor) Type() string

type BaseStatement

type BaseStatement struct{}

func (BaseStatement) Type

func (b BaseStatement) Type() string

type CharFactor

type CharFactor struct {
	BaseFactor
	Value string
}

func NewCharFactor

func NewCharFactor(baseFactor BaseFactor, value string) *CharFactor

NewCharFactor Create a new CharFactor

func (CharFactor) TokenLiteral

func (c CharFactor) TokenLiteral() string

type ConfigStmt

type ConfigStmt struct {
	BaseStatement
	ConfigType ConfigType
	Factor     Factor
}

func NewConfigStmt

func NewConfigStmt(baseStatement BaseStatement, configType ConfigType, factor Factor) *ConfigStmt

NewConfigStmt Create a new ConfigStmt

func (ConfigStmt) TokenLiteral

func (c ConfigStmt) TokenLiteral() string

type ConfigType

type ConfigType string

TODO: go generateで作成できないか

const (
	Bits     ConfigType = "BITS"
	InstrSet ConfigType = "INSTRSET"
	Optimize ConfigType = "OPTIMIZE"
	Format   ConfigType = "FORMAT"
	Padding  ConfigType = "PADDING"
	PadSet   ConfigType = "PADSET"
	Section  ConfigType = "SECTION"
	Absolute ConfigType = "ABSOLUTE"
	File     ConfigType = "FILE"
)

func NewConfigType

func NewConfigType(s string) (ConfigType, bool)

type DataType

type DataType string
const (
	Byte  DataType = "BYTE"
	Word  DataType = "WORD"
	Dword DataType = "DWORD"
	None  DataType = ""
)

func NewDataType

func NewDataType(s string) (DataType, bool)

type DeclareStmt

type DeclareStmt struct {
	BaseStatement
	Id    *IdentFactor
	Value Exp // interfaceはポインタにしない
}

func NewDeclareStmt

func NewDeclareStmt(baseStatement BaseStatement, id *IdentFactor, value Exp) *DeclareStmt

NewDeclareStmt Create a new DeclareStmt

func (DeclareStmt) TokenLiteral

func (d DeclareStmt) TokenLiteral() string

type Env

type Env interface {
	LookupMacro(name string) (Exp, bool)
	// GetLOC は '$' 評価に必要な現在のロケーションカウンタ値を返します。
	GetLOC() int32
	// GetConstValue は、式が定数である場合に整数値を抽出します。
	// これは通常、環境 (例: Pass1) によって実装されます。
	GetConstValue(exp Exp) (int, bool)
}

Env は評価中に必要な環境のインターフェースを定義します。 マクロやその他の定義を検索するメソッドを提供します。

type Exp

type Exp interface {
	Node

	Type() string
	// Eval は指定された環境内で式を評価します。
	// 評価/簡約された式と、評価が簡約をもたらしたかどうか (true)
	// そうでないか (false) を示すブール値を返します。
	// 評価が不可能な場合 (例: 未解決の識別子を含む)、
	// 元の式ノードと false を返す必要があります。
	Eval(env Env) (Exp, bool)
	// contains filtered or unexported methods
}

Exp は AST 内の式ノードを表します。

type ExportSymStmt

type ExportSymStmt struct {
	BaseStatement
	Symbols []*IdentFactor
}

func NewExportSymStmt

func NewExportSymStmt(baseStatement BaseStatement, symbols []*IdentFactor) *ExportSymStmt

NewExportSymStmt Create a new ExportSymStmt

func (ExportSymStmt) TokenLiteral

func (es ExportSymStmt) TokenLiteral() string

type ExternSymStmt

type ExternSymStmt struct {
	BaseStatement
	Symbols []*IdentFactor
}

func NewExternSymStmt

func NewExternSymStmt(baseStatement BaseStatement, symbols []*IdentFactor) *ExternSymStmt

NewExternSymStmt Create a new ExternSymStmt

func (ExternSymStmt) TokenLiteral

func (es ExternSymStmt) TokenLiteral() string

type Factor

type Factor interface {
	Node
	Type() string
	// contains filtered or unexported methods
}

type HexFactor

type HexFactor struct {
	BaseFactor
	Value string
}

func NewHexFactor

func NewHexFactor(baseFactor BaseFactor, value string) *HexFactor

NewHexFactor Create a new HexFactor

func (HexFactor) TokenLiteral

func (h HexFactor) TokenLiteral() string

type IdentFactor

type IdentFactor struct {
	BaseFactor
	Value string
}

func NewIdentFactor

func NewIdentFactor(baseFactor BaseFactor, value string) *IdentFactor

NewIdentFactor Create a new IdentFactor

func (IdentFactor) TokenLiteral

func (i IdentFactor) TokenLiteral() string

type ImmExp

type ImmExp struct {
	BaseExp
	Factor Factor
}

func NewImmExp

func NewImmExp(baseExp BaseExp, factor Factor) *ImmExp

NewImmExp Create a new ImmExp

func (*ImmExp) Eval

func (imm *ImmExp) Eval(env Env) (Exp, bool)

func (*ImmExp) TokenLiteral

func (imm *ImmExp) TokenLiteral() string

type JumpType

type JumpType string
const (
	Short JumpType = "SHORT"
	Near  JumpType = "NEAR"
	Far   JumpType = "FAR"
	Empty JumpType = ""
)

func NewJumpType

func NewJumpType(s string) (JumpType, bool)

type LabelStmt

type LabelStmt struct {
	BaseStatement
	Label *IdentFactor
}

func NewLabelStmt

func NewLabelStmt(baseStatement BaseStatement, label *IdentFactor) *LabelStmt

NewLabelStmt Create a new LabelStmt

func (LabelStmt) TokenLiteral

func (l LabelStmt) TokenLiteral() string

type MemoryAddrExp

type MemoryAddrExp struct {
	BaseExp
	DataType DataType
	JumpType JumpType
	Left     *AddExp
	Right    *AddExp // nullable (nil許容)
}

func NewMemoryAddrExp

func NewMemoryAddrExp(baseExp BaseExp, dataType DataType, jumpType JumpType, left *AddExp, right *AddExp) *MemoryAddrExp

NewMemoryAddrExp Create a new MemoryAddrExp

func (*MemoryAddrExp) Eval

func (m *MemoryAddrExp) Eval(env Env) (Exp, bool)

func (*MemoryAddrExp) TokenLiteral

func (m *MemoryAddrExp) TokenLiteral() string

type MnemonicStmt

type MnemonicStmt struct {
	BaseStatement
	Opcode   *IdentFactor
	Operands []Exp
}

func NewMnemonicStmt

func NewMnemonicStmt(baseStatement BaseStatement, opcode *IdentFactor, operands []Exp) *MnemonicStmt

NewMnemonicStmt Create a new MnemonicStmt

func (MnemonicStmt) TokenLiteral

func (ms MnemonicStmt) TokenLiteral() string

type MultExp

type MultExp struct {
	BaseExp
	HeadExp   Exp // Exp インターフェースに戻しました
	Operators []string
	TailExps  []Exp // Exp インターフェースに戻しました
}

func NewMultExp

func NewMultExp(baseExp BaseExp, headExp Exp, operators []string, tailExps []Exp) *MultExp

NewMultExp Create a new MultExp

func (*MultExp) Eval

func (m *MultExp) Eval(env Env) (Exp, bool)

func (*MultExp) TokenLiteral

func (m *MultExp) TokenLiteral() string

type Node

type Node interface {
	TokenLiteral() string
}

type NumberExp

type NumberExp struct {
	ImmExp       // Exp インターフェースを満たすために ImmExp を埋め込みます
	Value  int64 // 評価された数値
}

NumberExp は完全に評価された数値定数式を表します。

func NewNumberExp

func NewNumberExp(base ImmExp, value int64) *NumberExp

NewNumberExp は新しい NumberExp を作成します。

func (*NumberExp) Eval

func (n *NumberExp) Eval(env Env) (Exp, bool)

NumberExp の Eval は自身と true を返し、完全に評価された値であることを示します。

func (*NumberExp) TokenLiteral

func (n *NumberExp) TokenLiteral() string

TokenLiteral は数値の文字列表現を返します。

type NumberFactor

type NumberFactor struct {
	BaseFactor
	Value int
}

func NewNumberFactor

func NewNumberFactor(baseFactor BaseFactor, value int) *NumberFactor

NewNumberFactor Create a new NumberFactor

func (NumberFactor) TokenLiteral

func (n NumberFactor) TokenLiteral() string

type OpcodeStmt

type OpcodeStmt struct {
	BaseStatement
	Opcode *IdentFactor
}

func NewOpcodeStmt

func NewOpcodeStmt(baseStatement BaseStatement, opcode *IdentFactor) *OpcodeStmt

NewOpcodeStmt Create a new OpcodeStmt

func (OpcodeStmt) TokenLiteral

func (os OpcodeStmt) TokenLiteral() string

type Prog

type Prog interface {
	Node
	Type() string
	// contains filtered or unexported methods
}

type Program

type Program struct {
	Statements []Statement
}

func NewProgram

func NewProgram(statements []Statement) *Program

NewProgram Create a new Program

func (Program) String

func (p Program) String() string

func (Program) TokenLiteral

func (p Program) TokenLiteral() string

func (Program) Type

func (p Program) Type() string

type SegmentExp

type SegmentExp struct {
	BaseExp
	DataType DataType
	Left     *AddExp
	Right    *AddExp // nullable (nil許容)
}

func NewSegmentExp

func NewSegmentExp(baseExp BaseExp, dataType DataType, left *AddExp, right *AddExp) *SegmentExp

NewSegmentExp Create a new SegmentExp

func (*SegmentExp) Eval

func (s *SegmentExp) Eval(env Env) (Exp, bool)

func (*SegmentExp) TokenLiteral

func (s *SegmentExp) TokenLiteral() string

type Statement

type Statement interface {
	Node
	Type() string
	// contains filtered or unexported methods
}

type StringFactor

type StringFactor struct {
	BaseFactor
	Value string
}

func NewStringFactor

func NewStringFactor(baseFactor BaseFactor, value string) *StringFactor

NewStringFactor Create a new StringFactor

func (StringFactor) TokenLiteral

func (s StringFactor) TokenLiteral() string

Jump to

Keyboard shortcuts

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