[antlr-interest] Test class for tree grammars
Konstantinos Kakousis
csp7kk3 at cs.ucy.ac.cy
Tue Jan 26 07:34:33 PST 2010
Hello,
I have my grammar and tree grammars working exactly as expected at the
AntlrWorks.
Now I was trying to run from console or Eclipse the same grammar using
the following Test.java
class:
import org.antlr.runtime.ANTLRStringStream;
import org.antlr.runtime.CommonTokenStream;
import org.antlr.runtime.RecognitionException;
import org.antlr.runtime.tree.CommonTree;
import org.antlr.runtime.tree.CommonTreeNodeStream;
import org.antlr.runtime.tree.Tree;
public class Test{
public static void main (String[] args){
try{
String in = "5+6*7";
ANTLRStringStream input = new ANTLRStringStream(in);
UtilityLexer lexer = new UtilityLexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
UtilityParser parser = new UtilityParser(tokens);
UtilityParser.prog_return r = null;
r = parser.prog();
CommonTree t = (CommonTree)r.getTree(); // get tree from parser
System.out.println("Parse Tree:"+t.toStringTree());
CommonTreeNodeStream nodes = new CommonTreeNodeStream(t);
System.out.println ("Here1");
nodes.setTokenStream(tokens);
System.out.println ("Here2");
UtilTree walker = new UtilTree(nodes);
System.out.println ("Here3");
walker.prog();
System.out.println ("Here4");
} catch (RecognitionException e) {
e.printStackTrace();
}
}
}
From the output:
Parse Tree:(+ 5 (* 6 7))
Here1
Here2
It seems that the programs hangs on the following command:
UtilTree walker = new UtilTree(nodes);
Is there somewhere a standard Test.java class for running the generated
grammars?
Is there something wrong with the above class?
BR,
--
Konstantinos Kakousis
Research Associate
Department of Computer Science
University of Cyprus
Address: P.O. Box 20537, CY-1678, Nicosia, Cyprus
Tel: +357 22892684
Fax: +357 22892701
Webpage: http://www.cs.ucy.ac.cy/~csp7kk3
Email: mailto://kakousis@cs.ucy.ac.cy
Skype: callto://costas.kakousis
More information about the antlr-interest
mailing list