[antlr-interest] Ident with ending In or Out word

Bart Kiers bkiers at gmail.com
Thu Feb 10 10:40:16 PST 2011


On Thu, Feb 10, 2011 at 6:08 PM, Roohul <roohul17 at yahoo.com> wrote:

> Hi,
>
> I am working on a grammar which have some variables ending with In or Out
> which is treated as the connector between two components. I do not know how
> to handle this.
>
> For example:
> real abcIn
> real abcOut
>
> these are treated as connectors. while abcI or abcOu will be treated as
> normal variables.
>

You could handle this on a "lexer level" like this:

REAL
  :  'real'
  ;

CONNECTOR
  :  Alpha+ ('In' | 'Out')
  ;

VARIABLE
  :  Alpha+
  ;

fragment
Alpha
  :  'a'..'z'
  |  'A'..'Z'
  ;


(the order of the rules is important here!)

Regards,

Bart.


More information about the antlr-interest mailing list