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

Roohul roohul17 at yahoo.com
Fri Feb 11 05:27:57 PST 2011


Hi,
This is my sample grammar.. this did not work.. another thing is 
that my variables and connectors both can have digits so I created Alpha
 : LETTER (LETTER | DIGIT)*; for this but it also give an error. 

primitiveType
    :   'real'
    |   'integer'
    |   'char'
    |   'boolean'
    |   'void'
    ;



 
CONNECTOR : LETTER+ ('In' | 'Out');
ID: LETTER+ ;

    

fragment LETTER : ('a'..'z' | 'A'..'Z') ;
fragment DIGIT : '0'..'9';
INT : DIGIT+ ;

Regards

Roohul 
S/W Engineer, LIU, Sweden




--- On Thu, 2/10/11, Bart Kiers <bkiers at gmail.com> wrote:

From: Bart Kiers <bkiers at gmail.com>
Subject: Re: [antlr-interest] Ident with ending In or Out word
To: "Roohul" <roohul17 at yahoo.com>
Cc: "ANTLR" <antlr-interest at antlr.org>
Date: Thursday, February 10, 2011, 10:40 AM

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+
  ;

fragmentAlpha  :  'a'..'z'  |  'A'..'Z'  ;

(the order of the rules is important here!)
Regards,
Bart. 




      


More information about the antlr-interest mailing list