langdef

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Ignore = 0 + iota
	OnlyAppend
	TagNumberFormat
	TagEnumDeclaration
	TagErrorStatement
	TagDepositStatement
	TagElseStatement
	TagBranchStatement
	TagForStatement
	TagExpression
	TagStatement
	TagBlock
	TagOpcode
)

Tag values, Ignore and OnlyAppend respect defaults declared in parsing

Variables

This section is empty.

Functions

func LangParsingDefaultOptions

func LangParsingDefaultOptions() lexing.TokenMatchingOptions

LangParsingDefaultOptions return a valid matching options for lexing of a language definition

func MatchExpression

func MatchExpression(tokens []text.Token, pState parsing.ParserState) ([]text.Token, bool)

MatchExpression match a full expression in the parse stream

Types

type BinaryOperation

type BinaryOperation string

BinaryOperation is the binary operand name

func (BinaryOperation) Eval

func (bin BinaryOperation) Eval(eStack *[]Operand, values []OpcodeArg)

Eval unary operation

func (BinaryOperation) String

func (bin BinaryOperation) String() string

String return the name of the operator

type Block

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

Block of nodes delimited by braces

func (*Block) Assemble

func (b *Block) Assemble(values []OpcodeArg, flags uint) ([]uint, ui.SourceCodeError)

Assemble a block of nodes

func (*Block) DebugPrint

func (b *Block) DebugPrint()

DebugPrint print in the stdout the block structure

type BranchStatement

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

BranchStatement is a standard If else statement

func (BranchStatement) Assemble

func (b BranchStatement) Assemble(values []OpcodeArg, flags uint) ([]uint, ui.SourceCodeError)

Assemble branch statement

func (BranchStatement) DebugPrint

func (b BranchStatement) DebugPrint()

DebugPrint print the branch statement to stdout

type ByteListFilterWindow

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

ByteListFilterWindow is a filter window for byte list opcodes

func (ByteListFilterWindow) Collect

func (f ByteListFilterWindow) Collect() (bool, int)

Collect return the true if there is exactly 1 opcode left and opcode in the first index

func (ByteListFilterWindow) FilterByName

func (f ByteListFilterWindow) FilterByName(name string) FilterWindow

FilterByName in truth makes no sense, useful only to implement the FilterWindow interface probably in future should return an error

func (ByteListFilterWindow) FilterByToken

func (f ByteListFilterWindow) FilterByToken(token text.Token) (FilterWindow, bool)

FilterByToken check for match of the byteList or ',' after identifier/value and identifier/value after ','

func (ByteListFilterWindow) IsEmpty

func (f ByteListFilterWindow) IsEmpty() bool

IsEmpty check if the window has no more opcodes

func (ByteListFilterWindow) String

func (f ByteListFilterWindow) String() string

String return a stringed version of f

type CSTNode

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

CSTNode is a Concrete Syntax Tree node built by the parser

func NewCSTNode

func NewCSTNode(tag int, parent *CSTNode, content []text.Token, flags int) CSTNode

NewCSTNode create a new CSTNode with a tag, a parent, a content and some flags

func NewEmptyCSTNode

func NewEmptyCSTNode(tag int, parent *CSTNode, flags int) CSTNode

NewEmptyCSTNode same as NewCSTNode but without the content, assumed to be empty

func NewRootCSTNode

func NewRootCSTNode(tag int, flags int) CSTNode

NewRootCSTNode return a new CSTNode without parent

func (*CSTNode) AddChild

func (node *CSTNode) AddChild(child CSTNode)

AddChild add a child to the children of the CSTNode

func (*CSTNode) Root

func (node *CSTNode) Root() CSTNode

Root return the current root of the tree

type DefaultFilterWindow

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

DefaultFilterWindow is a the common implementation of FilterWindow

func (DefaultFilterWindow) Collect

func (f DefaultFilterWindow) Collect() (bool, int)

Collect return the true if there is exactly 1 opcode left and opcode in the first index

