Remove dubious workaround in parse_unary().

The comment "eat first char of illegal label, else endless loop on
implied .WORD" was no longer true. It did reveal some other small
gotchas, which are corrected now as well.
This commit is contained in:
Olaf Seibert 2021-01-23 21:01:37 +01:00
parent c587587f49
commit e3042c9175
10 changed files with 105 additions and 38 deletions

View File

@ -659,7 +659,7 @@ int do_word(
} else {
EX_TREE *value = parse_expr(cp, 0);
if (value->cp > cp) {
if (value->type != EX_ERR && value->cp > cp) {
store_value(stack, tr, size, value);
cp = value->cp;

20
parse.c
View File

@ -953,7 +953,7 @@ EX_TREE *parse_unary(
int islocal = 0;
char *endcp;
char *psectname = get_symbol(cp2, &endcp, &islocal);
SYMBOL *sectsym = lookup_sym(psectname, &section_st);
SYMBOL *sectsym = psectname ? lookup_sym(psectname, &section_st) : NULL;
if (sectsym && !islocal) {
SECTION *psect = sectsym->section;
@ -970,11 +970,20 @@ EX_TREE *parse_unary(
tp = new_ex_bin(EX_ADD, tp, rightp);
} else {
tp = ex_err(tp, endcp);
/* report(stack->top, "^p: %c not recognized", bound); */
/* report(stack->top, "^p: %c not recognized\n", bound); */
}
} else {
/* report(stack->top, "psect name %s not found"); */
tp = ex_err(new_ex_lit(0), endcp);
/* report(stack->top, "psect name %s not found\n", psectname); */
if (pass == 0) {
/*
* During the first pass it is expected that the psect is not
* found. Return a dummy value of the expected size, so that
* the size of the psect keeps in sync.
*/
tp = new_ex_lit(0);
} else {
tp = ex_err(new_ex_lit(0), endcp);
}
}
free(psectname);
tp->cp = endcp;
@ -1072,9 +1081,6 @@ EX_TREE *parse_unary(
get_symbol a second time. */
if (!(label = get_symbol(cp, &cp, &local))) {
if (!EOL(*cp)) {
cp++; /*JH: eat first char of illegal label, else endless loop on implied .WORD */
}
tp = ex_err(NULL, cp); /* Not a valid label. */
return tp;
}

21
tests/SetTestOk Executable file
View File

@ -0,0 +1,21 @@
#!/bin/sh
#
set_ok() {
t="$1"
if [ -e "$t".lst.ok ]
then
cp "$t".lst "$t".lst.ok
fi
if [ -e "$t".objd.ok ]
then
cp "$t".objd "$t".objd.okd
fi
}
for fn in "$@"
do
set_ok "$fn"
done

View File

@ -35,28 +35,24 @@ test-asciz.mac:18: ***ERROR Complex expression cannot be assigned to a symbol
18 .asciz =DEF= ; syntax error: assignment
test-asciz.mac:19: ***ERROR Complex expression cannot be assigned to a symbol
19 .asciz =###= ; syntax error: assignment
test-asciz.mac:20: ***ERROR .WORD on odd boundary
test-asciz.mac:20: ***ERROR Invalid expression
20 000075 000 000001 000000 .asciz :SOH: ; syntax error: colon not allowed
test-asciz.mac:21: ***ERROR Illegal symbol definition .ASCIZ
test-asciz.mac:21: ***ERROR Invalid expression
test-asciz.mac:21: ***ERROR Invalid expression
test-asciz.mac:21: ***ERROR Invalid expression
test-asciz.mac:21: ***ERROR Invalid expression
21 000102 000000 000000 000000 .asciz :###: ; syntax error: colon not allowed
000110 000000
22 000112 043 043 043 .asciz ^###^ ; previous versions of this macro11
000115 000
23 ; used ^/.../ quoting as an extension; however this should be ^...^.
23
20 000075 000 .even
test-asciz.mac:21: ***ERROR Invalid expression in .WORD
21 000076 000001 .asciz :SOH: ; syntax error: colon not allowed
test-asciz.mac:22: ***ERROR Illegal symbol definition .ASCIZ
test-asciz.mac:22: ***ERROR Invalid expression in .WORD
22 .asciz :###: ; syntax error: colon not allowed
23 000100 043 043 043 .asciz ^###^ ; previous versions of this macro11
000103 000
24 ; used ^/.../ quoting as an extension; however this should be ^...^.
24
Symbol table
. ******R 001 .ASCIZ 000075R 001 CR = 000015 LF = 000012 SOH = 000001
. ******R 001 .ASCIZ 000076R 001 CR = 000015 LF = 000012 SOH = 000001
Program sections:
. ABS. 000000 000 (RW,I,GBL,ABS,OVR,NOSAV)
000116 001 (RW,I,LCL,REL,CON,NOSAV)
000104 001 (RW,I,LCL,REL,CON,NOSAV)

View File

@ -17,6 +17,7 @@ SOH = 1
.asciz &###& ; another weird delimiter
.asciz =DEF= ; syntax error: assignment
.asciz =###= ; syntax error: assignment
.even
.asciz :SOH: ; syntax error: colon not allowed
.asciz :###: ; syntax error: colon not allowed
.asciz ^###^ ; previous versions of this macro11

View File

@ -46,8 +46,8 @@ test-include.mac:14: ***ERROR Bad .INCLUDE file name
test-include.mac:15: ***ERROR Bad .INCLUDE file name
15 .include <incl.mac<
16 .include =incl.mac= ; looks like assignment
test-include.mac:17: ***ERROR Invalid expression
17 000012 000000G 000000 .include :incl.mac: ; looks like a label
test-include.mac:17: ***ERROR Invalid expression in .WORD
17 000012 000000G .include :incl.mac: ; looks like a label
18
19 ; this is an error: file does not existst
20
@ -64,4 +64,4 @@ Symbol table
Program sections:
. ABS. 000000 000 (RW,I,GBL,ABS,OVR,NOSAV)
000016 001 (RW,I,LCL,REL,CON,NOSAV)
000014 001 (RW,I,LCL,REL,CON,NOSAV)

View File

@ -89,15 +89,42 @@ test-prec.mac:58: ***ERROR Invalid expression
7 .globl name
8 000132 000000G .word name
9 .endc
81
82
test-prec.mac:83: ***ERROR Invalid expression in .WORD
83 .word (
test-prec.mac:84: ***ERROR Invalid expression in .WORD
84 (
85
test-prec.mac:86: ***ERROR Invalid expression in .WORD
86 .word _,$
test-prec.mac:87: ***ERROR Invalid expression in .WORD
87 _
88 000134 000000G $
test-prec.mac:89: ***ERROR Invalid expression in .WORD
89 .word /
test-prec.mac:90: ***ERROR Invalid expression in .WORD
90 /
test-prec.mac:91: ***ERROR Invalid expression in .WORD
91 .word ^px
test-prec.mac:92: ***ERROR Invalid expression in .WORD
92 ^px
test-prec.mac:93: ***ERROR Invalid expression in .WORD
93 .word ^px / 256
test-prec.mac:94: ***ERROR Invalid expression in .WORD
94 ^px / 256
95
96 000136 000001 000002 000003 1,2,3
97 000144 000000G 000000G 000000G .1,.2,.3
97
Symbol table
. ******R 001 NAME = ****** G
$ = ****** GX .1 = ****** GX .3 = ****** GX
. ******R 001 .2 = ****** GX NAME = ****** G
Program sections:
. ABS. 000000 000 (RW,I,GBL,ABS,OVR,NOSAV)
000134 001 (RW,I,LCL,REL,CON,NOSAV)
000152 001 (RW,I,LCL,REL,CON,NOSAV)

View File

@ -79,3 +79,19 @@
.endm
dirdef name
.word (
(
.word _,$
_
$
.word /
/
.word ^px
^px
.word ^px / 256
^px / 256
1,2,3
.1,.2,.3

View File

@ -5,7 +5,7 @@
5 000000 .PSECT section
6
7 000000 000000' .word <^pl section>
8 000002 000014' .word <^ph section>
8 000002 000012' .word <^ph section>
9 000004 000000' .word <^pl code>
10 000006 000010' .word <^ph code>
11 000010 010' .byte <^ph code>
@ -14,7 +14,7 @@
14 000000 .PSECT code
15
16 000000 000000' .word <^pl section>
17 000002 000014' .word <^ph section>
17 000002 000012' .word <^ph section>
18 000004 000000' .word <^pl code>
19 000006 000010' .word <^ph code>
20
@ -31,5 +31,5 @@ Program sections:
. ABS. 000000 000 (RW,I,GBL,ABS,OVR,NOSAV)
000000 001 (RW,I,LCL,REL,CON,NOSAV)
SECTIO 000014 002 (RW,I,LCL,REL,CON,NOSAV)
SECTIO 000012 002 (RW,I,LCL,REL,CON,NOSAV)
CODE 000010 003 (RW,I,LCL,REL,CON,NOSAV)

View File

@ -3,27 +3,27 @@ GSD:
PSECT =0 CON RW REL LCL I flags=40
PSECT . ABS.=0 OVR RW ABS GBL I flags=104
PSECT CODE =10 CON RW REL LCL I flags=40
PSECT SECTIO=14 CON RW REL LCL I flags=40
PSECT SECTIO=12 CON RW REL LCL I flags=40
XFER . ABS.=1 flags=10
ENDGSD
RLD
Location counter definition SECTIO+0
TEXT ADDR=0 LEN=12
000000: 000000 000014 000000 000010 ........
000000: 000000 000012 000000 000010 ........
000010: 000010 ..
RLD
Internal 0=0
Internal 2=14
Internal 2=12
PSECT plus offset 4=CODE+0
PSECT plus offset 6=CODE+10
PSECT plus offset byte 10=CODE+10
Complex byte 11=CODE:10 256 / store
Location counter definition CODE+0
TEXT ADDR=0 LEN=10
000000: 000000 000014 000000 000010 ........
000000: 000000 000012 000000 000010 ........
RLD
PSECT plus offset 0=SECTIO+0
PSECT plus offset 2=SECTIO+14
PSECT plus offset 2=SECTIO+12
Internal 4=0
Internal 6=10
ENDMOD