views:

101

answers:

2

Hi, everybody, Please help me this problem: I do the example on the page: http://www.antlr.org/wiki/pages/viewpage.action?pageId=1760

in order use this example, i have built the grammar P on ANTLRWork 1.4 and generate code to have class PLexer and PParser. But when i run this code on java Jcreator 4.5:

import org.antlr.runtime.*;
import org.antlr.runtime.tree.*;
import org.antlr.runtime.debug.*;
import org.antlr.runtime.ANTLRStringStream;
import org.antlr.runtime.CharStream;
import ParserAndLexer.*;

public class TestP {
    public static void main (String[] args) throws Exception{
        ANTLRInputStream input=new ANTLRInputStream(System.in);
        PLexer lexer=new PLexer(input);
        CommonTokenStream tokens=new CommonTokenStream(lexer);
        ParseTreeBuilder builder=new ParseTreeBuilder("prog"); 
        PParser parser=new PParser(tokens,builder);
        parser.prog();
        System.out.println(builder.getTree().toStringTree());     
    }  
}

the error appear:

D:\CAO HOC\TAI LIEU THAM KHAO\ANTLR-EBNF\CREATE PARSTREE\TestP.java:14: 
cannot find symbol
symbol  : constructor PParser(org.antlr.runtime.CommonTokenStream,org.antlr.runtime.debug.ParseTreeBuilder)
location: class ParserAndLexer.PParser
    PParser parser=new PParser(tokens,builder);

When I drop one argument builder in PParser(tokens,builder) then that error not found. but i don't know how to run to have the following result:

java TestP
int i;
i=4;
(<grammar prog> (prog (decl (type int) i ;) (stat i = (expr 4))))
+2  A: 

Nguyen,

To make this work, I found that when you generate the parser and lexer you need to include the "-debug" argument like so:

java -jar antlr-3.2.jar yourGrammar.g -debug

That way, the extra constructor will be built.

Jon
A: 

Thank you very much, Jon. I have done it, very good.

nguyen
While it may look like it, this isn't a forum. Mark his answer as correct and move on.
Task