func (DefaultFilterWindow) FilterByName

func (f DefaultFilterWindow) FilterByName(name string) FilterWindow

FilterByName filter opcode by name

func (DefaultFilterWindow) FilterByToken

func (f DefaultFilterWindow) FilterByToken(token text.Token) (FilterWindow, bool)

FilterByToken filter the window using the token in the current position return a new filter window and if the token must be saved

func (DefaultFilterWindow) IsEmpty

func (f DefaultFilterWindow) IsEmpty() bool

IsEmpty check if the window has no more opcodes

func (DefaultFilterWindow) String

func (f DefaultFilterWindow) String() string

type DepositValue

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

DepositValue deposit a value in the destination file

func (DepositValue) Assemble

func (d DepositValue) Assemble(values []OpcodeArg, flags uint) ([]uint, ui.SourceCodeError)

Assemble deposit the value of the expression in the buffer, the high part is not cleared

func (DepositValue) DebugPrint

func (d DepositValue) DebugPrint()

DebugPrint print the deposit statement to stdout

type EmitError

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

EmitError is the error statement

func (EmitError) Assemble

func (es EmitError) Assemble(values []OpcodeArg, flags uint) ([]uint, ui.SourceCodeError)

Assemble return an error in the token position

func (EmitError) DebugPrint

func (es EmitError) DebugPrint()

DebugPrint print the error statement to stdout

type Enum

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

Enum is a set of names

func (Enum) Contains

func (e Enum) Contains(name string) bool

Contains return true if the enum contains the name

func (Enum) IndexOf

func (e Enum) IndexOf(name string) int

IndexOf return th index of the name in the enums

func (Enum) String

func (e Enum) String() string

String return a stringed version of the enum

type Expression

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

Expression postfix representation

func NewExpression

func NewExpression(postfix []text.Token, paramsName []string, enums []Enum) (Expression, *parsing.ParsingError)

NewExpression check and create the expression in the form of postfix operations

func (Expression) DebugPrint

func (e Expression) DebugPrint()

DebugPrint print a debug dump of the Expression

func (*Expression) Eval

func (e *Expression) Eval(params []OpcodeArg) uint

Eval expression

func (*Expression) EvalDebug

func (e *Expression) EvalDebug(params []OpcodeArg) uint

EvalDebug eval expression in debug mode

type FilterWindow

type FilterWindow interface {
	FilterByName(name string) FilterWindow
	FilterByToken(token text.Token) (FilterWindow, bool)
	Collect() (bool, int)
	IsEmpty() bool
	String() string
}

FilterWindow filter is a token by token filter

type InOperation

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

InOperation check if the name is in enums

func (InOperation) Eval

func (i InOperation) Eval(eStack *[]Operand, values []OpcodeArg)

Eval '.in' operation

func (InOperation) String

func (i InOperation) String() string

String return a string version of the operator

type LangBuilder

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

LangBuilder is the builder for the Lang struct

func NewLangBuilder

func NewLangBuilder() LangBuilder

NewLangBuilder create a new LangBuilder

func (*LangBuilder) Build

func (builder *LangBuilder) Build(pState *LangParserState) *LangDef

Build LangDef object

func (*LangBuilder) ParseBlock

func (builder *LangBuilder) ParseBlock(cstNode CSTNode) (Block, *parsing.ParsingError)

ParseBlock parse statements between '{' and '}'

func (*LangBuilder) ParseBranch

func (builder *LangBuilder) ParseBranch(node CSTNode) (BranchStatement, *parsing.ParsingError)

ParseBranch parse if { <statements> } [else { <statements> }] [0 [Other] Expression:13 [IfBlock] BlockParser:12 [ElseBlock] BlockParser:12 ElseParser:8 BranchParser:10]

func (*LangBuilder) ParseDeposit

func (builder *LangBuilder) ParseDeposit(node CSTNode) (DepositValue, *parsing.ParsingError)

ParseDeposit parse deposit statement in the format <size directive> <expression> <size directive> ::= .db | .dw | .dd

