在 Eclipse Luna (4.4) 上设置 ANTLR 4 IDE 时遇到问题 [英] Trouble Setting Up ANTLR 4 IDE on Eclipse Luna (4.4)

查看:27
本文介绍了在 Eclipse Luna (4.4) 上设置 ANTLR 4 IDE 时遇到问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Eclipse Luna (4.4) 上安装 ANTLR 4 IDE.我已经从 Marketplace 安装了它,但我不知道如何创建一个包含 ANTLR 4 Lexer/Parser 的项目.

I'm trying to install the ANTLR 4 IDE on Eclipse Luna (4.4). I've installed it from the Marketplace but I have no idea how to create a project that has an ANTLR 4 Lexer/Parser in it.

当我去创建一个新项目时,我没有看到 ANTLR 4 的任何选项.我尝试创建一个 .g4 文件,它在编辑器中打开,但当我保存它时,它什么也没做.

When I go to create a new project I don't see any options for ANTLR 4. I tried creating a .g4 file and it opens in the editor but when I save it doesn't do anything.

推荐答案

我环顾了整个互联网,找到了一些我拼凑起来的资源,并通过反复试验找到了解决方案.下面是我在我的几台机器上使用的指南,用于在 Eclipse 中设置 ANTLR 4 IDE.我想我应该在这里分享它并为其他人省去 Google 搜索数小时的麻烦(希望如此)

I looked around all over the internet and found a handful of resources that I cobbled together and found a solution by trial and error. Below is a guide that I've used on a few of my machines to get ANTLR 4 IDE setup in Eclipse. I figured I should share it here and save others the trouble of Google searching for hours (hopefully)

先决条件

  • Eclipse 4.4 Luna Xtext Complete SDK(需要 2.7.3 版)
  • Eclipse Faceted 项目框架(使用 3.4.0 测试)Eclipse Faceted
  • 项目框架 JDT 启用(使用 3.4.0 测试)ANTLR 4 SDK A
  • antlr-4.x-complete.jar 的副本(撰写本文时为 4.5)

