| @@ -1,29 +1,50 @@ | | | @@ -1,29 +1,50 @@ |
1 | /* $NetBSD: psym_for_exprs.c,v 1.4 2022/04/24 09:04:12 rillig Exp $ */ | | 1 | /* $NetBSD: psym_for_exprs.c,v 1.5 2023/05/15 08:22:23 rillig Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Tests for the parser state psym_for_exprs, which represents the state after | | 4 | * Tests for the parser state psym_for_exprs, which represents the state after |
5 | * reading the keyword 'for' and the 3 expressions, now waiting for the body | | 5 | * reading the keyword 'for' and the 3 expressions, now waiting for the body |
6 | * of the loop. | | 6 | * of the loop. |
7 | */ | | 7 | */ |
8 | | | 8 | |
9 | //indent input | | 9 | //indent input |
10 | // TODO: add input | | 10 | void |
| | | 11 | for_loops(void) |
| | | 12 | { |
| | | 13 | for (int i = 0; i < 10; i++) |
| | | 14 | printf("%d * %d = %d\n", i, 7, i * 7); |
| | | 15 | |
| | | 16 | for (int i = 0; i < 10; i++) { |
| | | 17 | printf("%d * %d = %d\n", i, 7, i * 7); |
| | | 18 | } |
| | | 19 | } |
11 | //indent end | | 20 | //indent end |
12 | | | 21 | |
13 | //indent run-equals-input | | 22 | //indent run |
| | | 23 | void |
| | | 24 | for_loops(void) |
| | | 25 | { |
| | | 26 | for (int i = 0; i < 10; i++) |
| | | 27 | printf("%d * %d = %d\n", i, 7, i * 7); |
| | | 28 | |
| | | 29 | /* $ FIXME: Add space between ')' and '{'. */ |
| | | 30 | for (int i = 0; i < 10; i++){ |
| | | 31 | printf("%d * %d = %d\n", i, 7, i * 7); |
| | | 32 | } |
| | | 33 | } |
| | | 34 | //indent end |
14 | | | 35 | |
15 | | | 36 | |
16 | /* | | 37 | /* |
17 | * Since C99, the first expression of a 'for' loop may be a declaration, not | | 38 | * Since C99, the first expression of a 'for' loop may be a declaration, not |
18 | * only an expression. | | 39 | * only an expression. |
19 | */ | | 40 | */ |
20 | //indent input | | 41 | //indent input |
21 | void | | 42 | void |
22 | function(void) | | 43 | small_scope(void) |
23 | { | | 44 | { |
24 | for (int i = 0; i < 3; i++) | | 45 | for (int i = 0; i < 3; i++) |
25 | stmt(); | | 46 | stmt(); |
26 | } | | 47 | } |
27 | //indent end | | 48 | //indent end |
28 | | | 49 | |
29 | //indent run-equals-input | | 50 | //indent run-equals-input |