1*148ee845SSimon J. Gerraty# $NetBSD: cond-op-parentheses.mk,v 1.7 2023/06/01 20:56:35 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). 184fde40d9SSimon J. Gerraty# 194fde40d9SSimon J. Gerraty# XXX: It's inconsistent that the right operand has unbalanced parentheses. 204fde40d9SSimon J. Gerraty# 214fde40d9SSimon 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. 43*148ee845SSimon J. Gerraty# expect+1: Malformed conditional (() 44dba7b0efSSimon J. Gerraty.if ( 45dba7b0efSSimon J. Gerraty. error 46dba7b0efSSimon J. Gerraty.else 47dba7b0efSSimon J. Gerraty. error 48dba7b0efSSimon J. Gerraty.endif 49dba7b0efSSimon J. Gerraty 50dba7b0efSSimon J. Gerraty# An unbalanced closing parenthesis is a parse error. 51dba7b0efSSimon J. Gerraty# 529f45a3c8SSimon J. Gerraty# Before cond.c 1.237 from 2021-01-19, CondParser_Term returned TOK_RPAREN 539f45a3c8SSimon J. Gerraty# even though the documentation of that function promised to only ever return 549f45a3c8SSimon J. Gerraty# TOK_TRUE, TOK_FALSE or TOK_ERROR. In cond.c 1.241, the return type of that 559f45a3c8SSimon J. Gerraty# function was changed to a properly restricted enum type, to prevent this bug 569f45a3c8SSimon J. Gerraty# from occurring again. 57*148ee845SSimon J. Gerraty# expect+1: Malformed conditional ()) 58dba7b0efSSimon J. Gerraty.if ) 59dba7b0efSSimon J. Gerraty. error 60dba7b0efSSimon J. Gerraty.else 61dba7b0efSSimon J. Gerraty. error 62dba7b0efSSimon J. Gerraty.endif 63dba7b0efSSimon J. Gerraty 642c3632d1SSimon J. Gerratyall: 652c3632d1SSimon J. Gerraty @:; 66