1

My professor gave us an assignment about ANTLR,

but I found that the given grammar file does not work with current ANTLR versions.

Actually, it is an example code included in ANTLR v2, which there are few documents left I can find and has been stopped to be supported by any IDE tools such as Eclipse or ANTLRWorks.

Because of this, it took quite long time for me to find out that the grammar file is from the ancient.

I need to modify the given grammar file to find whlie loops that are immediately enclosed by else branch, but cannot understand some part of the grammar.

Somebody please teach me what does '=>' means in this example?


program
    :   ( declaration )* EOF
    ;

declaration
    :   (variable) => variable
    |   function
    ;

declarator
    :   id:ID
    |   STAR id2:ID
    ;

variable
    :   type declarator SEMI
    ;

function
    :   type id:ID LPAREN
        (formalParameter (COMMA formalParameter)*)?
        RPAREN
        block
    ;

statement
    :   (declaration) => declaration
    |   expr SEMI
    |   if_statement
    |   while_statement
    |   block
    ;
4

1 に答える 1

1

これは、ANTLR 2 マニュアルに記載されている先読み構文述語です。これらは、先読みを使用してプロダクションのあいまいさを解消するために使用されます。

この特定のケースでは、変数または関数によって宣言を生成できます。それらのそれぞれが生成で始まる可能性があるため、述語は、先を見て、anよりも a を好むと言います。declarator SEMIid LPAREN

于 2013-04-28T06:27:21.753 に答える