[antlr-interest] Grammar help
Gavin Lambert
antlr at mirality.co.nz
Fri Apr 16 16:44:05 PDT 2010
At 21:12 16/03/2010, Brian Catlin wrote:
>I don't get the errors I was getting before, but that is because
>the FILE_NAME token is matching everything, I put a simple
>printf action on the FILE_NAME token, and it gets called for
>all input:
[...]
>Is there a way to make the FILE_NAME token context sensitive so
>that the lexer doesn't try to match it unless we're in a rule
>that wants to find a file name?
No, ANTLR lexer's are context-free: you can't influence token
selection from the parser.
What you need to do is to change your approach. Have one token
for QUOTED_STRING and another token for NAME. Then, at the parser
level (where you have context), decide whether any particular NAME
is a command name or a filename (or whatever).
More information about the antlr-interest
mailing list