[antlr-interest] My first tree walker

Terence Parr parrt at cs.usfca.edu
Fri Dec 10 09:04:04 PST 2010


sounds like a token type mismatch...make sure FUNCTION is same in all grammars
T
On Dec 10, 2010, at 5:56 AM, Simon Manschitz wrote:

> Hi,
> 
> i am trying to walk over a tree with this forum (tree.toTreeString-Method):
> 
> (function (OUTPUT output) (NAME test2) (INPUT input) (= output (- 4 input)))
> 
> My tree walker looks like this:
> 
> tree grammar MatlabTreeWalker;
> 
> options {
>   language = Java;
>   tokenVocab = Matlab;
>   ASTLabelType = CommonTree;
> }
> 
> walk: ^(FUNCTION
>     function_output
>     function_name
>     function_input
>     expression);
> 
> function_output: ^(OUTPUT IDENT);
> function_name: ^(NAME IDENT);
> function_input: ^(INPUT IDENT);
> 
> expression:
>   ^('=' expression expression) { System.out.println("t1"); }
>   | ^(MINUS o1=expression o2=expression) { System.out.println("t2"); }
>   | IDENT { System.out.println("t3"); }
>   | REAL_NUMBER { System.out.println("t4"); };
> 
> But i always receive this error: MatlabTreeWalker.g: node from line 1:0 
> mismatched tree node: function expecting FUNCTION. Has anyone an idea 
> why i get this error? FUNCTION is a lexer rule FUNCTION: 'function'; I 
> think he has problems to find the (OUTPUT IDENT) but i have no idea why? 
> Can somebody help me?
> 
> Bye, Simon.
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address



More information about the antlr-interest mailing list