[antlr-interest] a grammar problem

John B. Brodie jbb at acm.org
Sun Dec 13 10:10:18 PST 2009


On Sun, 2009-12-13 at 17:38 +0100, Hans-Martin Adorf wrote:
> An no, blanks are not permitted between #b and #e, since these
> character sequences are prefixes for binary numbers in Scheme (#b
> signifies a binary number, #e an exact number).
> 
> How can I switch off spaces?

the action `{ $channel = HIDDEN; }` on any lexer rule will cause
token(s) matched by that rule to be retained but not passed to the
parser.

the action `{ skip(); /*I think I got that name correct*/ }` on any
lexer rule will cause token(s) matched to be thrown away.

maybe looking through the Example grammars might make this clearer....

so for Scheme, since both whitespace and comments are used to separate
tokens but are otherwise ignored, you might have lexer rules:

fragment EOL : ( '\r' '\n'? | '\n' ) ;

WS : ( ' ' | '\t' | EOL )+ { $channel = HIDDEN; };

// single-line comments
SL_COMMENT: ';' (options{greedy=false;}: . )* EOL { $channel=HIDDEN; };





More information about the antlr-interest mailing list