Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where Are All the Grammar Options in Antlr3?

Tags:

antlr

antlr3

In Antlr2 there were numerous grammar options that could be set (reference). Now in Antlr3 we have like 1/3 of the amount of options (reference).

So I have two questions concerning this:

  1. Does anyone know why so many options were taken out and are any of them coming back?
  2. Does Antlr3 have the ability to do what Antlr2 could, even without all those options?

To be more specific on my second question, I want to be able to do a few things. First, I want to change the visibility of the generated lexer and parser classes (i.e. Antlr2 option "classHeaderPrefix").

Secondly, I want to be able to ignore any whitespace tokens found within certain keywords, like having "&keyword&" and "& k ey w o rd &" both match (i.e. Antlr2 option "ignore", I think?).

Finally, I want to make certain keywords case insensitive (i.e. Antlr2 option "caseSensitive").

like image 528
BluePlateSpecial Avatar asked Jan 26 '26 09:01

BluePlateSpecial


1 Answers

BluePlateSpecial wrote:

To be more specific on my second question, I want to be able to do a few things. First, I want to change the visibility of the generated lexer and parser classes (i.e. Antlr2 option "classHeaderPrefix").

In v3 there is no way to do this.

BluePlateSpecial wrote:

Secondly, I want to be able to ignore any whitespace tokens found within certain keywords, like having "&keyword&" and "& k ey w o rd &" both match (i.e. Antlr2 option "ignore", I think?).

That options might have been removed because the LL(*) algorithm in the lexer is far more powerful than what was used in v2. Now, there is no need for such an option since this would do the trick:

FOO
  :  '&' (' ' | 'a'..'z')+ '&'
  ;

BluePlateSpecial wrote:

Finally, I want to make certain keywords case insensitive (i.e. Antlr2 option "caseSensitive").

That is also not possible in v3 other than doing it the "hard" way:

BAR
  :  ('b' | 'B') ('a' | 'A') ('r' | 'R')
  ;
like image 75
Bart Kiers Avatar answered Jan 29 '26 13:01

Bart Kiers



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!