|
From: anonymous c. <nas...@us...> - 2010-10-04 13:09:29
|
>> >> > expand_smacro
>> >> > [(TOK_ID|TOK_PREPROC_ID)][(TOK_ID|TOK_PREPROC_ID|TOK_NUMBER)]
>> >> >
>> >> > expand_mmac_params
>> >> > [(TOK_ID|TOK_NUMBER|TOK_FLOAT)][(TOK_ID|TOK_NUMBER|TOK_FLOAT|TOK_OTHER)]
>> >>
>> >> The above permit concatenations that result in invalid
>> >> tokens, and therefore need to be tightened. Try these
>> >> rules instead:
>> >>
>> >> - whitespace(s)/tab(s) with whitespace(s)/tab(s)
>> >> - identifiers with either identifiers or numbers or $/$$
>> >> - preprocessor identifiers or numbers with numbers
>> >> - $ with identifiers or numbers that don't begin with $
>> >>
>> >> I don't know enough about TOK_FLOAT to comment.
>> >
>> > OK, thanks for comments, I'll take a look tomorrow. But basically I would
>> > rather like to hear which exactly invalid tokens you mean? Mind
>> > to elaborate if you have some spare minutes? Also I fear this part of
>>
>> In your first set of rules you cannot have TOK_PREPROC_ID on
>> the right side, since it may start with a character that cannot be
>> inside a TOK_ID or TOK_NUMBER.
>
> We still have to support it since people use it
>
> %assign %$_uses 0
> %rep 4
> %assign %$_ur%$_uses %$_uses
> mov eax, %$_ur%$_uses
> %assign %$_uses %$_uses+1
> %endrep
>
> and friends, we just can't drop it.
Even if I wrap your sample code in %PUSH and %POP
it does not seem to work:
# ./nasm 0.asm
0.asm:8: error: `%assign' expects a macro identifier
0.asm:8: error: `%assign' expects a macro identifier
0.asm:8: error: `%assign' expects a macro identifier
>> In your second set of rules you cannot have TOK_NUMBER plus
>> TOK_ID, let alone xxx plus any TOK_OTHER, for the same basic
>> reason as above.
>
> Well, as far as I see there can't be a combination of TOK_NUM+TOK_ID
> as a single term to be concat'ed, it's written this way in mask
> due to simplicity of handling.
>
> So at moment I fail to see what exactly may produce wrong concat'ed
> terms. Please, if you have a real example with code -- poke me, thanks.
# cat 0.asm
; a number and an identifier
%define TOK_NUM 1
%define TOK_ID @
; prove it
%ifnum TOK_NUM
db TOK_NUM
%endif
%ifid TOK_ID
TOK_ID: jmp TOK_ID
%endif
; implicit and explicit concatenation
%define concat_explicit(X,Y) X%+Y
%macro concat_implicit 2
%define Xi %1%2
%endm
; exercise both concatenations
%define Xe concat_explicit(TOK_NUM,TOK_ID)
concat_implicit TOK_NUM,TOK_ID
; do we have numbers?
%ifnum Xe
nop ; yes we do, due to bad concatenation
%endif
%ifnum Xi
nop ; yes we do, due to bad concatenation
%endif
; really?
%ifdef TRY_Xe
db Xe ; no, because 1# is not a number
%endif
%ifdef TRY_Xi
db Xi ; no, because 1# is not a number
%endif
; EOF
# ./nasm 0.asm -l 0.lst -DTRY_Xe
0.asm:43: error: comma expected after operand 1
# ./nasm 0.asm -l 0.lst -DTRY_Xi
0.asm:47: error: comma expected after operand 1
# ./nasm 0.asm -l 0.lst
# cat 0.lst
1 ; a number and an identifier
2
3 %define TOK_NUM 1
4 %define TOK_ID @
5
6 ; prove it
7
8 %ifnum TOK_NUM
9 00000000 01 db TOK_NUM
10 %endif
11
12 %ifid TOK_ID
13 00000001 EBFE TOK_ID: jmp TOK_ID
14 %endif
15
16 ; implicit and explicit concatenation
17
18 %define concat_explicit(X,Y) X%+Y
19
20 %macro concat_implicit 2
21 %define Xi %1%2
22 %endm
23
24 ; exercise both concatenations
25
26 %define Xe
concat_explicit(TOK_NUM,TOK_ID)
27
28 concat_implicit TOK_NUM,TOK_ID
29 <1> %define Xi %1%2
30
31 ; do we have numbers?
32
33 %ifnum Xe
34 00000003 90 nop ; yes we do, due to bad
concatenation
35 %endif
36
37 %ifnum Xi
38 00000004 90 nop ; yes we do, due to bad
concatenation
39 %endif
40
41 ; really?
42
43 %ifdef TRY_Xe
44 db Xe ; no, because 1# is not a number
45 %endif
46
47 %ifdef TRY_Xi
48 db Xi ; no, because 1# is not a number
49 %endif
50
51 ; EOF
|