[antlr-interest] Re: upgrade question
nagii5
nagii5 at yahoo.com
Tue Feb 19 14:29:03 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
I cant have the lexer match </anytag> for me because i dont
want other rules to modify the output buffer between
<anytag> and </anytag>
I need a way to specify that whatever comes between the tags
must be untouched.
now, if i try k = 14 ( thats the length of the longest such tag i
look for) antlr.Tool hangs at ( going into an infinite loop)
So i guess im doing something which i shudnt!
"main" prio=5 tid=0x235360 nid=0x690 runnable [0x6e000..0x6fc34]
at java.lang.Object.clone(Native Method)
at antlr.Lookahead.clone(Lookahead.java:96)
at antlr.LLkAnalyzer.look(LLkAnalyzer.java:944)
at antlr.LLkAnalyzer.look(LLkAnalyzer.java:773)
at antlr.RuleRefElement.look(RuleRefElement.java:49)
Coming back to the original question :
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);}
antlr2.7.1 generates the following code for the SAMPLE rule,
protected final void mSAMPLE(boolean _createToken) .etc
etc...TokenStreamException {
int _ttype; Token _token=null; int _begin=text.length();
_ttype = SAMPLE;
int _saveIndex;
{
_loop274:
do {
if (((LA(1) >= '\u0003' && LA(1) <= '\uffff'))) {
mNL_CTR(false);
}
else {
break _loop274;
}
} while (true);
}
if ( _createToken && _token==null && _ttype!=Token.SKIP ) {
_token = makeToken(_ttype);
_token.setText(new String(text.getBuffer(), _begin,
text.length()-_begin));
}
_returnToken = _token;
}
----------------------------------------------------
With 2.7.0 the method looks like: (omitting the common stuff)
-----------------------------------
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);
}
---------------------------------
Is there a reason for 2.7.1 to not add the extra
check
namely
&&(! 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