I am having trouble using cmake, flex and bison together.
- File Structure
.
├── build
│ ├── (excluded cmake files)
├── CMakeLists.txt
├── lexer
│ ├── lexer.c
│ └── lexer.l
├── parser
│ └── parser.y
├── src
│ ├── location.hh
│ ├── parser.cpp
│ ├── parser.hpp
│ ├── position.hh
│ ├── reqLangMain.cpp
│ └── stack.hh
- CMakeLists.txt
cmake_minimum_required(VERSION 3.13.4)
project(req_lang)
find_package(BISON)
find_package(FLEX)
BISON_TARGET(reqParser
${CMAKE_SOURCE_DIR}/parser/parser.y
${CMAKE_SOURCE_DIR}/src/parser.cpp
#COMPILE_FLAGS "-L C++"
)
FLEX_TARGET(reqLexer
${CMAKE_SOURCE_DIR}/lexer/lexer.l
${CMAKE_SOURCE_DIR}/lexer/lexer.c
#COMPILE_FLAGS "--bison-bridge" #"-+"
)
ADD_FLEX_BISON_DEPENDENCY(reqLexer reqParser)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
set(SOURCES
${PROJECT_SOURCE_DIR}/src/reqLangMain.cpp
)
add_executable(${PROJECT_NAME}
${SOURCES}
${BISON_reqParser_OUTPUTS}
${FLEX_reqLexer_OUTPUTS}
)
target_link_libraries(${PROJECT_NAME}
${FLEX_LIBRARIES}
)
- lexer.l
%option noyywrap
%{
#include <stdio.h>
#include "../src/parser.hpp"
%}
%%
[[:digit:]]+ { yylval->num = atoi(yytext); return NUMBER;}
[[:alnum:]]+ { yylval->str = strdup(yytext); return STRING;}
"="|";" { return yytext[0];}
. {}
%%
- paser.y
%{
#define YYPARSE_PARAM lexer
#define YYLEX_PARAM lexer
#include <stdio.h>
#include <stdlib.h>
%}
%union {
int num;
char* str;
}
%token <str> STRING
%token <num> NUMBER
%%
assignment:
STRING '=' NUMBER ';' {
printf( "(setf %s %d)", $1, $3 );
}
;
%%
Ultimately, I keep getting (some combination of) yylex
, and yyerror
were not declared in this scope when I run cd ..; cmake -S . -B build; cd build/; make;
from the build directory.
As for what I've attempted: researched git repos with similar tags, browsed stack-overflow for similar issues, gone though flex/cmake documentation, toggling flex and bison flags -+
and --bison_bridge
.
The goal is a bison produced cpp file.
I apologize in advance if this post was lengthy or if the issue is a one-line resolution.