[antlr-interest] Ada Grammar Question

Joseph Klumpp jklumpp0 at vt.edu
Sun Jul 20 17:18:33 PDT 2008


I have recently been updating the Ada grammar from
http://antlr.org/grammar/ada/ada.g to Antlr v3.  In testing this
grammar against the Ada Compiler test suite, I found that this grammar
fails for very specific constructs - all related with the Ada TIC mark
becoming confused with the CHARACHTER_LITERAL (or vice-versa).  The
rules are duplicated here:

TIC    : { LA(3)!='\'' }?  '\''    ;
        // condition needed to disambiguate from CHARACTER_LITERAL


CHARACTER_LITERAL    : { LA(3)=='\'' }? // condition needed to
disambiguate from TIC
       "'" . "'"


I rewrote these as:
TIC: {LA(3) != '\''} => "\'";
CHARACTER_LITERAL: {LA(3) == '\''}? => "\'" . "\'";

This works fine except for in constructs such as:
VAR_1 := ArrayType'('a','b','c' => X, others => Y);

In these situations the open parenthesis would be considered a
character literal and not a TIC mark, as it should be.  Any help in
how I could differentiate between this mark and character literals
would be greatly appreciated.


More information about the antlr-interest mailing list