简体   繁体   English

Flex / Bison:构建示例项目以生成Cpp时出错

[英]Flex/Bison: Error when building a sample project to generate Cpp

I'm trying to generate Cpp (not C) using flex and bison. 我正在尝试使用flex和bison生成Cpp(不是C)。 I got a sample code from GitHub ( https://github.com/ezaquarii/bison-flex-cpp-example ) and trying to build it. 我从GitHub( https://github.com/ezaquarii/bison-flex-cpp-example )获得了示例代码,并尝试构建它。

Here is Makefile content 这是Makefile的内容

all:
    flex -o scanner.cpp scanner.l
    bison -o parser.cpp parser.y
    g++ -g main.cpp scanner.cpp parser.cpp interpreter.cpp command.cpp -o a.out

clean:
    rm -rf scanner.cpp
    rm -rf parser.cpp parser.hpp location.hh position.hh stack.hh
    rm -rf a.out

When I run command make , I get the following error 当运行命令make时 ,出现以下错误

flex -o scanner.cpp scanner.l
bison -o parser.cpp parser.y
"parser.y", line 29: junk after `%%' in definition section
Makefile:2: recipe for target 'all' failed
make: *** [all] Segmentation fault

Here is my bison version (Linux OS) 这是我的野牛版(Linux OS)

bison --version
bison++ Version 1.21.9-1, adapted from GNU bison by coetmeur@icdc.fr
Maintained by Magnus Ekdahl <magnus@debian.org>

May someone tell me what is going wrong ? 有人可以告诉我怎么了吗?

I updated my bison version. 我更新了野牛版本。

bison --version
bison (GNU Bison) 3.0.4
Written by Robert Corbett and Richard Stallman.

Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

@user6556709, thanks for the fix. @ user6556709,感谢您的修复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM