在Eclipse Luna上设置ANTLR 4 IDE的麻烦(4.4) [英] Trouble Setting Up ANTLR 4 IDE on Eclipse Luna (4.4)

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

问题描述

我正在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完整的SDK(需要版本为2.7.3)

  • Eclipse Faceted Project Framework(经3.4测试) 0)Eclipse Faceted

  • 项目框架JDT启用(使用3.4.0进行测试)ANTLR 4 SDK A

  • antlr-4.x的副本-complete.jar(4.5写作时)

  • Eclipse 4.4 Luna Xtext Complete SDK(Needs to be version 2.7.3)
  • Eclipse Faceted Project Framework (Tested with 3.4.0) Eclipse Faceted
  • Project Framework JDT Enablement(Tested with 3.4.0) ANTLR 4 SDK A
  • A copy of the antlr-4.x-complete.jar (4.5 at the time of writing)

设置


  1. 安装Eclipse
  1. Install Eclipse

  1. https://www.eclipse.org/downloads/

  1. Download it from https://www.eclipse.org/downloads/


  • 安装XText 2.7.3

  • Install XText 2.7.3


    1. 转到帮助>安装新软件...

    2. 输入 http://download.eclipse.org/modeling/tmf/xtext/updates/composite / code>工作与文本框

    3. 点击Enter等待列表加载(这个将花费一些时间)

    4. 展开 Xtext 节点,并检查 Xtext Complete SDK (确保版本为2.7.3x)

    5. 单击下一步,同意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


  • 安装Faceted Project Framework

  • Install Faceted Project Framework


    1. 转到帮助>安装新软件...

    2. 输入 http://download.eclipse.org/releases/luna 使用文本框

    3. 点击Enter等待列表加载(这将需要一些时间)

    4. 在过滤器文本框中输入 Facet

    5. 选择 Eclipse Faceted Project Framework Eclipse Faceted Project Framework JDT启用

    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 Marketplace ...

    2. 搜索 antlr

    3. 选择 ANTLR 4 IDE (确保它是ANTLR 4 IDE不是ANTLR IDE)

    4. 单击安装

    5. 让安装程序完成点击ok,如果它提示并重新启动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. 将它保存在你会记住的地方

    1. Download the file from here
    2. Save it somewhere you'll remember


  • 创建ANTRL 4项目

    我发现大部分信息这里,其余的是阅读错误并猜测

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


    1. 转到文件>新项目>项目

    2. 展开常规选项卡并选择 ANTLR 4项目(如果没有看到,请参阅设置的第4步)

    3. 点击下一步,给项目一个名字并单击完成

    4. 项目完成后,右键单击项目,然后单击属性

    5. 转到项目方面,然后点击转换为刻面形式... (如果看不到,请参阅设置步骤3)

    6. 检查 Java 项目构面,然后单击应用(如果看不到,请参阅设置步骤3)

    7. 点击确定,让解决方案重建,再次打开属性

    8. 转到 Java构建路径,单击标签

    9. 点击添加文件夹... 并检查 Project>目标>生成源> antlr4 ,点击确定

    10. 点击 Libraries 标签

    11. 添加外部JAR ... ,找到您的副本 antlr-4.x-complete .jar ,点击打开

    12. 转到 ANTLR 4>工具,点击应用如果弹出窗口出现

    13. 检查启用项目单击添加,找到 antlr-4的副本。 x-complete.jar ,点击打开

    14. 检查 4.x

    15. 点击申请,点击重建,点击确定退出属性

    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 there Ctrl + 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版本工具>分发消失,这似乎是好的

    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上设置ANTLR 4 IDE的麻烦(4.4)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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