1*4fde40d9SSimon J. Gerraty# $NetBSD: cond-op-parentheses.mk,v 1.6 2022/09/04 22:55:00 rillig Exp $ 22c3632d1SSimon J. Gerraty# 39f45a3c8SSimon J. Gerraty# Tests for parentheses in .if conditions, which group expressions to override 49f45a3c8SSimon J. Gerraty# the precedence of the operators '!', '&&' and '||'. Parentheses cannot be 59f45a3c8SSimon J. Gerraty# used to form arithmetic expressions such as '(3+4)' though. 62c3632d1SSimon J. Gerraty 79f45a3c8SSimon J. Gerraty# Contrary to the C family of programming languages, the outermost condition 89f45a3c8SSimon J. Gerraty# does not have to be enclosed in parentheses. 99f45a3c8SSimon J. Gerraty.if defined(VAR) 109f45a3c8SSimon J. Gerraty. error 119f45a3c8SSimon J. Gerraty.elif !1 129f45a3c8SSimon J. Gerraty. error 139f45a3c8SSimon J. Gerraty.endif 149f45a3c8SSimon J. Gerraty 159f45a3c8SSimon J. Gerraty# Parentheses cannot enclose numbers as there is no need for it. Make does 169f45a3c8SSimon J. Gerraty# not implement any arithmetic functions in its condition parser. If 179f45a3c8SSimon J. Gerraty# absolutely necessary, use expr(1). 18*4fde40d9SSimon J. Gerraty# 19*4fde40d9SSimon J. Gerraty# XXX: It's inconsistent that the right operand has unbalanced parentheses. 20*4fde40d9SSimon J. Gerraty# 21*4fde40d9SSimon J. Gerraty# expect+1: Comparison with '>' requires both operands '3' and '(2' to be numeric 229f45a3c8SSimon J. Gerraty.if 3 > (2) 239f45a3c8SSimon J. Gerraty.endif 249f45a3c8SSimon J. Gerraty# expect+1: Malformed conditional ((3) > 2) 259f45a3c8SSimon J. Gerraty.if (3) > 2 269f45a3c8SSimon J. Gerraty.endif 272c3632d1SSimon J. Gerraty 28e2eeea75SSimon J. Gerraty# Test for deeply nested conditions. 29e2eeea75SSimon J. Gerraty.if (((((((((((((((((((((((((((((((((((((((((((((((((((((((( \ 30e2eeea75SSimon J. Gerraty (((((((((((((((((((((((((((((((((((((((((((((((((((((((( \ 31e2eeea75SSimon J. Gerraty 1 \ 32e2eeea75SSimon J. Gerraty )))))))))))))))))))))))))))))))))))))))))))))))))))))))) \ 33e2eeea75SSimon J. Gerraty )))))))))))))))))))))))))))))))))))))))))))))))))))))))) 349f45a3c8SSimon J. Gerraty# Parentheses can be nested at least to depth 112. There is nothing special 359f45a3c8SSimon J. Gerraty# about this number though, much higher numbers work as well, at least on 369f45a3c8SSimon J. Gerraty# NetBSD. The actual limit depends on the allowed call stack depth for C code 379f45a3c8SSimon J. Gerraty# of the platform. Anyway, 112 should be enough for all practical purposes. 38e2eeea75SSimon J. Gerraty.else 39e2eeea75SSimon J. Gerraty. error 40e2eeea75SSimon J. Gerraty.endif 41e2eeea75SSimon J. Gerraty 42dba7b0efSSimon J. Gerraty# An unbalanced opening parenthesis is a parse error. 43dba7b0efSSimon J. Gerraty.if ( 44dba7b0efSSimon J. Gerraty. error 45dba7b0efSSimon J. Gerraty.else 46dba7b0efSSimon J. Gerraty. error 47dba7b0efSSimon J. Gerraty.endif 48dba7b0efSSimon J. Gerraty 49dba7b0efSSimon J. Gerraty# An unbalanced closing parenthesis is a parse error. 50dba7b0efSSimon J. Gerraty# 519f45a3c8SSimon J. Gerraty# Before cond.c 1.237 from 2021-01-19, CondParser_Term returned TOK_RPAREN 529f45a3c8SSimon J. Gerraty# even though the documentation of that function promised to only ever return 539f45a3c8SSimon J. Gerraty# TOK_TRUE, TOK_FALSE or TOK_ERROR. In cond.c 1.241, the return type of that 549f45a3c8SSimon J. Gerraty# function was changed to a properly restricted enum type, to prevent this bug 559f45a3c8SSimon J. Gerraty# from occurring again. 56dba7b0efSSimon J. Gerraty.if ) 57dba7b0efSSimon J. Gerraty. error 58dba7b0efSSimon J. Gerraty.else 59dba7b0efSSimon J. Gerraty. error 60dba7b0efSSimon J. Gerraty.endif 61dba7b0efSSimon J. Gerraty 622c3632d1SSimon J. Gerratyall: 632c3632d1SSimon J. Gerraty @:; 64