谁能帮助我将这个ANTLR 2.0语法文件转换为ANTLR 3.0语法?

时间:2008-10-28 21:28:57

标签: parsing antlr rdf

我已经转换了'easy'部分(片段,@ head和@member) declerations等),但因为我是Antlr的新手我真的很难 时间转换树语句等。

我使用以下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 个答案:

答案 0 :(得分:1)

n3Directive0!:
                d=AT_PREFIX ns=nsprefix u=uriref
                {directive($d, $ns, $u);}
                ;
  • 您必须使用'='进行分配。
  • 然后可以将标记用作'$ tokenname.getText()',...
  • 然后,规则结果可以在您的代码中用作'rulename.result'
  • 如果您有规则已声明结果名称,则必须使用这些名称iso '结果'。