Greetings!

On 11/11/2011 03:00 AM, D. Frej wrote:
> The grammar is rather stupid and simple
... snipped ...

> It is executed with the following Java code
> 
> ANTLRStringStream input = new ANTLRStringStream("15 / 7.25 +4");
> ExpressionLexer lex = new ExpressionLexer(input);
> CommonTokenStream tokens = new CommonTokenStream(lex);
> 
> ExpressionParser g = new ExpressionParser(tokens); //, 49100, null);
> try {
>      ExpressionParser.content_return r = g.content();
> 
>      CommonTree ctree = (CommonTree) r.getTree();
>      System.out.println("ctree.type|" + ctree.getType() + "|" + 
> ExpressionParser.tokenNames[ctree.getType()] + "|");
> } catch (RecognitionException e) {
>      e.printStackTrace();
> }
> 
> Yet here the input of "15 / 7.25 +4" does not work. Eclipse outputs 
> "ctree.type|0|<invalid>|". 

it actually does parse correctly. you are not printing the result
properly. the result of the parse is a tree and yet you try to print it
as if it were a token.

use ctree.toStringTree() in your println instead.

> When I use simply "15" as input, I get the - 
> correct - output "ctree.type|7|INT|".
> 

because the tree in this case is simply a single token.




i do not use ANTLRWorks so can not speak to your experiences with that tool.

hope this helps...
   -jbb


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 il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.

Reply via email to