Antlr3+Eclipse開發環境的搭建

先從http://www.eclipse.org/downloads/上下載classic版本的Eclipse:php

image

進入http://www.antlr.org/wiki/display/ANTLR3/ANTLR+3+Wiki+Home頁面:html

image

進入後選擇:express

image

選擇http://antlrv3ide.sourceforge.net/windows

image

進入AntlrIDE主頁,選擇download:eclipse

image

能夠看到安裝ANTLR-IDE的先決條件,要安裝GEF、Zest和Dynamic Language ToolKit,剛開始我用updatemanager的方式來下載這些軟件,可是不知道爲何,有不少都出現下載錯誤。最後只好用手動的方式安裝部分插件。在Eclipse的更新管理器imageide

輸入以下網址http://download.eclipse.org/tools/gef/updates/releases/,獲取GEF/ZEST插件ui

image

用手動的方式安裝EMF/AntlrIDE/Dynamic Language Toolkit(DLTK) Core插件.atom

EMF插件下載地址:http://www.eclipse.org/modeling/emf/downloads/index.php?project=emf&showAll=0&showMax=5spa

下載EMF Runtime:.net

image

AntlrIDE下載地址:

http://sourceforge.net/projects/antlrv3ide/files/antlride/2.1.0/antlride-2.1.2.zip/download

image

 

Dynamic Language Toolkit(DLTK) Core下載地址:http://download.eclipse.org/technology/dltk/downloads/drops/R3.0/R-3.0-201106091504/,下載:

image 

將上面的插件下載後,用手動的方式進行安裝,安裝步驟以下:

在F:\Eclipse-EMF\eclipse-SDK-3.7.1-win32\eclipse目錄下創建extplugins和links兩個目錄:

image 

將下載的插件放入到extplugins目錄下:

image

在links目錄下創建以下三個文件:

image

文件的內容以下:

image

 

image

image

如今全部的軟件都已經安裝好了,咱們能夠在eclipse中檢查下看是否安裝成功:

windows->preferences下:

image

在Antlr下的Builder中添加altlr parser generator,下載地址以下:

http://www.antlr.org/download.html

image

而後設置Antlr自動生成文件

image

-----------------------------------------------分割線-------------------------------------------

如今開始在eclipse下創建一個Java工程,而後在Java工程中添加Antlr文件:

image

image

image

 

在Antlr_test.g下輸入以下文法:

grammar Antlr_test;

options {
  language = Java;
}

programe: statement +;
statement : (expression | VAR '=' expression) ';';
expression: (multExpr (('+' | '-')multExpr)*) | STRING;
multExpr:  atom ('*'atom)*;
atom  :  INT | '(' expression ')';
VAR : ('a'..'z' | 'A'..'Z')+;
INT : '0'..'9'+;
STRING  : '"'(('A'..'Z'| 'a'..'z')+)'"';
WS  : (' ' | '\t' | '\n' | '\r')+ {Skip();};

image

而後將Javaproject轉化爲Antlr工程,這一步困擾了我很久………………

image

最後能夠看到Antlr自動生成的Java代碼:

image 

image

相關文章
相關標籤/搜索