Documentation ¶
Index ¶
- Constants
- func LangParsingDefaultOptions() lexing.TokenMatchingOptions
- func MatchExpression(tokens []text.Token, pState parsing.ParserState) ([]text.Token, bool)
- type BinaryOperation
- type Block
- type BranchStatement
- type ByteListFilterWindow
- type CSTNode
- type DefaultFilterWindow
- type DepositValue
- type EmitError
- type Enum
- type Expression
- type FilterWindow
- type InOperation
- type LangBuilder
- func (builder *LangBuilder) Build(pState *LangParserState) *LangDef
- func (builder *LangBuilder) ParseBlock(cstNode CSTNode) (Block, *parsing.ParsingError)
- func (builder *LangBuilder) ParseBranch(node CSTNode) (BranchStatement, *parsing.ParsingError)
- func (builder *LangBuilder) ParseDeposit(node CSTNode) (DepositValue, *parsing.ParsingError)
- func (builder *LangBuilder) ParseEnum(node CSTNode) bool
- func (builder *LangBuilder) ParseError(node CSTNode) (EmitError, *parsing.ParsingError)
- func (builder *LangBuilder) ParseLoop(node CSTNode) (*LoopFill, *parsing.ParsingError)
- func (builder *LangBuilder) ParseNumericFormat(node CSTNode) bool
- func (builder *LangBuilder) ParseOpcodeDeclaration(node CSTNode, report func(err *parsing.ParsingError)) bool
- type LangDef
- func (lang *LangDef) AssembleOpcode(n int, tokens []text.Token, values []int, flags uint) ([]uint, ui.SourceCodeError)
- func (lang *LangDef) GetEnumValue(identifier string) int
- func (lang *LangDef) GetOpcodeNumber() int
- func (lang *LangDef) IdentifyNumber(t text.Token) (text.Token, ui.SourceCodeError)
- func (lang *LangDef) IsEnumValue(identifier string) bool
- func (lang *LangDef) NewFilterWindow() FilterWindow
- func (lang *LangDef) RemoveSpecialPurposeChars(s string) string
- func (lang *LangDef) SortOpcodes()
- func (lang *LangDef) StringOpcode(index int, argsName []text.Token) string
- type LangParserState
- func (s *LangParserState) Mark() (int, int)
- func (s *LangParserState) Pull(tokens *[]text.Token) int
- func (s *LangParserState) Push(tokens []text.Token, tag int)
- func (s *LangParserState) ReportError(wrong text.Token, err parsing.ParsingErrorType, msg string)
- func (s *LangParserState) SetSkipEOL(skipEOL bool, tokens *[]text.Token)
- func (s *LangParserState) ToCST(markT int, markL int, tag int)
- type LoopFill
- type NumberFormat
- type Opcode
- type OpcodeArg
- type OpcodeNode
- type OpcodeSlice
- type Operand
- type Operation
- type UnaryOperation
Constants ¶
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 ¶
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) 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 ¶
NewCSTNode create a new CSTNode with a tag, a parent, a content and some flags
func NewEmptyCSTNode ¶
NewEmptyCSTNode same as NewCSTNode but without the content, assumed to be empty
func NewRootCSTNode ¶
NewRootCSTNode return a new CSTNode without parent
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) 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
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) 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 (*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 ¶
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 ¶
GetEnumValue return the value of the specified identifier
func (*LangDef) GetOpcodeNumber ¶
GetOpcodeNumber return the number of the opcode in the assembly language
func (*LangDef) IdentifyNumber ¶
IdentifyNumber identify if the token is a number or not
func (*LangDef) IsEnumValue ¶
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 ¶
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
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) 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
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) 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, '->',
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) Less ¶
func (p OpcodeSlice) Less(i, j int) bool
Less return true if p[i] come first than p[j]
type Operand ¶
type Operand struct {
// contains filtered or unexported fields
}
Operand is used to replace OperandUnion
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