[antlr-interest] How to write this lexer rule?
Gavin Lambert
antlr at mirality.co.nz
Tue Jan 13 12:21:37 PST 2009
At 00:29 14/01/2009, chain one wrote:
>I tried the lexer rule you gave me. But following error comes
>out:
>
>Alternative 155: after matching input such as
>'F''U''N''C''T''I''O''N''F''U''N''C''T''I''O''N''F''U''N''C''T''I''O''N''E''N''D''_''F''U''N''C''T''I''O''N'{'0'..'9',
>'A'..'Z', '_',
>'a'..'z'}'F''U''N''C''T''I''O''N''E''N''D''_''F''U''N''C''T''I''O''N'{'0'..'9',
>'A'..'Z', '_', 'a'..'z'}'F''U''N''C''T''I''O'{'\u0000'..'/',
>':'..'@', 'N', '['..'^', '`', '{'..'\uFFFF'} decision cannot
>predict what comes next due to recursion overflow to
>FUNCTION_DECL from FUNCTION_DECL
Hmm. Well, another variation (that it might like better) would
be:
FUNCTION_DECL
: 'FUNCTION' { $channel = HIDDEN; }
(FUNCTION_DECL | ~'E' | 'E' (~'N' | 'N' (~'D' | 'D'
(~'_' | '_' (~'F' | 'F' (~'U' | 'U' (~'N' | 'N'
(~'C' | 'C' (~'T' | 'T' (~'I' | 'I' (~'O' | 'O'
(~'N' | 'N' ~SEMI))))))))))))*
'END_FUNCTION' SEMI
;
Another thing that might help is to change the embedded reference
to FUNCTION_DECL to ('FUNCTION') => FUNCTION_DECL; ie:
FUNCTION_DECL
: 'FUNCTION' { $channel = HIDDEN; }
('FUNCTION') => FUNCTION_DECL | ~'E' | 'E' (~'N' | 'N'
(~'D' | 'D' (~'_' | '_' (~'F' | 'F' (~'U' | 'U'
(~'N' | 'N' (~'C' | 'C' (~'T' | 'T' (~'I' | 'I'
(~'O' | 'O' (~'N' | 'N' ~SEMI))))))))))))*
'END_FUNCTION' SEMI
;
More information about the antlr-interest
mailing list