func (*LangBuilder) ParseEnum

func (builder *LangBuilder) ParseEnum(node CSTNode) bool

ParseEnum parse the enums in the language definition

func (*LangBuilder) ParseError

func (builder *LangBuilder) ParseError(node CSTNode) (EmitError, *parsing.ParsingError)

ParseError parse error message

func (*LangBuilder) ParseLoop

func (builder *LangBuilder) ParseLoop(node CSTNode) (*LoopFill, *parsing.ParsingError)

ParseLoop parse loop in form: loop <identifier> until <limit expression> <deposit expression> ;

func (*LangBuilder) ParseNumericFormat

func (builder *LangBuilder) ParseNumericFormat(node CSTNode) bool

ParseNumericFormat parse the number format for the specified base always return true

func (*LangBuilder) ParseOpcodeDeclaration

func (builder *LangBuilder) ParseOpcodeDeclaration(node CSTNode, report func(err *parsing.ParsingError)) bool

ParseOpcodeDeclaration parse the opcode declaration in the form name <token list> -> { <body> }

type LangDef

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

LangDef is the language definition it contains the list of defined enums, the chosen number format and a list of the allowed opcodes

func NewLangDef

func NewLangDef(name string, reader io.Reader, ui ui.UI) *LangDef

NewLangDef create a new language definition from a reader

func (*LangDef) AssembleOpcode

func (lang *LangDef) AssembleOpcode(n int, tokens []text.Token, values []int, flags uint) ([]uint, ui.SourceCodeError)

AssembleOpcode assemble the opcode at index n

func (*LangDef) GetEnumValue

func (lang *LangDef) GetEnumValue(identifier string) int

GetEnumValue return the value of the specified identifier

func (*LangDef) GetOpcodeNumber

func (lang *LangDef) GetOpcodeNumber() int

GetOpcodeNumber return the number of the opcode in the assembly language

func (*LangDef) IdentifyNumber

func (lang *LangDef) IdentifyNumber(t text.Token) (text.Token, ui.SourceCodeError)

IdentifyNumber identify if the token is a number or not

func (*LangDef) IsEnumValue

func (lang *LangDef) IsEnumValue(identifier string) bool

IsEnumValue return true if the identifier is an enum value

func (*LangDef) NewFilterWindow

func (lang *LangDef) NewFilterWindow() FilterWindow

NewFilterWindow return a new filterable data set

func (*LangDef) RemoveSpecialPurposeChars

func (lang *LangDef) RemoveSpecialPurposeChars(s string) string

RemoveSpecialPurposeChars remove char used by numbers format as prefix or suffix

func (*LangDef) SortOpcodes

func (lang *LangDef) SortOpcodes()

SortOpcodes sort opcode slice for successive searches

func (*LangDef) StringOpcode

func (lang *LangDef) StringOpcode(index int, argsName []text.Token) string

StringOpcode return the equivalent string for opcode name and format

type LangParserState

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

LangParserState is a configurable ParseState that can skip the EOL if needed

func NewParserState

func NewParserState(pUI ui.UI, src parsing.TokenSource, skipEOL bool, report func(err *parsing.ParsingError)) *LangParserState

NewParserState return a new parser state

func (*LangParserState) Mark

func (s *LangParserState) Mark() (int, int)

Mark current state

func (*LangParserState) Pull

func (s *LangParserState) Pull(tokens *[]text.Token) int

Pull the tokens from the source

func (*LangParserState) Push

func (s *LangParserState) Push(tokens []text.Token, tag int)

Push the tokens in the parsed collection

func (*LangParserState) ReportError

func (s *LangParserState) ReportError(wrong text.Token, err parsing.ParsingErrorType, msg string)

ReportError on a token

func (*LangParserState) SetSkipEOL

func (s *LangParserState) SetSkipEOL(skipEOL bool, tokens *[]text.Token)

SetSkipEOL ask to the ParseState to filter (or not) EOL tokens. The filter (if skipEOL is true) will be applied to the buffered tokens too

