Eclipse中的Antlr IDE不起作用 [英] Antlr IDE in Eclipse doesn't work

查看:195
本文介绍了Eclipse中的Antlr IDE不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Antlr v3和java作为一个项目,一切都在AntlrWorks中运行,但是当我切换到Antlr IDE时,eclipse的插件,解释器与我写的句子不符,告诉我不匹配。在我看来,它无法识别我在词法分析器上指定的单词列表。但是,在AntlrWorks中,它是完全相同的。



任何建议?



我已经设置eclipse中的antlr buider:Antlr Parser Generator v3.4

解决方案




更新: / h1>

如果您正在Eclipse Neon中查找ANTLR v4的安装和设置,请参阅SO文档(与这些说明相似的格式)。






这可能是一个配置问题。我有一些困难让一切工作,所以没有找到任何一个地方如何做到这一点,我写了我自己的文件。希望这可以帮助。



如何在Eclipse Indigo中安装ANTLR IDE



使用Indigo R2和IDE 2.1.2测试




  1. 安装Eclipse。

  2. 下载 ANTLR完整的二进制jar包含ANTLR v2。提取到临时目录。将antlr-nn
    文件夹复制到相应的永久位置,例如安装Eclipse的相同的
    文件夹。

  3. 将ANTLR IDE更新站点添加到
    Eclipse。


    • 在Eclipse中,单击帮助并选择安装新软件。

    • 单击添加...按钮。

    • 在添加存储库窗口中,对于位置类型 http://antlrv3ide.sourceforge.net/更新并键入类似ANTLR IDE的名称,然后单击确定以返回到可用的软件窗口。

    • 选中ANTLR IDE vn.nn框,然后单击直到安装。 Eclipse可能会重新启动。


  4. 配置ANTLR IDE。


    • 在Eclipse主窗口中,单击窗口,然后单击首选项。

    • 在左窗格中,展开ANTLR并选择生成器。

    • 在右窗格中,单击添加...按钮。

    • 在添加ANTLR包窗口中,单击目录...并导航到antlr-nn文件夹,然后单击确定。

    • 单击确定关闭添加ANTLR包窗口。

    • 在左窗格中选择代码生成器,然后单击在右窗格中的项目相对文件夹。键入文件夹名称。示例:antlr-java或antlr生成。

    • 选择任何其他配置参数,但不要在构建窗口的常规下检查-nfa或-dfa。如果选中,这些将导致ANTLR错误,从而防止在输出文件夹中生成java文件。

    • 单击确定关闭首选项窗口。


  5. 创建一个新的Java项目并启用ANTLR支持。


    • 从Eclipse主窗口中,转到File,New,Java Project。单击下一步,键入项目名称,然后单击完成。

    • 要为项目启用ANTLR支持,请在包资源管理器窗口(左窗格)中右键单击刚刚创建的项目,然后选择配置

    • 将ANTLR完整的jar文件添加到项目中:右键单击该项目,然后选择属性,Java构建路径,添加外部JAR...,浏览到ANTLR jar文件,选择它,然后单击确定。单击确定关闭项目属性窗口。


  6. 创建ANTLR语法。


    • 创建一个新的ANTLR语法:右键单击项目的src文件夹,然后单击文件,新建,其他,展开ANTLR并选择组合语法。单击下一步,键入语法名称,选择语言选项,然后单击完成。

    • 创建一个.g文件,并选择选项和空白规则。在顶部添加选项language = Java,@header,@lexer :: header和@members语句(请参阅示例)。自动完成是添加这些功能的最简单方法(按CTRL空格显示自动完成列表)。


  7. 保存语法。


    • 保存时,包含生成的语法代码的文件夹应显示在项目资源管理器中。如果没有,请确保在构建窗口中的常规下的ANTLR首选项中不检查-nfa或-dfa选项(步骤4g)。 [确认这些是否需要:检查CLASSPATH环境变量指向与您的Eclipse安装(32或64位)匹配的Java7,Windows Path环境变量具有Java7 SDK。]

    • 为避免不能被解析为类型Java错误,右键单击包含生成的Java代码的文件夹,然后构建路径,用作源文件夹。


样本组合GRAMMAR

 语法测试; // must match filename.g 

options {
language = Java;
}

@header {// parser
package pkgName; //可选
import java。<无论你需要什么>。*;
}

@members {// parser
// java代码这里
}

@lexer :: header {// lexer
包pkgName; //可选
import java。<无论你需要什么>。*;
}

@lexer :: members {
// java code here
}
/ * ----------- -------------------------------------------------- -----
* PARSER规则(约定全部为小写)
* --------------------------- --------------------------------------- * /
parserule:LEXRULE;

