[antlr-interest] Syntactic predicates in lexer

Indhu Bharathi indhu.b at s7software.com
Wed Oct 14 03:20:48 PDT 2009


Doesn’t a simple approach like the one shown below work?

 

r              :               ASSIGNMENTOP  |  KEYWORDMARKER

                ;

 

ASSIGNMENTOP              :               ':='          ;

                

KEYWORDMARKER          :               ':'             ;

 

I assume you want a different token for ‘:=’ and ‘:’. If I understood the
problem wrong, let me know.

 

Cheers, Indhu

 

 

From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Loïc Quéran
Sent: Wednesday, October 14, 2009 2:57 PM
To: antlr-interest at antlr.org
Subject: [antlr-interest] Syntactic predicates in lexer

 

Hi,

This is probably a very simple question, but I can't get syntactic
predicates to work in lexer rules:


AssignmentOperatorOrKeywordMarker
  : ':=' => AssignmentOperator
  | ':' => KeywordMarker
  ;
  
KeywordMarker
  :    ':'
  ;
    
AssignmentOperator
  :    ':='
  ;

What I want to achieve is to have the lexer produce an assignment operator
':=' token instead of a keyword marker ':' whenever possible.
The error is  "unexpected token: ':='" at AssignmentOperatorOrKeywordMarker
rule definition.

Any help would be welcomed.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20091014/55204e52/attachment.html 


More information about the antlr-interest mailing list