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://[email protected]
Skype: callto://costas.kakousis
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address
--
You received this message because you are subscribed to the Google Groups
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/il-antlr-interest?hl=en.