为什么我无法使用ANTLR4构建Code :: Blocks?

时间:2019-05-28 01:11:51

标签: c++ codeblocks antlr4

我按照此网站上的说明进行操作:

https://github.com/antlr/antlr4/blob/master/runtime/Cpp/README.md

要在C ++中使用antlr4,我安装了运行时就没有问题了。

接下来,我创建了一个简单的语法Hello.g4,并按照此站点上的说明进行操作:

https://github.com/antlr/antlr4/blob/master/doc/cpp-target.md

我使用Ubuntu 16.04和Code :: Blocks进行编程,Antlr的版本为4.7.1

接下来,我用Code :: Blocks创建了一个C ++项目,这是我的main.cpp:

#include <iostream>
#include <antlr4-runtime/antlr4-runtime.h>
#include "HelloLexer.h"
#include "HelloParser.h"
#include "HelloBaseListener.h"

using namespace std;
using namespace antlr4;

class TreeShapeListener : public HelloBaseListener {
public:
   void enterR(HelloParser::HelloContext *ctx) override {
   // Do something when entering the key rule.
   }
};

int main(int argc, const char* argv[]) {
  ANTLRFileStream input("rules.smp");
  HelloLexer lexer(&input);
  CommonTokenStream tokens(&lexer);

  tokens.fill();
  for (auto token : tokens.getTokens()) {
    cout << token->toString() << endl;
  }

  HelloParser parser(&tokens);

  tree::ParseTree *tree = parser.r();
  TreeShapeListener listener;
  tree::ParseTreeWalker::DEFAULT.walk(&listener, tree);
  cout << tree->toStringTree(&parser) << endl;
  return 0;
}

但是我无法构建项目,因为Code :: Blocks向我显示了此错误:

/usr/local/include/antlr4-runtime/misc/Interval.h:8:27: fatal error: antlr4-common.h: No such file or directory

有什么想法吗?我不明白问题所在。

0 个答案:

没有答案
相关问题