parent
ccf63459c6
commit
8d45972ee3
5 changed files with 79 additions and 0 deletions
@ -0,0 +1,8 @@ |
||||
%{ |
||||
#include <stdlib.h> |
||||
#include "parser.tab.h" |
||||
%} |
||||
|
||||
%% |
||||
("true"|"false") {return BOOLEAN;} |
||||
. { yyerror(); } |
@ -0,0 +1,26 @@ |
||||
project('flex and bison', 'c') |
||||
|
||||
# The point of this test is that one generator |
||||
# may output headers that are necessary to build |
||||
# the sources of a different generator. |
||||
|
||||
flex = find_program('flex') |
||||
bison = find_program('bison') |
||||
|
||||
lgen = generator(flex, |
||||
output : '@PLAINNAME@.yy.c', |
||||
arguments : ['-o', '@OUTPUT@', '@INPUT@']) |
||||
|
||||
lfiles = lgen.process('lexer.l') |
||||
|
||||
pgen = generator(bison, |
||||
output : ['@BASENAME@.tab.c', '@BASENAME@.tab.h'], |
||||
arguments : ['@INPUT@', '--defines=@OUTPUT1@', '--output=@OUTPUT0@']) |
||||
|
||||
pfiles = pgen.process('parser.y') |
||||
|
||||
e = executable('pgen', 'prog.c', |
||||
lfiles, pfiles) |
||||
|
||||
test('parsertest', e) |
||||
|
@ -0,0 +1,6 @@ |
||||
%token BOOLEAN |
||||
|
||||
%% |
||||
input: |
||||
BOOLEAN { $$ = $1;} |
||||
; |
@ -0,0 +1,38 @@ |
||||
#include"parser.tab.h" |
||||
#include<unistd.h> |
||||
#include<sys/types.h> |
||||
#include<sys/stat.h> |
||||
#include<fcntl.h> |
||||
#include<stdio.h> |
||||
#include<stdlib.h> |
||||
|
||||
int main(int argc, char **argv) { |
||||
/*
|
||||
int input; |
||||
if(argc != 2) { |
||||
printf("%s <input file>"); |
||||
return 1; |
||||
} |
||||
input = open(argv[1], O_RDONLY); |
||||
dup2(input, STDIN_FILENO); |
||||
close(input); |
||||
return yyparse(); |
||||
*/ |
||||
/* We really should test that the
|
||||
* generated parser works with input |
||||
* but it froze and I don't want to waste |
||||
* time debugging that. For this test what |
||||
* we care about is that it compiles and links. |
||||
*/ |
||||
void* __attribute__((unused)) dummy = (void*)yyparse; |
||||
return 0; |
||||
} |
||||
|
||||
int yywrap(void) { |
||||
return 0; |
||||
} |
||||
|
||||
int yyerror(void) { |
||||
printf("Parse error\n"); |
||||
exit(1); |
||||
} |
@ -0,0 +1 @@ |
||||
true |
Loading…
Reference in new issue