Qualcuno può aiutarmi a convertire questo file grammaticale ANTLR 2.0 in sintassi ANTLR 3.0?

StackOverflow https://stackoverflow.com/questions/244936

  •  05-07-2019
  •  | 
  •  

Domanda

Ho convertito le parti 'facili' (frammento, @header e @member declerazioni ecc.), ma dato che sono nuovo in Antlr ho davvero un duro tempo di convertire le dichiarazioni Tree ecc.

Uso il seguente guida alla migrazione .

Il file grammaticale è disponibile qui. ...

Di seguito puoi trovare alcuni esempi in cui ho riscontrato problemi:

Ad esempio, ho problemi con:

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

o

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 ", ."
    ; 
È stato utile?

Soluzione

n3Directive0!:
                d=AT_PREFIX ns=nsprefix u=uriref
                {directive($d, $ns, $u);}
                ;
  • Devi usare '=' per i compiti.
  • I token possono quindi essere usati come '$ tokenname.getText ()', ...
  • I risultati delle regole possono quindi essere utilizzati nel codice come 'rulename.result'
  • Se hai regole che hanno dichiarato i nomi dei risultati, devi usare questi nomi iso.
    'Risultato'.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top