recursive calls work

[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 6832]
This commit is contained in:
parrt 2010-05-01 13:23:08 -08:00
parent f6f444db52
commit 16ad680adb
2 changed files with 18 additions and 7 deletions

View File

@ -177,7 +177,7 @@ workLoop:
boolean accepted = false;
processOneChar:
while ( i<closure.size() ) {
System.out.println("input["+input.index()+"]=="+(char)c+" closure="+closure+", i="+i+", reach="+ reach);
//System.out.println("input["+input.index()+"]=="+(char)c+" closure="+closure+", i="+i+", reach="+ reach);
ThreadState t = closure.get(i);
ip = t.addr;
NFAStack context = t.context;
@ -238,7 +238,7 @@ processOneChar:
int j=i+1;
while ( j<closure.size() ) {
ThreadState cl = closure.get(j);
System.out.println("remaining "+ cl);
//System.out.println("remaining "+ cl);
if ( cl.alt==alt ) closure.remove(j);
else j++;
}

View File

@ -77,11 +77,22 @@ public class TestNFABytecodeInterp extends BaseTest {
@Test public void testRecursiveCall() throws Exception {
LexerGrammar g = new LexerGrammar(
"lexer grammar L;\n" + //TODO
"I : D+ ;\n" +
"fragment D : '0'..'9'+ ;\n");
String expecting = "I, EOF";
checkMatches(g, "32", expecting);
"lexer grammar L;\n" +
"ACTION : '{' (ACTION|.)* '}' ;\n");
String expecting = "ACTION, EOF";
checkMatches(g, "{hi}", expecting);
checkMatches(g, "{{hi}}", expecting);
checkMatches(g, "{{x}{y}}", expecting);
checkMatches(g, "{{{{{{x}}}}}}", expecting);
}
@Test public void testAltOrWildcard() throws Exception {
LexerGrammar g = new LexerGrammar(
"lexer grammar L;\n" +
"A : 'a' ;\n" +
"ELSE : . ;\n");
String expecting = "A, A, ELSE, A, EOF";
checkMatches(g, "aaxa", expecting);
}
public void _template() throws Exception {