[antlr-interest] Another simple case (of confusion)

Norman Dunbar Norman at dunbar-it.co.uk
Fri Dec 16 06:48:41 PST 2011


Sorry, me again.

I have this in my grammar:

BIN_VALUE : SIGN? '%' BIN_DIGIT+ ;

HEX_VALUE : SIGN? '%' HEX_DIGIT+ ;

INT_VALUE : SIGN? DIGIT+


fragment
BIN_DIGIT : '0'..'1';

fragment
HEX_DIGIT : (DIGIT | 'a'..'f' | 'A'..'F') ;

fragment
DIGIT : '0'..'9' ;

fragment
SIGN : '+'|'-' ;


The interpreter allows "+%1.9" or other "bad" values for a BIN_VALUE. 
The diagram for the above is "grammar T -> BIN_VALUE -> <epsilon>". 
There's nothing in the console output.

If I do a similar invalid HEX_VALUE such as "+$5.f", I get a similar 
result, the value is accepted as a valid HEX_VALUE.

Similarly, a decimal point in my INT_VALUE is accepted as well, however, 
if the invalid character at at the start of the input, it does get 
rejected - 'a5000' for an INT_VALUE for example - giving "no viable alt 
exception".


I do have both ANTLR books, but I can find nothing that explains my 
problems. Feel free to point me at  the correct location in the manual 
if you know different. Thanks.


Cheers,
Norm.

-- 
Norman Dunbar
Dunbar IT Consultants Ltd

Registered address:
Thorpe House
61 Richardshaw Lane
Pudsey
West Yorkshire
United Kingdom
LS28 7EL

Company Number: 05132767


More information about the antlr-interest mailing list