[antlr-interest] Variables names with number

Putrycz, Erik Erik.Putrycz at nrc-cnrc.gc.ca
Sun Apr 23 00:23:39 PDT 2006


I'm working on a cobol grammar and I'm stuck with a strange problem:
In Cobol some "variable" (records) names not only can contain number but can start with numbers:
For instance a COBOL line with:
005574         88  2ND-PREVIOUS-YEAR-DED             VALUE
I have no problem scanning the record structure but "2ND-PREVIOUS-YEAR-DED" fails the "NAME" rule (my grammar is based on the python grammar). I get the error expecting NAME, found '2'.

I tried to add (Int Letter) => Name { $setType(NAME);} to the main NAME rule but it doesn't do anything.
Here are my main NAME rules:

STRING_OR_NAME
options {
    testLiterals=true; // check to see if we are a keyword
}   :  
 	String {$setType(STRING);}
    | (Int Letter) => Name { $setType(NAME);}	
    |   SimpleName {$setType(NAME);}   

protected
Name
    :
    	(Digit)* (Letter) (Letter|Digit|'-')*
    ;

Are there any other grammars that implement such naming rules?

Thanks,

Erik Putrycz, Ph.D - Research Associate / erik.putrycz at nrc-cnrc.gc.ca / (613) 990 0681
Institute for Information Technology - Software Engineering Group
National Research Council, Canada - Building M-50, 1200 Montreal Road
Ottawa, Ontario, CANADA K1A 0R6




More information about the antlr-interest mailing list