stmt_if.c revision 1.2 1 /* $NetBSD: stmt_if.c,v 1.2 2022/06/17 18:54:53 rillig Exp $ */
2 # 3 "stmt_if.c"
3
4 /*
5 * Test parsing of 'if' statements.
6 */
7
8 void println(const char *);
9
10 void
11 dangling_else(int x)
12 {
13 if (x > 0)
14 if (x > 10)
15 println("> 10");
16 /* This 'else' is bound to the closest unfinished 'if'. */
17 else
18 println("> 0");
19 /*
20 * If the above 'else' were bound to the other 'if', the next 'else'
21 * would have no corresponding 'if', resulting in a syntax error.
22 */
23 else
24 println("not positive");
25 /* expect+1: error: syntax error 'else' [249] */
26 else
27 println("syntax error");
28 }
29