/ * ---------------------------------------- --------------------------
* LEXER规则(约定全部为大写)
* ------ -------------------------------------------------- ---------- * /
LEXRULE:'a'..'z';


I'm using Antlr v3 and java for a project and all goes well in AntlrWorks, but when I switch to Antlr IDE, the plugin for eclipse, the interpreter cannot match the sentence that I wrote, telling me mismatch. And it seems to me that it cannot recognize the list of words to skip that I've specified in on lexer. However it is the same that works perfectly in AntlrWorks.

Any suggestions?

I've set up the antlr buider in eclipse: Antlr Parser Generator v3.4

解决方案


UPDATE:

If you are looking for installation and setup of ANTLR v4 in Eclipse Neon, see the SO Documentation for it (similar format to these instructions).


This may be a configuration issue. I had several difficulties getting everything to work so, not finding any one place for how to do this, I wrote my own document. Hope this helps.

How To Install ANTLR IDE in Eclipse Indigo

Tested With Indigo R2 and IDE 2.1.2

  1. Install Eclipse.
  2. Download ANTLR complete binaries jar that includes ANTLR v2. Extract to a temp directory. Copy the antlr-n.n folder to an appropriate permanent location, for example the same folder that Eclipse is installed in.
  3. Add ANTLR IDE update site to Eclipse.
    • In Eclipse, click on Help and select Install New Software.
    • Click Add… button.
    • In the Add Repository window, for Location type http://antlrv3ide.sourceforge.net/updates and type something like ANTLR IDE for the Name and click OK to get back to the Available Software window.
    • Check the box for ANTLR IDE vn.n.n and click on through until it is installed. Eclipse will probably restart.
  4. Configure the ANTLR IDE.
    • In the Eclipse main window, click Window then Preferences.
    • In the left pane, expand ANTLR and select Builder.
    • In the right pane, click the Add… button.
    • In the Add ANTLR Package window, click Directory… and navigate to the location of the antlr-n.n folder and click OK.
    • Click OK to close the Add ANTLR Package window.
    • Select Code Generator in the left pane and click on Project relative folder in the right pane. Type a folder name. Examples: antlr-java or antlr-generated.
    • Select any other configuration parameters but DO NOT check –nfa or –dfa in the under General in the Building window. If checked, these will cause ANTLR errors preventing java files from being generated in the output folder.
    • Click OK to close the Preferences window.
  5. Create a new Java project and enable ANTLR support.
    • From the Eclipse main window, go to File, New, Java Project. Click Next, type a project name and click Finish.
    • To enable ANTLR support for the project, in the Package Explorer window (left pane) right-click the project just created and select Configure, Convert to ANTLR project.
    • Add the ANTLR complete jar file to the project: right-click the project and select Properties, Java Build Path, click Add External JARs…, browse to the ANTLR jar file, select it, and click OK. Click OK to close the project Properties window.
  6. Create an ANTLR grammar.
    • Create a new ANTLR grammar: right-click the src folder of the project, then File, New, Other, expand ANTLR and select Combined Grammar. Click Next, type grammar name, select a Language option, and click Finish.
    • A ".g" file is created with the options selected and a blank rule. Add the options language=Java, @header, @lexer::header, and @members statements at the top (see example). Auto completion is the easiest way to add these (press CTRL-space to bring up auto-completion list).
  7. Save the grammar.
    • When saved, a folder containing generated Java code for the grammar should appear in the Project Explorer. If it does not, make sure the –nfa or –dfa options are not checked in ANTLR Preferences under General in the Building window (Step 4g). [Confirm if these needed: check CLASSPATH environment variable points to the Java7 that matches your Eclipse install (32 or 64 bits) and Windows Path environment variable had Java7 SDK.]
    • To avoid "cannot be resolved to a type" Java errors, right-click the folder containing generated Java code, then Build Path, Use as a Source Folder.

SAMPLE COMBINED GRAMMAR

grammar test; //must match filename.g

options {
    language = Java;
}

@header { //parser
    package pkgName; //optional
    import java.<whatever you need>.*;
}

@members { //parser
    // java code here
}

@lexer::header { //lexer
    package pkgName; //optional
    import java.<whatever you need>.*;
}

@lexer::members {
    // java code here
}
/*------------------------------------------------------------------
 * PARSER RULES (convention is all lowercase)
 *------------------------------------------------------------------*/
parserule: LEXRULE;

/*------------------------------------------------------------------
 * LEXER RULES (convention is all uppercase)
 *------------------------------------------------------------------*/
LEXRULE: 'a'..'z';

这篇关于Eclipse中的Antlr IDE不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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