示例#1
0
文件: linelist.go 项目: mm0205/gcasl
func (assembler *LineList) ParseEnd(currentLine string) error {
	source := token.NewSource(currentLine)
	end := line.NewEnd()
	err := end.Parse(source)
	if err != nil {
		return err
	}
	assembler.Lines = append(assembler.Lines, end)
	return nil
}
示例#2
0
文件: linelist.go 项目: mm0205/gcasl
func (assembler *LineList) ParseDC(currentLine string) error {
	source := token.NewSource(currentLine)
	temp := line.NewDC()
	err := temp.Parse(source)
	if err != nil {
		return err
	}
	assembler.Lines = append(assembler.Lines, temp)
	return nil
}
示例#3
0
文件: linelist.go 项目: mm0205/gcasl
func (assembler *LineList) ParseStart(currentLine string) error {
	source := token.NewSource(currentLine)
	start := line.NewStart()
	err := start.Parse(source)
	if err != nil {
		return err
	}
	assembler.Lines = append(assembler.Lines, start)
	return nil
}
示例#4
0
文件: end_test.go 项目: mm0205/gcasl
func TestEndParse(t *testing.T) {
	testCaseList := []testCaseForTestEndParse{
		{data: `     END`},
		{data: `     END	; COMMENT`},
	}
	for _, testCase := range testCaseList {
		testData := testCase.data
		start := line.NewEnd()
		source := token.NewSource(testData)
		err := start.Parse(source)
		if err != nil {
			t.Error(err)
		}
	}
}
示例#5
0
文件: r1r2_test.go 项目: mm0205/gcasl
func TestR1R2Parse(t *testing.T) {
	testCaseList := []testCaseForTestR1R2Parse{
		{data: `     LD		GR0, GR1`},
		{data: `     LD GR2		, 		GR3	; COMMENT`},
	}
	for _, testCase := range testCaseList {
		testData := testCase.data
		r1r2 := line.NewR1R2()
		source := token.NewSource(testData)
		err := r1r2.Parse(source)
		if err != nil {
			t.Error(err)
		}
		// t.Error(r1r2)
	}
}
示例#6
0
func TestStartParse(t *testing.T) {
	testCaseList := []testCaseForTestStartParse{
		{data: `EX11     START`},
		{data: `EX11     START SLABEL`},
		{data: `EX11     START SLABEL ; COMMENt`},
	}
	for _, testCase := range testCaseList {
		testData := testCase.data
		start := line.NewStart()
		source := token.NewSource(testData)
		err := start.Parse(source)
		if err != nil {
			t.Error(err)
		}
	}
}
示例#7
0
func TestCommentParse(t *testing.T) {
	testCaseList := []testCaseForTestCommentParse{
		{data: `; This is Comment`},
		{data: ` ; This is comment`},
	}
	for _, testCase := range testCaseList {
		testData := testCase.data

		source := token.NewSource(testData)
		register := token.NewComment()
		err := register.Parse(source)
		if err != nil {
			t.Error(err)
		}
	}
}
示例#8
0
文件: adr_test.go 项目: mm0205/gcasl
func TestAdrParse(t *testing.T) {
	testCaseList := []testCaseForTestAdrParse{
		{data: `     JPL ADR1`},
		{data: `     JMI ADR1		; COMMENT`},
		{data: `LABEL     JNZ  ADR1 	; COMMENT`},
	}
	for _, testCase := range testCaseList {
		testData := testCase.data
		adr := line.NewAdr()
		source := token.NewSource(testData)
		err := adr.Parse(source)
		if err != nil {
			t.Error(err)
		}
		// t.Error(adr)
	}
}
示例#9
0
文件: ds_test.go 项目: mm0205/gcasl
func TestDSParse(t *testing.T) {
	testCaseList := []testCaseForTestDSParse{
		{data: `     DS 1234`},
		{data: `     DS #10		; COMMENT`},
		{data: `LABEL     DS #FFFF ; COMMENT`},
	}
	for _, testCase := range testCaseList {
		testData := testCase.data
		ds := line.NewDS()
		source := token.NewSource(testData)
		err := ds.Parse(source)
		if err != nil {
			t.Error(err)
		}
		// t.Error(ds)
	}
}
示例#10
0
文件: r_test.go 项目: mm0205/gcasl
func TestRParse(t *testing.T) {
	testCaseList := []testCaseForTestRParse{
		{data: `     POP GR0`},
		{data: `     POP GR1 ; COMMENT`},
		{data: `LABEL     POP GR5	; COMMENT`},
	}
	for _, testCase := range testCaseList {
		testData := testCase.data
		adr := line.NewR()
		source := token.NewSource(testData)
		err := adr.Parse(source)
		if err != nil {
			t.Error(err)
		}
		// t.Error(adr)
	}
}
示例#11
0
文件: dc_test.go 项目: mm0205/gcasl
func TestDCParse(t *testing.T) {
	testCaseList := []testCaseForTestDCParse{
		{data: `     DC 1234`},
		{data: `     DC #10, 1234, '''test'''		; COMMENT`},
		{data: `LABEL     DC #FFFF, LABEL2, 'string', 10 ; COMMENT`},
	}
	for _, testCase := range testCaseList {
		testData := testCase.data
		dc := line.NewDC()
		source := token.NewSource(testData)
		err := dc.Parse(source)
		if err != nil {
			t.Error(err)
		}
		// t.Error(dc.Operands)
	}
}
示例#12
0
func TestRAdrXParse(t *testing.T) {
	testCaseList := []testCaseForTestRAdrXParse{
		{data: `     ADDA  GR0, ADR1, GR1`},
		{data: `     SUBA GR0, ADR1, GR1	; COMMENT`},
		{data: `LABEL     SRL GR0, ADR1, GR1	; COMMENT`},
	}
	for _, testCase := range testCaseList {
		testData := testCase.data
		radrx := line.NewRAdrX()
		source := token.NewSource(testData)
		err := radrx.Parse(source)
		if err != nil {
			t.Error(err)
		}
		// t.Error(radrx)
	}
}
示例#13
0
func TestInOutParse(t *testing.T) {
	testCaseList := []testCaseForTestInOutParse{
		{data: `         IN      BUFF, LEN`},
		{data: `         OUT     MSG2, MLEN		; COMMENT`},
		{data: `OK       OUT     MSG1, MLEN ; COMMENT`},
	}
	for _, testCase := range testCaseList {
		testData := testCase.data
		inout := line.NewInOut()
		source := token.NewSource(testData)
		err := inout.Parse(source)
		if err != nil {
			t.Error(err)
		}
		// t.Error(inout)
	}
}
示例#14
0
文件: none_test.go 项目: mm0205/gcasl
func TestNoneParse(t *testing.T) {
	testCaseList := []testCaseForTestNoneParse{
		{data: `     NOP`},
		{data: `     RET 	; COMMENT`},
		{data: `LABEL     NOP 	; COMMENT`},
		{data: `LABEL     RPUSH ; COMMENT`},
		{data: `LABEL     RPOP ; COMMENT`},
	}
	for _, testCase := range testCaseList {
		testData := testCase.data
		adr := line.NewNone()
		source := token.NewSource(testData)
		err := adr.Parse(source)
		if err != nil {
			t.Error(err)
		}
		// t.Error(adr)
	}
}
示例#15
0
func TestLabelParse(t *testing.T) {
	label := token.NewLabel()
	source := token.NewSource("MAIN			 START")
	err := label.Parse(source)
	if err != nil {
		t.Error(err)
	}
	if label.TextValue() != "MAIN" {
		t.Errorf("Label error %#v", label)
	}

	opcode := token.NewOpcode()
	err = opcode.Parse(source)
	if err != nil {
		t.Error(err)
	}
	if opcode.TextValue() != "START" {
		t.Errorf("Label error %#v", opcode)
	}
}
示例#16
0
func TestRegisterParse(t *testing.T) {
	testCaseList := []testCaseForTestRegisterParse{
		{data: `							LD      GR0, DATA1`},
		{data: `							LD      GR0, 65535`},
		{data: `							LD      GR0, #ABCD`},
		{data: `							LD      GR0, =12345`},
		{data: `							LD      GR0, =#1FE0`},
		{data: `							LD      GR0, ='string'`},
		{data: `							LD      GR0, ='''is esacped quote'`},
	}
	for _, testCase := range testCaseList {
		testData := testCase.data

		source := token.NewSource(testData)
		opcode := token.NewOpcode()
		err := opcode.Parse(source)
		if err != nil {
			t.Error(err)
		}

		register := token.NewRegister()
		err = register.Parse(source)
		if err != nil {
			t.Error(err)
		}

		comma := token.NewComma()
		err = comma.Parse(source)
		if err != nil {
			t.Error(err)
		}
		address := token.NewAddress()
		err = address.Parse(source)
		if err != nil {
			t.Error(err)
		}
	}
}