cond-op-parentheses.mk revision 1.6 1 1.6 rillig # $NetBSD: cond-op-parentheses.mk,v 1.6 2022/09/04 22:55:00 rillig Exp $
2 1.1 rillig #
3 1.5 rillig # Tests for parentheses in .if conditions, which group expressions to override
4 1.5 rillig # the precedence of the operators '!', '&&' and '||'. Parentheses cannot be
5 1.5 rillig # used to form arithmetic expressions such as '(3+4)' though.
6 1.1 rillig
7 1.5 rillig # Contrary to the C family of programming languages, the outermost condition
8 1.5 rillig # does not have to be enclosed in parentheses.
9 1.5 rillig .if defined(VAR)
10 1.5 rillig . error
11 1.5 rillig .elif !1
12 1.5 rillig . error
13 1.5 rillig .endif
14 1.5 rillig
15 1.5 rillig # Parentheses cannot enclose numbers as there is no need for it. Make does
16 1.5 rillig # not implement any arithmetic functions in its condition parser. If
17 1.5 rillig # absolutely necessary, use expr(1).
18 1.6 rillig #
19 1.6 rillig # XXX: It's inconsistent that the right operand has unbalanced parentheses.
20 1.6 rillig #
21 1.6 rillig # expect+1: Comparison with '>' requires both operands '3' and '(2' to be numeric
22 1.5 rillig .if 3 > (2)
23 1.5 rillig .endif
24 1.5 rillig # expect+1: Malformed conditional ((3) > 2)
25 1.5 rillig .if (3) > 2
26 1.5 rillig .endif
27 1.1 rillig
28 1.3 rillig # Test for deeply nested conditions.
29 1.3 rillig .if (((((((((((((((((((((((((((((((((((((((((((((((((((((((( \
30 1.3 rillig (((((((((((((((((((((((((((((((((((((((((((((((((((((((( \
31 1.3 rillig 1 \
32 1.3 rillig )))))))))))))))))))))))))))))))))))))))))))))))))))))))) \
33 1.3 rillig ))))))))))))))))))))))))))))))))))))))))))))))))))))))))
34 1.5 rillig # Parentheses can be nested at least to depth 112. There is nothing special
35 1.5 rillig # about this number though, much higher numbers work as well, at least on
36 1.5 rillig # NetBSD. The actual limit depends on the allowed call stack depth for C code
37 1.5 rillig # of the platform. Anyway, 112 should be enough for all practical purposes.
38 1.3 rillig .else
39 1.3 rillig . error
40 1.3 rillig .endif
41 1.3 rillig
42 1.4 rillig # An unbalanced opening parenthesis is a parse error.
43 1.4 rillig .if (
44 1.4 rillig . error
45 1.4 rillig .else
46 1.4 rillig . error
47 1.4 rillig .endif
48 1.4 rillig
49 1.4 rillig # An unbalanced closing parenthesis is a parse error.
50 1.4 rillig #
51 1.5 rillig # Before cond.c 1.237 from 2021-01-19, CondParser_Term returned TOK_RPAREN
52 1.5 rillig # even though the documentation of that function promised to only ever return
53 1.5 rillig # TOK_TRUE, TOK_FALSE or TOK_ERROR. In cond.c 1.241, the return type of that
54 1.5 rillig # function was changed to a properly restricted enum type, to prevent this bug
55 1.5 rillig # from occurring again.
56 1.4 rillig .if )
57 1.4 rillig . error
58 1.4 rillig .else
59 1.4 rillig . error
60 1.4 rillig .endif
61 1.4 rillig
62 1.1 rillig all:
63 1.1 rillig @:;
64