[antlr-interest] mismatched tree node

Mark Volkmann r.mark.volkmann at gmail.com
Fri Dec 7 12:21:17 PST 2007


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