Skip to content

Commit d7c9ae5

Browse files
authored
tweaks the grammar to handle empty files (#18)
also adds a tests to prevent regressions.
1 parent 0524ecd commit d7c9ae5

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

frontc/cparser.mly

+4-2
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,11 @@ AND_EQ PIPE_EQ CIRC_EQ INF_INF_EQ SUP_SUP_EQ
185185

186186
%%
187187

188-
interpret: file EOF {$1};
188+
interpret: file {$1};
189189

190-
file: globals EOF {List.rev $1};
190+
file:
191+
| EOF {[]}
192+
| globals EOF {List.rev $1};
191193

192194
globals:
193195
| global {[$1]}

test.t/empty.c

Whitespace-only changes.

test.t/run.t

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
$ ../printc/printc_bin.exe empty.c
2+
3+
14
$ ../printc/printc_bin.exe volatile.c
25

36
typedef int const t1;
@@ -32,6 +35,8 @@
3235

3336

3437

38+
39+
3540
$ ../printc/printc_bin.exe for.c
3641

3742
void main()
@@ -53,6 +58,8 @@
5358

5459

5560

61+
62+
5663
$ ../printc/printc_bin.exe from.c
5764

5865
void main()
@@ -85,6 +92,8 @@
8592

8693

8794

95+
96+
8897
$ ../printc/printc_bin.exe okp.c
8998

9099
typedef int j_decompress_ptr, boolean, my_main_ptr, j_decompress_ptr, size_t,

0 commit comments

Comments
 (0)