2

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.

zsf222
  • 345
  • 1
  • 10

2 Answers2

4

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)

Community
  • 1
  • 1
Damien_The_Unbeliever
  • 234,701
  • 27
  • 340
  • 448
1
The ^ is used as an inline tree operator, indicating a certain token should become the root of the tree
Pedro Lobito
  • 94,083
  • 31
  • 258
  • 268
  • Thanks! Do you know on which page of The Definitive ANTLR 4 Reference has mentioned this? – zsf222 Apr 23 '14 at 09:43
  • 1
    Check it here: https://theantlrguy.atlassian.net/wiki/display/ANTLR3/Tree+construction . You may also want to check this answer: http://stackoverflow.com/questions/11365781/caret-prefix-instead-of-postfix-in-antlr?answertab=active#tab-top – Pedro Lobito Apr 23 '14 at 09:45
  • I'm glad you found a solution, gl :) – Pedro Lobito Apr 23 '14 at 09:56