1

What is the antlr4 (v-4.1) equivalent form of the following grammar rule (written for antlr3 (v-3.2))?

text
:   tag => (tag)!
|   outsidetag
;
Pranshu
  • 11
  • 1
  • 2

1 Answers1

2

The following is invalid in ANTLR 3:

text
:   tag => (tag)!
|   outsidetag
;

You probably meant the following:

text
 : (tag)=> (tag)!
 | outsidetag
 ;

where ( ... )=> is a syntactic predicate, which has no ANTLR4 equivalent: simply remove them. As 280Z28 mentioned (and also explained in the previous link): the lack of syntactic predicates is not a feature that was removed from ANTLR 4. It's a workaround for a weakness in ANTLR 3's prediction algorithm that no longer applies to ANTLR 4.

The exlamation mark in v3 denotes to removal of a rule in the generated AST. Since ANTLR4 does not produce AST's, also just remove the exclamation mark.

So, the v4 equivalent would look like this:

text
 : tag
 | outsidetag
 ;
Community
  • 1
  • 1
Bart Kiers
  • 166,582
  • 36
  • 299
  • 288
  • You might clarify that the lack of syntactic predicates is not a feature that was removed from ANTLR 4. It's a workaround for a weakness in ANTLR 3's prediction algorithm that no longer applies to ANTLR 4. – Sam Harwell May 29 '14 at 12:53
  • @280Z28, true, I was a bit lazy, and this is already mentioned in your answer I linked to. Anyway, edited my answer. – Bart Kiers May 29 '14 at 12:56
  • Simply ignore would mean? What would be the output of toStringTree() called through root? Will that replace an occurrence of tag with a space? – Pranshu Jun 06 '14 at 10:57