[antlr-interest] Can subrules be set to 'n-to-m'?
Terence Parr
parrt at cs.usfca.edu
Thu Mar 24 14:58:40 PST 2005
On Mar 24, 2005, at 2:47 PM, Richard Matthias wrote:
> Yes, I hate putting checks in action code for something so simple and
> it does
> come up often enough when you are trying to covert rules from a 'lex'
> type
> scanner. I'm pulling my hair out now with trying to get the sample CSS
> grammar to work with antlr (pretty close to giving up and using the
> Apache
> Batik project's hand-coded parser). That has a rule for unicode
> escapes.
>
> H : '0'..'9' | 'a'..'f';
> UNICODE : '\\' (H)+ // one to six hex characters
> { some action code here to check the length;}
> ;
Hi Richard,
I usually do it this way. Not everything has to be checked with the
syntax. I've built a lot of translators and I have encountered very
few cases where the length of a lexeme was important ('cept for when I
did fortran translation). It's reasonably easy to put in the
"semantic" check. :)
Ter
>
> I suppose another way to do it would be
>
> UNICODE : '\\' H ( H ( H ( H ( H ( H )? )? )? )? )? ;
>
> Not pretty though!
> --
CS Professor & Grad Director, University of San Francisco
Creator, ANTLR Parser Generator, http://www.antlr.org
Cofounder, http://www.jguru.com
More information about the antlr-interest
mailing list