2008-10-28 49 views
1

我已經轉換了「容易」部分(片段,@header和@member declerations等),但由於我是新來的Antlr我有一個很艱難 時間轉換樹報表等任何人都可以幫助我將這個ANTLR 2.0語法文件轉換爲ANTLR 3.0語法嗎?

我使用以下migration guide

The grammar file can be found here. ...

下面你可以找到一些例子,我遇到的問題:

舉例來說,我有一個問題:

n3Directive0!: 
       d:AT_PREFIX ns:nsprefix u:uriref 
       {directive(#d, #ns, #u);} 
       ; 

propertyList![AST subj] 
     : NAME_OP! anonnode[subj] propertyList[subj] 
     | propValue[subj] (SEMI propertyList[subj])? 
     |    // void : allows for [ :a :b ] and empty list "; .". 
     ; 

propValue [AST subj] 
     : v1:verb objectList[subj, #v1] 
       // Reverse the subject and object 
     | v2:verbReverse subjectList[subj, #v2] 
     ; 

subjectList![AST oldSub, AST prop] 
     : obj:item { emitQuad(#obj, prop, oldSub) ; } 
       (COMMA subjectList[oldSub, prop])? ; 

objectList! [AST subj, AST prop] 
     : obj:item { emitQuad(subj,prop,#obj) ; } 
       (COMMA objectList[subj, prop])? 
    | // Allows for empty list ", ." 
    ; 

回答

1
n3Directive0!: 
       d=AT_PREFIX ns=nsprefix u=uriref 
       {directive($d, $ns, $u);} 
       ; 
  • 您必須使用'='進行分配。然後
  • 令牌可以作爲「$ tokenname.getText()」,...
  • 規則結果然後在代碼中被用作「rulename.result」
  • 如果您有已宣佈結果的名稱規則,你必須使用這些名稱iso。
    '結果'。