Documentation
¶
Overview ¶
Package parser consumes tokens from the lexer, and generates the AST which is then walked to generate binary code.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Data ¶
type Data struct { Node // Name is the name of the data-section Name string // Contents holds the string/byte data for the reference Contents []byte }
Data holds a data-statement, which might look like either of these:
.foo DB "Steve" .bar DB 0x030, 0x40, 0x90
type Instruction ¶
type Instruction struct { Node // Instruction holds the instruction we've found, as a string. Instruction string // Operands holds the operands for this instruction. // // Operands will include numbers, registers, and indrected registers. Operands []Operand }
Instruction holds a parsed instruction.
For example "mov rax, rax".
func (Instruction) String ¶
func (d Instruction) String() string
String outputs this Error structure as a string
type Label ¶
Label holds a label, as seen when it is defined.
For example ":foo" will define a label with name "foo".
type Node ¶
type Node interface { // Output this as a readable string String() string }
Node is something we return from our parser.
type Operand ¶
type Operand struct { // Token contains our parent token. token.Token // If we're operating upon memory-addresses we need to be // able to understand the size of the thing we're operating // upon. // // For example `inc byte ptr [rax]` will increment a byte, // or 8 bits. We have different define sizes available to us: // // byte -> 8 bits. // word -> 16 bits. // dword -> 32 bites. // qword -> 64 bites. Size int // Is indirection used? // // i.e. `rax` has no indirection, but `[rax]` does. Indirection bool }
Operand is used to hold the operand for an instruction.
Some instructions have zero operands (e.g. `nop`), others have one (e.g. `inc rax`), and finally we have several which take two operands (e.g. `mov rax, rbx`).
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser holds our state.
func New ¶
New creates a new Parser, which will parse the specified input program into a series of tokens, and then allow it to be parsed.
func (*Parser) Next ¶
Next returns the stream of parsed "things" from the input source program.
The things we return include:
- Instructions.
- Label definitions.
- Data references.
There might be more things in the future.
func (*Parser) TakeOneArgument ¶
TakeOneArgument reads the argument for a single-arg instruction.
Arguments may be a register-name, number, or a label-value.
func (*Parser) TakeTwoArguments ¶
TakeTwoArguments handles fetching two arguments for an instruction.
Arguments may be register-names, numbers, or label-values