[antlr-interest] ANTLR3.0b2 - Action not executed

David CROSSON david.crosson at wanadoo.fr
Tue Jul 18 08:44:12 PDT 2006


In the following sample grammar, the action is
not executed although it is when using 3.0ea8
and although the pattern is well recognized and
returned !

Sample Grammar :

    grammar SampleParser;
    options {
        filter=true;
        output=AST;
    }
    @header {
      package stackdumpparser.parsers;
    }
    @lexer::header {
      package stackdumpparser.parsers;
    }
    all : 'A' {System.out.println("must be executed !!");}
        ;


Test case :

    package stackdumpparsertest;
    import junit.framework.*;
    import org.antlr.runtime.ANTLRStringStream;
    import org.antlr.runtime.CharStream;
    import org.antlr.runtime.CommonTokenStream;
    import org.antlr.runtime.RecognitionException;
    import org.antlr.runtime.tree.BaseTree;
    import stackdumpparser.parsers.SampleParser;
    import stackdumpparser.parsers.SampleParserLexer;
    
    public class AntlrFeaturesTest extends TestCase {
        
        public AntlrFeaturesTest(String testName) {
            super(testName);
        }
    
        protected void setUp() throws Exception {
        }
    
        protected void tearDown() throws Exception {
        }
        
        public void testBasic() throws RecognitionException, InterruptedException {
            CharStream in = new ANTLRStringStream("BABAA");
            SampleParserLexer lexer = new SampleParserLexer(in);
            CommonTokenStream tokens = new CommonTokenStream(lexer);
            SampleParser parser = new SampleParser(tokens);
            int i=0;
            SampleParser.all_return rc;
            while(true) {
                rc=parser.all();
                BaseTree tree = (BaseTree)rc.getTree();
                if (tree.isNil()) break;
                System.out.println("Found "+(i++)+" : "+tree.toString());
            }
        }
    }

Best regards,
Crosson David.


More information about the antlr-interest mailing list