[antlr-interest] mismatched tree node

Mark Volkmann r.mark.volkmann at gmail.com
Fri Dec 7 15:09:05 PST 2007


The problem was that I also had a lexer rule in my lexer/parser
grammar named SIGN that matched '+' and '-' just like the non-lexer
rule in my tree grammar.

On Dec 7, 2007 2:21 PM, Mark Volkmann <r.mark.volkmann at gmail.com> wrote:
> I'm trying to understand why my tree parser is giving me a "mismatched
> tree node: - expecting <UP>" error.
> Here's the string representation of the simple AST it is processing.
>
> (SCRIPT (FUNCTION f x (POLYNOMIAL (TERM 3 x 2) - (TERM 5 x) + (TERM
> 7))) (FIND f 1))
>
> It doesn't like the minus sign between the first and second TERM. It
> also doesn't like the plus sign between the second and third term.
>
> Here is my tree grammar, stripped down to the bare minimum that will
> reproduce the problem.
>
> tree grammar MathTree;
>
> options {
>   ASTLabelType = CommonTree;
>   tokenVocab = Math;
>   output = template;
> }
>
> @header {
>   package com.ociweb.math;
> }
>
> script: ^(SCRIPT statement*);
>
> statement: ^(FUNCTION name=NAME variable=NAME polynomial);
>
> polynomial: ^(POLYNOMIAL term (sign term)*);
>
> sign:   '+' | '-';
>
> term
>   :     ^(TERM NUMBER)
>   |     ^(TERM NUMBER NAME)
>   |     ^(TERM NAME NUMBER)
>   |     ^(TERM NUMBER NAME NUMBER)
>   ;

-- 
R. Mark Volkmann
Object Computing, Inc.


More information about the antlr-interest mailing list