Skip to content

Commit 8d45972

Browse files
committed
Add flex+bison test case.
1 parent ccf6345 commit 8d45972

File tree

5 files changed

+79
-0
lines changed

5 files changed

+79
-0
lines changed

test cases/frameworks/8 flex/lexer.l

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
%{
2+
#include <stdlib.h>
3+
#include "parser.tab.h"
4+
%}
5+
6+
%%
7+
("true"|"false") {return BOOLEAN;}
8+
. { yyerror(); }
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
project('flex and bison', 'c')
2+
3+
# The point of this test is that one generator
4+
# may output headers that are necessary to build
5+
# the sources of a different generator.
6+
7+
flex = find_program('flex')
8+
bison = find_program('bison')
9+
10+
lgen = generator(flex,
11+
output : '@PLAINNAME@.yy.c',
12+
arguments : ['-o', '@OUTPUT@', '@INPUT@'])
13+
14+
lfiles = lgen.process('lexer.l')
15+
16+
pgen = generator(bison,
17+
output : ['@BASENAME@.tab.c', '@BASENAME@.tab.h'],
18+
arguments : ['@INPUT@', '--defines=@OUTPUT1@', '--output=@OUTPUT0@'])
19+
20+
pfiles = pgen.process('parser.y')
21+
22+
e = executable('pgen', 'prog.c',
23+
lfiles, pfiles)
24+
25+
test('parsertest', e)
26+

test cases/frameworks/8 flex/parser.y

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
%token BOOLEAN
2+
3+
%%
4+
input:
5+
BOOLEAN { $$ = $1;}
6+
;

test cases/frameworks/8 flex/prog.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include"parser.tab.h"
2+
#include<unistd.h>
3+
#include<sys/types.h>
4+
#include<sys/stat.h>
5+
#include<fcntl.h>
6+
#include<stdio.h>
7+
#include<stdlib.h>
8+
9+
int main(int argc, char **argv) {
10+
/*
11+
int input;
12+
if(argc != 2) {
13+
printf("%s <input file>");
14+
return 1;
15+
}
16+
input = open(argv[1], O_RDONLY);
17+
dup2(input, STDIN_FILENO);
18+
close(input);
19+
return yyparse();
20+
*/
21+
/* We really should test that the
22+
* generated parser works with input
23+
* but it froze and I don't want to waste
24+
* time debugging that. For this test what
25+
* we care about is that it compiles and links.
26+
*/
27+
void* __attribute__((unused)) dummy = (void*)yyparse;
28+
return 0;
29+
}
30+
31+
int yywrap(void) {
32+
return 0;
33+
}
34+
35+
int yyerror(void) {
36+
printf("Parse error\n");
37+
exit(1);
38+
}

test cases/frameworks/8 flex/test.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
true

0 commit comments

Comments
 (0)