blob: d36532675c29b1ca6900636872e95f28c02c17a0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
/* $NetBSD: psym_else.c,v 1.7 2023/06/16 23:19:01 rillig Exp $ */
/*
* Tests for the parser symbol psym_else, which represents the keyword 'else'
* that is being shifted on the parser stack.
*
* This parser symbol never ends up on the stack itself.
*/
/*
* When parsing nested incomplete 'if' statements, the problem of the
* 'dangling else' occurs. It is resolved by binding the 'else' to the
* innermost incomplete 'if' statement.
*
* In 'parse', an if_expr_stmt is reduced to a simple statement, unless the
* next token is 'else'. The comment does not influence this since it never
* reaches 'parse'.
*/
//indent input
void
example(bool cond)
{
if (cond)
if (cond)
if (cond)
stmt();
else
stmt();
/* comment */
else
stmt();
}
//indent end
//indent run
void
example(bool cond)
{
if (cond)
if (cond)
if (cond)
stmt();
else
stmt();
/* comment */
else
stmt();
}
//indent end
/*
* The keyword 'else' is followed by an expression, as opposed to 'if', which
* is followed by a parenthesized expression.
*/
//indent input
void
function(void)
{
if(var>0)var=0;else(var=3);
}
//indent end
//indent run
void
function(void)
{
if (var > 0)
var = 0;
else
(var = 3);
}
//indent end
//indent input
{
else
}
//indent end
//indent run
{
else
}
// exit 1
// error: Standard Input:2: Unmatched 'else'
//indent end
|