[antlr-interest] two question about java.g
lzy7886
lzy7886 at yahoo.com
Fri Apr 11 05:07:49 PDT 2003
Hi Terence:
I just have two questions about some rules in your java.g example
(antlr-2.7.2\examples\java\java).
First the NUM_INT lexer rule:
please see the //?? part of in the following excerpt .
NUM_INT
{boolean isDecimal=false; Token t=null;}
: '.' {_ttype = DOT;}
( ('0'..'9')+ (EXPONENT)? (f1:FLOAT_SUFFIX {t=f1;})?
)?
| ( '0' {isDecimal = true;}
( ('x'|'X')
(
// hex
options {
warnWhenFollowAmbig=false;
}
: HEX_DIGIT
)+
| ('0'..'7')+
)?
| ('1'..'9') ('0'..'9')* {isDecimal=true;}
// non-zero decimal
)
//??here when you enter the follwing subrule whether now you have
//hex,decimal or oct number,the rule set all the isDecimal variable to
//ture.so the semantic predicates of the isDecimal variable in the
//beginning of the second alternative of the follwing subrule seems
//meaningless.
//I wonder if the initial idea is to prevent hex number appended
//with '.',ie:0x44.0e44
( ('l'|'L') { _ttype = NUM_LONG; }
// only check to see if it's a float if looks like
decimal so far
| {isDecimal}?
( '.' ('0'..'9')* (EXPONENT)?
(f2:FLOAT_SUFFIX {t=f2;})?
EXPONENT (f3:FLOAT_SUFFIX {t=f3;})?
| f4:FLOAT_SUFFIX {t=f4;}
)
{
if (t != null && t.getText().toUpperCase
() .indexOf('F') >= 0) {
_ttype = NUM_FLOAT;
}
else {
_ttype = NUM_DOUBLE; // assume double
}
}
)?
The second question is that I found in the java spec 2rd:
It is a compile-time error for a line terminator to appear after the
opening ' and before the closing '.(chapter 3.10.4)
It is a compile-time error for a line terminator to appear after the
opening " and before the closing matching ".(chapter 3.10.5)
But the corresponding lexer rule in java.g doesn't abide by the spec :
// character literals
CHAR_LITERAL
: '\'' ( ESC | ~'\'' ) '\''
;
// string literals
STRING_LITERAL
: '"' (ESC|~('"'|'\\'))* '"'
;
One proposal for revision:
// character literals
CHAR_LITERAL
: '\'' ( ESC | ~('\''|'\n'|'\r') ) '\''
;
// string literals
STRING_LITERAL
: '"' (ESC|~('"'|'\\'|'\n'|'\r'))* '"'
;
OK,that's all my question so far,anyway ANTLR is just so wonderful!I
appreciate you guys work a lot.I am looking forward to
the progress of this revolutionary tool.
One guy from China
lzy
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list