FW: [antlr-interest] Use each token Once -- All required

Bryan Ewbank ewbank at synopsys.com
Wed Sep 22 03:18:59 PDT 2004


> > How can I specify a compact syntax for the parser that will define a
> > list of token types from the lexer where each type must appear, but
> > only one time?
> >
> > XXX :  (TokenType1 | TokenType2 | TokenType3 | TokenType4)+;
> > doesn't limit the token types to appearing only one time.

It seems you need more than a bitset, unless you add semantic predicates to
each alternative...

	// alternative one - bits.  errors come from syntactic predicates.
	XXX :
		( { TT(1) == 0 }? TokenType1 { setTT(1); }
		| { TT(2) == 0 }? TokenType2 { setTT(2); }
		| { TT(3) == 0 }? TokenType3 { setTT(3); }
		| { TT(4) == 0 }? TokenType4 { setTT(4); }
		)+
		{ ... here check for existence of each ... ; }
		;

	// alternative two - ints.  perhaps better error message.
	XXX :
		( TokenType1 { incrTT(1); }
		| TokenType2 { incrTT(2); }
		| TokenType3 { incrTT(3); }
		| TokenType4 { incrTT(4); }
		)+
		{ ... here check for exactly one of each ... ; }
		;

A new ANTLRite,
--
Bryan Ewbank            919.425.7344 (V)    Senior R&D Engineer
ewbank at synopsys.com     919.425.7320 (F)          Synopsys, Inc




 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
    antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 





More information about the antlr-interest mailing list