func (*LangParserState) ToCST

func (s *LangParserState) ToCST(markT int, markL int, tag int)

ToCST reduce all trees and parsed tokens after the mark to a single tree

type LoopFill

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

LoopFill contains parsing result of a loop statement Loop <index> = this_address -> <limit expression> evaluating <expression> es loop i until this_address + 32 do i*i/4; //this is the fourth square table of 4 bit value useful for the multiplication algorithm a * b = ((a + b)**2)/4 - ((a - b)**2)/4

func (LoopFill) Assemble

func (l LoopFill) Assemble(values []OpcodeArg, flags uint) ([]uint, ui.SourceCodeError)

Assemble fill a slice of uint with result of repeated evaluation

func (LoopFill) DebugPrint

func (l LoopFill) DebugPrint()

DebugPrint print the loop statement to stdout

type NumberFormat

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

NumberFormat tells how number of the base are prefixed or suffixed

func NewNumberFormat

func NewNumberFormat(str string, prefix bool, base int) NumberFormat

NewNumberFormat return a new NumberFormat with the specified parameters, also unquote the string if it is quoted

func (NumberFormat) IsNumber

func (numFormat NumberFormat) IsNumber(n string) bool

IsNumber check if a string is a number for that base

func (NumberFormat) ParseNumber

func (numFormat NumberFormat) ParseNumber(n string) int64

ParseNumber parse a number in that format

func (NumberFormat) String

func (numFormat NumberFormat) String() string

type Opcode

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

Opcode contains name and argument format (if present) <opcode declaration> ::= <name> [<args format>] <name> ::= <identifier> <args format> ::= <arg> | <symbol> | <number> <arg> ::= <identifier> <number> ::= <base prefix> <base digit> [ {<base digit>} ] <identifier> is a valid C identifier <symbol> anythings else but comment marker, '->',

func NewOpcode

func NewOpcode(name string, paramsFormat []text.TokenType, paramsString []string, nodes Block) Opcode

NewOpcode return a new opcode

func (*Opcode) Assemble

func (p *Opcode) Assemble(enums []Enum, args []text.Token, values []int, flags uint) ([]uint, ui.SourceCodeError)

Assemble the opcode given the arguments

type OpcodeArg

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

OpcodeArg is the argument sent to the opcode

type OpcodeNode

type OpcodeNode interface {
	Assemble(values []OpcodeArg, flags uint) ([]uint, ui.SourceCodeError)
	DebugPrint()
}

OpcodeNode is a node of the opcode

type OpcodeSlice

type OpcodeSlice []Opcode

OpcodeSlice is a slice of opcodes

func (OpcodeSlice) Len

func (p OpcodeSlice) Len() int

Len of the opcode slice

func (OpcodeSlice) Less

func (p OpcodeSlice) Less(i, j int) bool

Less return true if p[i] come first than p[j]

func (OpcodeSlice) Swap

func (p OpcodeSlice) Swap(i, j int)

Swap swap two opcode

type Operand

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

Operand is used to replace OperandUnion

func (Operand) Eval

func (p Operand) Eval(eStack *[]Operand, values []OpcodeArg)

Eval push the operand in the expression stack

func (Operand) String

func (p Operand) String() string

String return the stringed version of the operand

func (Operand) Value

func (p Operand) Value(values []OpcodeArg) int64

Value of the Operand

type Operation

type Operation interface {
	Eval(eStack *[]Operand, values []OpcodeArg) //Eval Operation
	String() string                             //String return the equivalent string for the operation
}

Operation pop values from expression stack and push the result

type UnaryOperation

type UnaryOperation string

UnaryOperation is the unary operand name

func (UnaryOperation) Eval

func (u UnaryOperation) Eval(eStack *[]Operand, values []OpcodeArg)

Eval unary operation

func (UnaryOperation) String

func (u UnaryOperation) String() string

String return the name of the operator

Jump to

Keyboard shortcuts

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