[antlr-interest] how to define these characters(java)
Nan Zhang
nan.zhang at sympatico.ca
Mon Jan 17 12:04:41 PST 2005
I tried to build a parser and lexer (java) to do this simple task:
print every '+' encountered and ignore all other characters in the inputstream(or maybe do other actions instead of just ignore it).
Here's my code:
-----------
class P extends Parser;
options {
defaultErrorHandler = false;
}
startRule
:
(n:PLUS {System.out.println(n.getText())}
)+ NEWLINE
;
class L extends Lexer;
PLUS : '+' ;
NEWLINE : '\r''\n'|'\n' ;
NON : ~('+'|'\r''\n'|'\n') {$setType(Token.SKIP); }//and other actions
;
------------
but I got an error message: This subrule cannot be inverted. Only subrules of the form:
(T1|T2|T3...) or
('c1'|'c2'|'c3'...)
may be inverted (ranges are also allowed).
Exiting due to errors.
I know there must be something wrong with NON definition in my code, but how to define such a characterSet: not '+' and not newline?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20050117/82a3c18e/attachment.html
More information about the antlr-interest
mailing list