Beispiel #1
0
// Parse parses a line.
func (radr *RAdr) Parse(source *token.Source) error {
	radr.Label.Parse(source)

	err := radr.Opcode.Parse(source)
	if err != nil {
		return err
	}
	err = radr.Operand1.Parse(source)
	if err != nil {
		return err
	}
	err = token.NewComma().Parse(source)
	if err != nil {
		return err
	}
	err = radr.Operand2.Parse(source)
	if err != nil {
		return err
	}

	radr.Comment.Parse(source)
	if !IsRAdrOpcode(radr.Opcode.TextValue()) {
		return fmt.Errorf("This line can't accept R, adr %#v", source)
	}
	if !source.IsEmpty() {
		return fmt.Errorf("This line doesn't end. %#v", source)
	}
	return nil
}
Beispiel #2
0
// Parse parses a line.
func (adrx *AdrX) Parse(source *token.Source) error {
	adrx.Label.Parse(source)

	err := adrx.Opcode.Parse(source)
	if err != nil {
		return err
	}
	err = adrx.Operand1.Parse(source)
	if err != nil {
		return err
	}
	err = token.NewComma().Parse(source)
	if err != nil {
		return err
	}
	err = adrx.Operand2.Parse(source)
	if err != nil {
		return err
	}

	adrx.Comment.Parse(source)
	if !IsAdrXOpcode(adrx.Opcode.TextValue()) {
		return fmt.Errorf("This line can't accept adr, x %#v", source)
	}
	if !source.IsEmpty() {
		return fmt.Errorf("This line doesn't end. %#v", source)
	}

	return nil
}
Beispiel #3
0
// Parse parses a line.
func (r1r2 *R1R2) Parse(source *token.Source) error {
	r1r2.Label.Parse(source)

	err := r1r2.Opcode.Parse(source)
	if err != nil {
		return err
	}
	err = r1r2.Operand1.Parse(source)
	if err != nil {
		return err
	}
	err = token.NewComma().Parse(source)
	if err != nil {
		return err
	}
	err = r1r2.Operand2.Parse(source)
	if err != nil {
		return err
	}
	r1r2.Comment.Parse(source)
	if !IsR1R2Opcode(r1r2.Opcode.TextValue()) {
		return fmt.Errorf("This line can't accept R1, R2, %#v", source)
	}
	if !source.IsEmpty() {
		return fmt.Errorf("This line doesn't end. %#v", source)
	}
	return nil
}
Beispiel #4
0
// Parse parses a line.
func (inout *InOut) Parse(source *token.Source) error {
	inout.Label.Parse(source)

	err := inout.Opcode.Parse(source)
	if err != nil {
		return err
	}
	err = inout.Operand1.Parse(source)
	if err != nil {
		return err
	}
	err = token.NewComma().Parse(source)
	if err != nil {
		return err
	}
	err = inout.Operand2.Parse(source)
	if err != nil {
		return err
	}

	inout.Comment.Parse(source)
	if !IsInOutOpcode(inout.Opcode.TextValue()) {
		return fmt.Errorf("This line can't accept label, label %#v", source)
	}
	if !source.IsEmpty() {
		return fmt.Errorf("This line doesn't end. %#v", source)
	}

	return nil
}
Beispiel #5
0
// Parse parses a line.
func (dc *DC) Parse(source *token.Source) error {
	dc.Label.Parse(source)

	err := dc.Opcode.Parse(source)
	if err != nil {
		return err
	}
	for {
		constant := token.NewConstant()
		err = constant.Parse(source)
		if err != nil {
			if 0 < len(dc.Operands) {
				break
			}
			return fmt.Errorf("This line is invalid DC, %#v", source)
		}
		dc.Operands = append(dc.Operands, constant)
		err = token.NewComma().Parse(source)
		if err == nil {
			continue
		}
		break
	}

	dc.Comment.Parse(source)
	if !IsDCOpcode(dc.Opcode.TextValue()) {
		return fmt.Errorf("This line can't accept dc %#v", source)
	}
	if !source.IsEmpty() {
		return fmt.Errorf("This line doesn't end. %#v", source)
	}
	return nil
}
Beispiel #6
0
// Parse parses a line.
func (end *End) Parse(source *token.Source) error {
	err := end.Opcode.Parse(source)
	if err != nil {
		return err
	}
	end.Comment.Parse(source)
	if end.Opcode.TextValue() != "END" {
		return fmt.Errorf("This line is not end. %s", source)
	}
	if !source.IsEmpty() {
		return fmt.Errorf("This line doesn't end. %#v", source)
	}
	return nil
}
Beispiel #7
0
// Parse parses a line.
func (none *None) Parse(source *token.Source) error {
	none.Label.Parse(source)

	err := none.Opcode.Parse(source)
	if err != nil {
		return err
	}

	none.Comment.Parse(source)
	if !IsNoneOpcode(none.Opcode.TextValue()) {
		return fmt.Errorf("This line can't accept none %#v", source)
	}
	if !source.IsEmpty() {
		return fmt.Errorf("This line doesn't end. %#v", source)
	}
	return nil
}
Beispiel #8
0
// Parse parses a line.
func (start *Start) Parse(source *token.Source) error {
	err := start.Label.Parse(source)
	// START line must have label.
	if err != nil {
		return err
	}
	err = start.Opcode.Parse(source)
	if err != nil {
		return err
	}
	start.Operand1.Parse(source)
	start.Comment.Parse(source)
	if start.Opcode.TextValue() != "START" {
		return fmt.Errorf("This line is not START. %s", source)
	}
	if !source.IsEmpty() {
		return fmt.Errorf("This line doesn't end. %#v", source)
	}
	return nil
}
Beispiel #9
0
// Parse parses a line.
func (ds *DS) Parse(source *token.Source) error {
	ds.Label.Parse(source)

	err := ds.Opcode.Parse(source)
	if err != nil {
		return err
	}
	err = ds.Operand1.Parse(source)
	if err != nil {
		return err
	}

	ds.Comment.Parse(source)
	if !IsDSOpcode(ds.Opcode.TextValue()) {
		return fmt.Errorf("This line can't accept ds %#v", source)
	}
	if !source.IsEmpty() {
		return fmt.Errorf("This line doesn't end. %#v", source)
	}
	return nil
}
Beispiel #10
0
Datei: r.go Projekt: mm0205/gcasl
// Parse parses a line.
func (r *R) Parse(source *token.Source) error {
	r.Label.Parse(source)

	err := r.Opcode.Parse(source)
	if err != nil {
		return err
	}
	err = r.Operand1.Parse(source)
	if err != nil {
		return err
	}

	r.Comment.Parse(source)
	if !IsROpcode(r.Opcode.TextValue()) {
		return fmt.Errorf("This line can't accept r %#v", source)
	}
	if !source.IsEmpty() {
		return fmt.Errorf("This line doesn't end. %#v", source)
	}
	return nil
}