parsingtokenantlrgrammar

What does the Equal Sign (not a token) in an ANTLR grammar mean?


What does the construct basename = in the following rule?

tabname:
   (ID'.')? basename = ID
;

There is this single occurrence of basename in the grammar.


Solution

  • Using equals in that syntax creates a variable called basename that can then be referenced in actions:

    tabname:
        (ID '.')? basename=ID {
            if ($basename.equals("CAT"))
                System.out.println("CAT found");
        };