zsf222
zsf222

Reputation: 401

what does '^' after some token names in antlr do?

this is part of the https://github.com/monperrus/pascal3g/blob/master/pascal3g.g file. I have searched everywhere in the antlr4 documentation, but still don't know what the '^' sign do. Is this a sign for older versions of antlr?

usesUnitsPart
    : USES^ identifierList SEMI!
    ;

labelDeclarationPart
    : LABEL^ label ( COMMA! label )* SEMI!
    ;

I was asked to modify my question -- this is a sign in antlr3, and it was removed from antlr4. This is a difference of the two versions.

Upvotes: 2

Views: 409

Answers (2)

Pedro Lobito
Pedro Lobito

Reputation: 99001

The ^ is used as an inline tree operator, indicating a certain token should become the root of the tree

Upvotes: 1

Damien_The_Unbeliever
Damien_The_Unbeliever

Reputation: 239784

From ANTLR By Example: Part 3: Parsing:

We guide the AST construction using postfix annotations on the tokens in our parser rules. The following annotations are available:

  • no annotation: a token without an annotation becomes a leaf node in the tree
  • ^: a token annotated with a carat becomes a sub-expression root
  • !: a token annotated with an exclamation point is not included in the tree

(Which also covers the !s in your example that you hadn't yet asked about)

Upvotes: 4

Related Questions