Why in my project bison file (parser.yy)can't include normal header?

Here is the error:

/home/lzx/mitscript/parser.yy:29:10: fatal error: AST.h: No such file or directory
 #include "AST.h"
          ^~~~~~~
compilation terminated.

And here is my cmake:

cmake_minimum_required(VERSION 3.16)
project(mitscript)

set(CMAKE_CXX_STANDARD 17)
find_package(BISON)
find_package(FLEX)

bison_target(Parser parser.yy ${CMAKE_CURRENT_SOURCE_DIR}/parser.cpp
        DEFINES_FILE ${CMAKE_CURRENT_SOURCE_DIR}/parser.h)
flex_target(Scanner lexer.lex ${CMAKE_CURRENT_BINARY_DIR}/lexer.cpp
        DEFINES_FILE ${CMAKE_CURRENT_SOURCE_DIR}/lexer.h)

add_flex_bison_dependency(Scanner Parser)

add_executable(mitscript main.cpp ${FLEX_Scanner_OUTPUTS} ${BISON_Parser_OUTPUTS} AST.h Visitor.h PrettyPrinter.h)

First up, all the references to CMAKE_CURRENT_SOURCE_DIR should really be CMAKE_CURRENT_BINARY_DIR. You should not generate files into the source directory, only the build directory.

Take a look at the example at the end of the FindFLEX module page. Apart from the source/binary dir problem mentioned above, there are a couple of lines your project is missing (I’ve modified the include part to use target-based includes rather than the old-style include_directories())

target_include_directories(mitscript PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
target_link_libraries(mitscript ${FLEX_LIBRARIES})

I suspect fixing the combination of the above will make things work for you.