[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Grammar question
On Tue, 30 Oct 2001, Todd Ogrin wrote:
> For example, using the tokens A, B, and C, all the
> following would be acceptable: ABC, CAB, C, A, BAC,
> AB, etc. Unacceptable examples include: CC, ABB,
> ACAB. Basically any string with duplicates is out,
> and I don't care about the ordering of the items that
> ARE there.
One possibility would be to make a custom Lexer which looks for the tokens
you've identified and complains when a token appears multiple times. I'm
not sure how icky this is in terms of code aesthetics. I recently wrote a
Lexer which distinguished different types of identifiers depending on
whether they had a prior declaration or not.
It seems that you could also make a pass through the AST and filter out
situations where this would occur after parsing? To do this, you would
use a DepthFirstAdapter and traverse the AST.