[antlr-interest] multi line identifiers

Putrycz, Erik Erik.Putrycz at nrc-cnrc.gc.ca
Wed Sep 12 15:47:27 PDT 2007


I'm having great trouble trying to implement multi line identifiers in
antlr 3.
In Cobol, one of the wild cases is that an identifier can have the
following form
     CALL 'DSNHADDR' USING SQL-VPARMPTR OF SQL-PLIST7 SQL-PVAR-LIS
-    T7.
This is equivalent to CALL 'DSNHADDR' USING SQL-VPARMPTR OF SQL-PLIST7
SQL-PVAR-LIST7

My identifier rule is
fragment
NameElem
	: Letter | Digit | '-';
	 
fragment	
ContinuedName	:
	NewLine ContinuedLine Space* 
	;

fragment         
ContinuedLine
	:{getCharPositionInLine() == 0 }? '-'
	;

Name	: (Letter ~(NameElem)) => Letter
	| (NameElem+ ContinuedName NameElem) => NameElem+ ContinuedName
NameElem+ 
	| (Digit (Digit|'-')*)? Letter NameElem*
	;

This works fine for recognizing multi line identifiers but it is causing
a very strange side effect.
The last token of the last line of the input gets recognized as Name
instead of a literal. If I remove the second alternative (the multi line
case) to the Name then the last token is recognized correctly as a
literal. This defies my logic how the second alternative can affect the
third one and fail the literal recognition.

Erik 



More information about the antlr-interest mailing list