[antlr-interest] Infinite lookahead/syntactic predicates
Akhilesh Mritunjai
virtualaspirin at yahoo.com
Thu Jun 23 15:57:36 PDT 2005
Hi
Its fairly simple using syntactic lookahead, let the
lexer do all grunt work:
protected HEX_CONST: ('0'..'9'|'A'..'F'|'a'..'f')+;
protected DEC_CONST: ('0'..'9')+
protected BIN_CONST: ('0'|'1')+
protected FOO_CONST: ....
CONST:
QUOTE
(
(HEX_CONST QUOTE 'H') => HEX_CONST QUOTE 'H' {
$setType(HEX_CONSTANT); }
|(BIN_CONST QUOTE 'B') => BIN_CONST QUOTE 'B' {
$setType(BIN_CONSTANT); }
|(DEC_CONST QUOTE 'D') => DEC_CONST QUOTE 'D' {
$setType(DEC_CONSTANT); }
....
);
declare 'BIN_CONSTANT', 'DEC_CONSTANT' etc in tokens
section. That way you get nice tagged constants to use
in your parser grammar, or skip the $setType stuff if
you don't care about type of constant in parser.
HTH
- Akhilesh
--- Anders Jacobsson <anders.jacobsson at gmail.com>
>
> '12345'D
> '13AEF'H
> '1A4'T
> '1010101'B
> '17853'
>
> The first one should be matched to be a decimal
> constant, the second
> one a hexadecimal constant, the third one a TBCD
> constant, the fourth
> one a binary constant and the last to be a constant
> of unknown type.
>
> It would have been nice to have the type indicator
> in front of the
> constant but I guess I'm not that lucky... :) I have
> been trying to
> use looping and syntactic predicates but so far no
> luck.
__________________________________
Do you Yahoo!?
Yahoo! Mail - Find what you need with new enhanced search.
http://info.mail.yahoo.com/mail_250
More information about the antlr-interest
mailing list