18.3 Invocation (4tH script). 4tH 4tH Forth compiler
โฆษณา
โฆษณา
CHAPTER 18. PREPROCESSOR MANUAL hello’s 10
364
It is even powerful enough to resolve a CASE..ENDCASE construct:
:macro case >>> 0 ;
:macro of over = if drop ;
:macro endof else >>> 1 @add ;
:macro endif @if then >>> -1 @add endif ;
:macro endcase drop endif @drop ;
: .WEEKDAY ( daynum --- )
CASE
1 OF ." Sunday"
2 OF ." Monday"
ENDOF
ENDOF
3 OF ." Tuesday" ENDOF
4 OF ." Wednesday" ENDOF
5 OF ." Thursday" ENDOF
6 OF ." Friday" ENDOF
7 OF ." Saturday" ENDOF
ENDCASE ;
With @minus you can negate a number on the stack, so subtractions are possible too.
Multiplications can also be performed by using @mul. Divisions are supported by the
@divrm function, which leaves the division and modulo on the stack. If you want to evaluate the result of an arithmetic expression, you can use @sign. @sign returns -1 when the top of the string stack is negative, 1 when it is positive and else zero. It closely resembles the [SIGN] directive of 4tH.
@cell will leave a true flag on the stack if the top of the stack can be converted to a number. Some stack instructions are provided as well, like @drop, @dup, @nip and
@over . They work exactly like their 4tH counterparts. @cr simply issues a newline.
The most elusive function may be @eval. If the top of the string stack contains the name of a user-defined macro, it will be executed. If it doesn’t, the top of the stack is simply printed. You can use this function to interpret a string of user-defined macro’s or simply print the top of the stack.
You can check the existence of a user-defined macro with @exist, which leaves a nonzero value if the top of the string stack is the name of a user-defined macro. Finally,
@match will compare the two topmost items on the string stack and leave a zero value if they match.
18.3
Invocation (4tH script)
Since the preprocessor is written in 4tH, you can invoke it in the usual way:
4th cxq pp4th.4th mysource.4pp mysource.4th
You can also use make, see section 25.11. Note the preprocessor uses the DIR4TH environment variable to locate include files.
18.3.1
Options
The preprocessor supports the following options:
ดาวน์โหลด
โฆษณา