- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在学习 cmake 和 flex-lexer,但根据 make 的错误消息,我遇到错误代码为 2 的构建问题:
$ make
/usr/bin/cmake -H/home/dac/ClionProjects/openshell -B/home/dac/ClionProjects/openshell --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /home/dac/ClionProjects/openshell/CMakeFiles /home/dac/ClionProjects/openshell/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/dac/ClionProjects/openshell'
make -f CMakeFiles/lemon.dir/build.make CMakeFiles/lemon.dir/depend
make[2]: Entering directory '/home/dac/ClionProjects/openshell'
cd /home/dac/ClionProjects/openshell && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/dac/ClionProjects/openshell /home/dac/ClionProjects/openshell /home/dac/ClionProjects/openshell /home/dac/ClionProjects/openshell /home/dac/ClionProjects/openshell/CMakeFiles/lemon.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/home/dac/ClionProjects/openshell'
make -f CMakeFiles/lemon.dir/build.make CMakeFiles/lemon.dir/build
make[2]: Entering directory '/home/dac/ClionProjects/openshell'
make[2]: Nothing to be done for 'CMakeFiles/lemon.dir/build'.
make[2]: Leaving directory '/home/dac/ClionProjects/openshell'
/usr/bin/cmake -E cmake_progress_report /home/dac/ClionProjects/openshell/CMakeFiles 1
[ 14%] Built target lemon
make -f CMakeFiles/openshell.dir/build.make CMakeFiles/openshell.dir/depend
make[2]: Entering directory '/home/dac/ClionProjects/openshell'
/usr/bin/cmake -E cmake_progress_report /home/dac/ClionProjects/openshell/CMakeFiles 2
[ 28%] [FLEX][openshell] Building scanner with flex 2.5.39
/usr/bin/flex -oshellparser.c shellscanner.l
cd /home/dac/ClionProjects/openshell && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/dac/ClionProjects/openshell /home/dac/ClionProjects/openshell /home/dac/ClionProjects/openshell /home/dac/ClionProjects/openshell /home/dac/ClionProjects/openshell/CMakeFiles/openshell.dir/DependInfo.cmake --color=
Scanning dependencies of target openshell
make[2]: Leaving directory '/home/dac/ClionProjects/openshell'
make -f CMakeFiles/openshell.dir/build.make CMakeFiles/openshell.dir/build
make[2]: Entering directory '/home/dac/ClionProjects/openshell'
/usr/bin/cmake -E cmake_progress_report /home/dac/ClionProjects/openshell/CMakeFiles 3
[ 42%] Building C object CMakeFiles/openshell.dir/shellparser.c.o
/usr/bin/cc -Wall -Werror -O3 -std=c99 -I/usr/include/readline -o CMakeFiles/openshell.dir/shellparser.c.o -c /home/dac/ClionProjects/openshell/shellparser.c
shellparser.c: In function ‘yy_init_buffer’:
shellparser.c:1432:48: error: implicit declaration of function ‘fileno’ [-Werror=implicit-function-declaration]
b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0;
^
shellscanner.l: At top level:
shellparser.c:1181:17: error: ‘yyunput’ defined but not used [-Werror=unused-function]
static void yyunput (int c, register char * yy_bp , yyscan_t yyscanner)
^
shellparser.c:1223:16: error: ‘input’ defined but not used [-Werror=unused-function]
static int input (yyscan_t yyscanner)
^
cc1: all warnings being treated as errors
CMakeFiles/openshell.dir/build.make:62: recipe for target 'CMakeFiles/openshell.dir/shellparser.c.o' failed
make[2]: *** [CMakeFiles/openshell.dir/shellparser.c.o] Error 1
make[2]: Leaving directory '/home/dac/ClionProjects/openshell'
CMakeFiles/Makefile2:98: recipe for target 'CMakeFiles/openshell.dir/all' failed
make[1]: *** [CMakeFiles/openshell.dir/all] Error 2
make[1]: Leaving directory '/home/dac/ClionProjects/openshell'
Makefile:78: recipe for target 'all' failed
make: *** [all] Error 2
我的构建文件是
cmake_minimum_required(VERSION 3.0)
project(openshell)
find_package(FLEX)
FLEX_TARGET(openshell shellscanner.l shellparser.c)
add_executable(openshell shellparser.c ${FLEX_ShellScanner_OUTPUTS} main.c openshell.h errors.c errors.h util.c util.h stack.c stack.h shellscanner.l shellscanner.h)
set(CMAKE_VERBOSE_MAKEFILE on)
include_directories(/usr/include/readline)
#### Lemon bootstrap ####
ADD_EXECUTABLE(lemon lemon.c)
file(GLOB SOURCES "./*.c")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror -O3 -std=c99")
target_link_libraries(openshell ${READLINE_LIBRARY} ${FLEX_LIBRARIES})
我必须更改编译器选项吗?我的文件结构是:
$ tree
.
├── CMakeCache.txt
├── CMakeFiles
│ ├── 3.2.2
│ │ ├── CMakeCCompiler.cmake
│ │ ├── CMakeCXXCompiler.cmake
│ │ ├── CMakeDetermineCompilerABI_C.bin
│ │ ├── CMakeDetermineCompilerABI_CXX.bin
│ │ ├── CMakeSystem.cmake
│ │ ├── CompilerIdC
│ │ │ ├── a.out
│ │ │ └── CMakeCCompilerId.c
│ │ └── CompilerIdCXX
│ │ ├── a.out
│ │ └── CMakeCXXCompilerId.cpp
│ ├── cmake.check_cache
│ ├── CMakeDirectoryInformation.cmake
│ ├── CMakeOutput.log
│ ├── CMakeRuleHashes.txt
│ ├── CMakeTmp
│ ├── feature_tests.bin
│ ├── feature_tests.c
│ ├── feature_tests.cxx
│ ├── lemon.dir
│ │ ├── build.make
│ │ ├── C.includecache
│ │ ├── cmake_clean.cmake
│ │ ├── DependInfo.cmake
│ │ ├── depend.internal
│ │ ├── depend.make
│ │ ├── flags.make
│ │ ├── lemon.c.o
│ │ ├── link.txt
│ │ └── progress.make
│ ├── Makefile2
│ ├── Makefile.cmake
│ ├── openshell.dir
│ │ ├── build.make
│ │ ├── C.includecache
│ │ ├── cmake_clean.cmake
│ │ ├── DependInfo.cmake
│ │ ├── depend.internal
│ │ ├── depend.make
│ │ ├── flags.make
│ │ ├── flex
│ │ │ ├── lemon.c.o
│ │ │ └── shellparser.c.o
│ │ ├── lemon.c.o
│ │ ├── link.txt
│ │ ├── progress.make
│ │ ├── stack.c.o
│ │ └── util.c.o
│ ├── parser.dir
│ │ ├── build.make
│ │ ├── cmake_clean.cmake
│ │ ├── DependInfo.cmake
│ │ ├── depend.internal
│ │ ├── depend.make
│ │ └── progress.make
│ ├── Progress
│ │ ├── 1
│ │ ├── 2
│ │ ├── 3
│ │ └── count.txt
│ ├── progress.marks
│ └── TargetDirectories.txt
├── cmake_install.cmake
├── CMakeLists.txt
├── digenv.c
├── errors.c
├── errors.h
├── example.c
├── example.h
├── flex
│ ├── digenv.c
│ ├── errors.c
│ ├── errors.h
│ ├── example.c
│ ├── example.h
│ ├── lemon
│ ├── lemon.c
│ ├── lempar.c
│ ├── lex.yy.c
│ ├── main.c
│ ├── main.c~
│ ├── main.h
│ ├── main.o
│ ├── Makefile
│ ├── Makefile~
│ ├── miniShell2.c
│ ├── openshell
│ ├── openshell.c
│ ├── openshell.h
│ ├── openshell.l
│ ├── pipeline.c
│ ├── README.md
│ ├── shell
│ ├── shellparser.c
│ ├── shellparser.h
│ ├── shellparser.hpp
│ ├── shellparser.o
│ ├── shellparser.out
│ ├── shellparser.y
│ ├── shellparser.y~
│ ├── shellscanner.h
│ ├── shellscanner.l
│ ├── shellscanner.o
│ ├── snazzle
│ ├── util.c
│ └── util.h
├── lemon
├── lemon.c
├── lempar.c
├── lex.yy.c
├── main.c
├── main.h
├── main.o
├── Makefile
├── miniShell2.c
├── openshell
├── openshell.c
├── openshell.h
├── pipeline.c
├── README.md
├── shellparser.c
├── shellparser.h
├── shellparser.hpp
├── shellparser.o
├── shellparser.out
├── shellparser.y
├── shellscanner.h
├── shellscanner.l
├── shellscanner.o
├── snazzle
├── snazzle.l~
├── stack.c
├── stack.h
├── util.c
└── util.h
11 directories, 127 files
dac@dac-Latitude-E7450:~/ClionProjects/openshell$
我的 flex 语法是
%include {
#include <stdio.h>
#include <assert.h>
}
%token_type {const char*}
%syntax_error
{
fprintf(stderr, "Error parsing command\n");
}
start ::= in .
in ::= .
in ::= in commandList EOL .
{
printf("in ::= in commandList EOL .\n");
printf("> ");
}
commandList ::= command PIPE commandList .
{
printf("commandList ::= command PIPE commandList .\n");
}
commandList ::= command .
{
printf("commandList ::= command .\n");
}
command ::= FILENAME argumentList .
{
printf("command ::= FILENAME argumentList .\n");
}
command ::= FILENAME .
{
printf("command ::= FILENAME .\n");
}
argumentList ::= argument argumentList .
{
printf("argumentList ::= argument argumentList .\n");
}
argumentList ::= argument .
{
printf("argumentList ::= argument .\n");
}
argument ::= ARGUMENT .
{
printf("argument ::= ARGUMENT .\n");
}
argument ::= FILENAME .
{
printf("argument ::= FILENAME .\n");
}
最佳答案
-Wall
和 -Werror
在编译器标志中的组合对于 flex 生成的代码来说太严格了。您可以通过添加更多选项告诉编译器将特定错误视为常规警告:
-Wno-error=implicit-function-declaration
-Wno-error=unused-function
基本上只是将 no-
插入到编译器打印的 -Werror=
诊断中。
最佳做法是只将这些编译器选项添加到 flex 生成的特定源文件,而不是整个项目。在您的情况下,它可能看起来像这样:
set_source_files_properties(shellparser.c PROPERTIES COMPILE_FLAGS
-Wno-error=implicit-function-declaration
-Wno-error=unused-function
)
或者如果你想完全避免这个文件的警告,这可能是个好主意,这样你就不会习惯于容忍警告:
set_source_files_properties(shellparser.c PROPERTIES COMPILE_FLAGS
-Wno-implicit-function-declaration
-Wno-unused-function
)
最后,您实际上可以通过在 flex 语法文件的顶部添加以下代码来解决未声明的 fileno
问题:
%{
#include <stdio.h>
%}
关于c - 使用 flex-lexer 和 cmake 构建错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36685457/
我正在尝试从 https://github.com/antlr/grammars-v4/tree/master/mysql 处的 MySQL .g4 文件构建解析器和词法分析器。 。我收到错误“词法分
我正在学习 ANTLR4 并尝试使用词汇模式。如何让相同的标记出现在多个词法模式中?作为一个非常简单的例子,假设我的语法有两种模式,我想在这两种模式中匹配空格和行尾,例如我怎么能不以 WS_MODE1
我有一个扫描仪dice notation 使用以下扫描器 %option debug %option noyywrap %option yylineno %{ #include #includ
默认情况下,flex使用最长匹配规则。 有什么方法可以覆盖此行为以使其与最短序列匹配? 谢谢 最佳答案 Flex手册中的This page表示它没有任何非贪婪的运算符,因为它是扫描程序而不是解析程序,
我正在为tcpdump日志编写一个简单的解析器,能否请您告诉我为什么我无法获得正确的行号? %{ char str[80]; %} %option yylineno ... %% ^{HOURS}:{
我想在flex中制定一条规则,以使用像/ * * /这样的c样式注释 我有以下 c_comment "/*"[\n.]*"*/" 但是它永远不会匹配。知道为什么吗?如果您需要更多我的代码,请告诉我,我
解析数字和字符串是词法分析器的工作吗? 考虑到我在询问词法分析器是否应该解析输入这一事实,这可能听起来也可能不愚蠢。但是,我不确定这实际上是词法分析器的工作还是解析器的工作,因为为了正确地进行词法分析
我想为嵌套 block 语法编写一个简单 解析器,只是分层纯文本。例如: Some regular text. This is outputted as-is, foo{but THIS is ins
正在使用编译器,我想打印出符号表。我有一个节点结构,我需要访问全局变量“lineCount”。当我尝试在 idPush 函数中打印它时,出现段错误。我的目标是将节点放置在数组中或链接在一起,然后打印表
我正在寻求有关自定义构建的 Lexer 类并使用它来解析输入的帮助。我们的教授为我们的项目提供了一些框架代码,我们必须使用它。我的问题是,我们需要能够一次调用多个函数来对表进行排序和合并/排序单独表的
我正在尝试用 C# 编写一个非常简单的解析器。 我需要一个词法分析器——它可以让我将正则表达式与标记相关联,因此它会读取正则表达式并返回符号。 似乎我应该能够使用 Regex 来完成实际的繁重工作,但
我正在尝试使用 Antlr 4.7 创建具有多种模式的词法分析器。我的词法分析器目前是: ACTIONONLY : 'AO'; BELIEFS : ':Initial Beliefs:' ->
似乎有时 Antlr 词法分析器在标记字符流时对使用哪个规则做出了错误的选择......我试图弄清楚如何帮助 Antlr 做出显而易见的正确选择。我想像这样解析文本: d/dt(x)=a a=d/dt
这是八进制值的示例规则。我不想使用 YYTEXT,而是在结尾处获取值、字母和 # (8,...64)。我怎样才能得到它们?我猜 printf("%s", $1) 来看看我是否能得到这个值,但 lex
这种语法之间有什么区别: ... if_statement : 'if' condition 'then' statement 'else' statement 'end_if'; ... 和这个:
我使用 flex 在扫描仪上工作,将 \" 替换为 ";和 \\ 与 \。 所以我的代码是这样的 %% \\" \"; \\\ \\; 但是当我编译时,我收到一条错误消息,如 missin
根据manual YY_BUF_SIZE 是 16K 我们需要覆盖它。但是,手册没有指定如何覆盖它,我也找不到任何命令行选项。有人可以指出如何更改此设置。在生成的源代码中,YY_BUF_SIZE定义如
我有一个简单的“语言”,我正在使用 Flex(词法分析器),如下所示: /* Just like UNIX wc */ %{ int chars = 0; int words = 0; int lin
我正在使用 flex (词法分析器,而不是 Adobe Flex)在一个项目上。但是,我也希望能够在 Windows 平台上进行编译,但是 Windows version的最新版本只有 2.5.4
当我在 CMD 提示符下运行 .jar 文件时,出现以下错误: C:\Users\Mikael\My Documents\NetBeansProjects\cs413CompilerProject\d
我是一名优秀的程序员,十分优秀!