设置

  1. 安装 Eclipse
  1. Install Eclipse
  1. https://www.eclipse.org/downloads/
  2. 下载

  • 安装 XText 2.7.3

  • Install XText 2.7.3

    1. 转到帮助>安装新软件...
    2. Work With 文本框中输入 http://download.eclipse.org/modeling/tmf/xtext/updates/composite/releases/
    3. 按 Enter 并等待列表加载(这将需要一些时间)
    4. 展开Xtext节点,勾选Xtext Complete SDK(确保版本为2.7.3x)
    5. 点击Next,同意EULA,然后点击完成
    6. 让安装程序完成并重新启动 Eclipse
    1. Go to Help > Install New Software...
    2. Enter http://download.eclipse.org/modeling/tmf/xtext/updates/composite/releases/ in the Work With textbox
    3. Hit Enter and wait for the list to load (this will take a few moments)
    4. Expand the Xtext node and check Xtext Complete SDK (ensure the version is 2.7.3x)
    5. Click Next, agree to the EULA, and click finish
    6. Let the installer finish and restart Eclipse

  • 安装分面项目框架

  • Install Faceted Project Framework

    1. 转到帮助>安装新软件...
    2. Work With 文本框中输入 http://download.eclipse.org/releases/luna
    3. 按 Enter 并等待列表加载(这将需要一些时间)
    4. 在过滤器文本框中输入Facet
    5. 选择Eclipse Faceted Project FrameworkEclipse Faceted Project Framework JDT Enablement
    6. 点击Next,同意EULA,然后点击完成
    7. 让安装程序完成并重新启动 Eclipse
    1. Go to Help > Install New Software...
    2. Enter http://download.eclipse.org/releases/luna in the Work With textbox
    3. Hit Enter and wait for the list to load (this will take a few moments)
    4. In the filter text box enter Facet
    5. Select Eclipse Faceted Project Framework and Eclipse Faceted Project Framework JDT Enablement
    6. Click Next, agree to the EULA, and click finish
    7. Let the installer finish and restart Eclipse

  • 安装 ANTLR 4 IDE

  • Install ANTLR 4 IDE

    1. 转到帮助>Eclipse 市场...
    2. 搜索antlr
    3. 选择ANTLR 4 IDE(确保它是ANTLR 4 IDE而不是ANTLR IDE)
    4. 点击安装
    5. 让安装程序在提示时完成单击确定并重新启动 Eclipse
    1. Go to Help > Eclipse Marketplace...
    2. Search for antlr
    3. Choose ANTLR 4 IDE (make sure it's ANTLR 4 IDE not ANTLR IDE)
    4. Click Install
    5. Let the installer finish clicking ok if it prompts and restart Eclipse

  • 获取antlr-4.x-complete.jar的副本

  • Obtain a copy of antlr-4.x-complete.jar

    1. 这里
    2. 下载文件
    3. 把它保存在你会记得的地方

  • 创建 ANTRL 4 项目

    我在这里找到了大部分信息,剩下的就是阅读错误和猜测

    I found most of this information here, the rest was reading errors and guessing

    1. 转到<代码>文件>新项目项目
    2. 展开General 选项卡 并选择ANTLR 4 Project(如果您没有看到此内容,请参阅设置的第 4 步)
    3. 点击Next,为项目命名并点击Finish
    4. 项目完成后,右键单击该项目,然后单击Properties
    5. 转到Project Facets 并单击Convert to faceted form...(如果您没有看到此内容,请参阅设置的第 3 步)
    6. 检查 Java 项目方面并单击 Apply(如果您没有看到此内容,请参阅设置的第 3 步)
    7. 点击OK,让解决方案重建,再次打开属性
    8. 进入Java Build Path,点击Source标签
    9. 点击 Add Folder... 并检查 Project >目标 >生成源 >antlr4,点击OK
    10. 点击标签
    11. Add External JARs...,找到antlr-4.x-complete.jar的副本,点击Open
    12. 转到<代码>ANTLR 4 >工具,出现弹窗点击Apply
    13. 勾选启用项目特定设置
    14. 点击Add,找到antlr-4.x-complete.jar的副本,点击Open
    15. 检查4.x
    16. 点击Apply,点击Yes重建,点击OK退出属性
    1. Go to File > New Project > Project
    2. Expand the General Tab and select ANTLR 4 Project (if you don't see this see step 4 of setup)
    3. Click Next, give the project a name and click Finish
    4. Once the project is complete right click the project and click Properties
    5. Go to Project Facets and click Convert to faceted form... (if you don't see this see step 3 of setup)
    6. Check the Java project facet and click Apply (if you don't see this see step 3 of setup)
    7. Click OK, let the solution rebuild, open the properties again
    8. Go to Java Build Path, click the Source tab
    9. Click Add Folder... and check Project > target > generated-sources > antlr4, click OK
    10. Click the Libraries tab
    11. Add External JARs..., find your copy of antlr-4.x-complete.jar, click Open
    12. Go to ANTLR 4 > Tool, click Apply if a pop-up appears
    13. Check Enable project specific settings
    14. Click Add, find your copy of antlr-4.x-complete.jar, click Open
    15. Check 4.x
    16. Click Apply, click Yes to rebuild, click OK to exit the properties

    测试

    使用以下代码创建一个新类并尝试运行.在控制台中写入 Hello thereCtrl + z 将 EOF 发送到输入流

    Create a new class with the following code and try running. In the console write Hello there and Ctrl + z to send EOF to the input stream

    import org.antlr.v4.runtime.*;
    import org.antlr.v4.runtime.tree.*;
    public class HelloRunner 
    {
        public static void main( String[] args) throws Exception 
        {
    
            ANTLRInputStream input = new ANTLRInputStream( System.in);
    
            HelloLexer lexer = new HelloLexer(input);
    
            CommonTokenStream tokens = new CommonTokenStream(lexer);
    
            HelloParser parser = new HelloParser(tokens);
            ParseTree tree = parser.r(); // begin parsing at rule 'r'
            System.out.println(tree.toStringTree(parser)); // print LISP-style tree
        }
    }
    

    注意事项

    1. 如果您在尝试进入 ANTLR 4 > 时看到错误工具检查你的Xtext版本,2.8.0导致工具窗口出错
    2. 在第 8 步中,如果您更改了 ANTLR 生成的目录,请使用该目录
    3. 如果您注意到您添加到 ANTLR 4 > 的 ANTLR 版本工具 >Distributions 消失了,这似乎没问题

    1. If you see an error when you try to go into ANTLR 4 > Tool check your Xtext version, 2.8.0 causes an error in the tool window
    2. In step 8, if you've changed the directory ANTLR generates it's sources use that directory
    3. If you notice that the version of ANTLR you've added to ANTLR 4 > Tool > Distributions disappears this seems to be ok

    • 检查您的构建输出以查看它使用的是什么工具,即使它消失了,它仍应使用您添加的 JAR.这是我的样子:

    ANTLR 工具 v4.5 (C:\JavaLib\antlr-4.5-complete.jar)Hello.g4 -o C:\Users\username\workspace\project\target\generated-sources\antlr4 -listener -no-visitor -encoding UTF-8

    这篇关于在 Eclipse Luna (4.4) 上设置 ANTLR 4 IDE 时遇到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