I tripped over this in an earlier version of ANTLR 3 in which sempreds were 
broken.  The template code is "correct" in the Java version; I can't remember 
how this gets broken, but you need to keep on looking.

--Loring




________________________________
From: Sam Harwell <[email protected]>
To: [email protected]
Sent: Tuesday, March 3, 2009 4:06:16 PM
Subject: [antlr-dev] cyclicDFAState template incompatible with unbuffered tree 
node streams


Taken from Java.stg, we end up with a mismatched mark/rewind, which causes the 
temporary stream buffer (FastQueue) to flush during a predict operation that 
encounters predicates.
 
/** A state in a cyclic DFA; it's a special state and part of a big switch on
 *  state.
 */
cyclicDFAState(decisionNumber,stateNumber,edges,needErrorClause,semPredState) 
::= <<
int LA<decisionNumber>_<stateNumber> = input.LA(1);<\n>
<if(semPredState)> <! get next lookahead symbol to test edges, then rewind !>
int index<decisionNumber>_<stateNumber> = input.index();
input.rewind();<\n>
<endif>
s = -1;
<edges; separator="\nelse ">
<if(semPredState)> <! return input cursor to state before we rewound !>
input.seek(index<decisionNumber>_<stateNumber>);<\n>
<endif>
if ( s>=0 ) return s;
break;
>>  
 
For now I noticed it “works” to simply add a call input.mark() right after the 
call to input.rewind(), but I don’t think that’s the proper solution.
 
Sam


      
_______________________________________________
antlr-dev mailing list
[email protected]
http://www.antlr.org/mailman/listinfo/antlr-dev

Reply via email to