[antlr-interest] ANTLR 3(ea8) TreeNodeStream DOWN & UP insertion question.

Anthony Harrison anh23 at pitt.edu
Mon May 22 12:07:15 PDT 2006


I'm not sure if this is a bug or just a general misunderstanding on my
part, but something seems wonky when running a tree parser over a tree
that only has optional children. Specifically, something like ^(ROOT
OPTIONAL_CHILD*) will throw mismatches when no children are present
because DOWN & UP are not being inserted by the TreeNodeStream.

My tree parser looks something like this (cutting out all the irrelevant bits):

//model must be ^(MODEL_TOKEN NAME_TOKEN MODULES_TOKEN PARAMETERS_TOKEN)
model : ^(MODEL_TOKEN NAME_TOKEN modules parameters);

// must always have MODULES tag, and possibly individual module trees
modules : ^(MODULES_TOKEN module*);

module : ^(MODULE_TOKEN CLASS_TOKEN); //just a class name ref

//must have PARAMETERS token and maybe some parameters
parameters : ^(PARAMETERS_TOKEN parameter*);

parameter : ^(PARAMETER_TOKEN NAME_TOKEN STRING_TOKEN);


Model must have three children: NAME_TOKEN, MODULES_TOKEN, and
PARAMETERS_TOKEN. Both MODULES_TOKEN and PARAMETERS_TOKEN may or may
not have additional children.

When I provide it with this tree, everything is fine:

^(MODEL_TOKEN NAME_TOKEN
       ^(MODULES_TOKEN
            (MODULE_TOKEN CLASS_TOKEN))
       ^(PARAMETERS_TOKEN
            (PARAMETER_TOKEN NAME_TOKEN STRING_TOKEN)))

Fine and dandy.

However.

When I provide it with a tree where either modules or parameters has
no children, I get oodles of mismatches because it is looking for DOWN
(2) and UP(3), which aren't being generated. (specifically
MismatchedTreeNodeEx (0!=2) or 3)

^(MODEL_TOKEN NAME_TOKEN
       ^(MODULES_TOKEN )
       ^(PARAMETERS_TOKEN ))

Since the TreeParser code generated demands the matching of DOWN token
regardless of their being any children, shouldn't the TreeNodeStream
be inserting the DOWN & UPs in this case regardless of the presence of
said children?

Any help with this (most likely) misunderstanding on my part would really help.


the full grammar is attached, with static test methods.

TestParser.testGoodModel() will traverse the fully specified tree
(generated via createWorkingTree())
TestParser.testBadModel() will try to traverse the partially specified
tree (generated via createFailingButValidModelTree())


Many thanks to anyone who can show me the errs of my ways.
-- 
+------------------------------------------------------------+
  "Theories are more like graduate students -
    once admitted you try hard to avoid flunking
    them out, it being much better for them and
    for the world if they can become long-term
    contributors to society."
                - Allen Newell, 1990

  Anthony M. Harrison
  http://simon.lrdc.pitt.edu/~harrison/
  anh23 at pitt.edu
  Learning Research and Development Center
  University of Pittsburgh
-------------- next part --------------
A non-text attachment was scrubbed...
Name: parser.g
Type: application/octet-stream
Size: 3817 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20060522/a96776c1/parser.obj


More information about the antlr-interest mailing list