[antlr-interest] Re: upgrade question

nagii5 nagii5 at yahoo.com
Tue Feb 19 14:56:25 PST 2002


> An excellent question.  The answer is yes, but that should start 
> indicating another solution is better.  You could have the lexer 
match 
> <anytag> and </anytag> and then use a stack to make sure they line 
up :)
> 
> Ter

Thanks, Terence
The reason i cannot let the lexer match </anytag> is that 
i dont want other rules to be fired between <anytag> and 
</anytag> which will eventually modify my output content.

so i tried with k = 14 which is the longest such tag 
and antlr271 hangs.. so i presume i'm doing something wrong.

coming back to the original question:

given the following tokens

protected SAMPLE: ( {! LA(1)=='<' && LA(2)=='/' && LA(3)== 'a' &&
                    LA(4)=='n' && LA(5)=='y' && LA(6)=='t' &&
                    LA(7)=='a' && LA(8)=='g' }? NL_CTR )*;

protected NL_CTR: c:. {if (c=='\n') newline(); buff.append((char)c);};

charVocabulory='\3'..'\uffff'

antlr270 generates the following code for the SAMPLE rule
------------------------------------------------------------

protected final void mSAMPLE(boolean _createToken) throws 
RecognitionException, CharStreamException, TokenStreamException {
int _ttype; Token _token=null; int _begin=text.length();
 _ttype = SAMPLE;
 int _saveIndex;
 {
  _loop274:
 do {
			if ((((LA(1) >= '\3' && LA(1) <= '\uffff')))&&
(! LA(1)=='<' && LA(2)=='/' && LA(3)== 'a' &&
                    LA(4)=='n' && LA(5)=='y' && LA(6)=='t' &&
                    LA(7)=='a' && LA(8)=='g' )) {
				mNL_CTR(false);
			}
			else {
				break _loop274;

....

----------------------------------------
whereas, antlr 271 generates the following code: (ommiting the common
code)

	if (((LA(1) >= '\u0003' && LA(1) <= '\uffff'))) {
		mNL_CTR(false);
         ....


Is there a reason for antlr271 to not append the 

&&(! LA(1)=='<' && LA(2)=='/' && LA(3)== 'a' &&
                    LA(4)=='n' && LA(5)=='y' && LA(6)=='t' &&
                    LA(7)=='a' && LA(8)=='g' )) {


thanks
nagesh



 

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



More information about the antlr-interest mailing list