[antlr-interest] Newbie Q: does grammar tree structure matter?

Johannes Luber jaluber at gmx.de
Sat Nov 17 09:33:04 PST 2007


Steve Bennett wrote:
> Hi all,
>   Question as I think about designing a grammar: how much does the
> resulting tree structure matter? For example, a rule like X: P+; will
> create a horizontal tree, whereas X:P X?; will create deep nesting. Is
> it a bad idea to design around the idea of trying to avoid this sort
> of nesting? Should I just use recursion whenever convenient? Is trying
> to keep the tree pretty a total waste of time? :)

I was the opinion that without using the '^'-symbol or an explicit
rewrite the output will be always a flat list. Otherwise some examples
in the book wouldn't make sense. As I haven't done much with tree output
yet, I can't say for sure but make is it to mimic the grammar structure
in the tree. It makes creating a tree grammar easier. I would deviate
from the input grammar structure, if using extra subtrees for ordering
and adding semantic information is useful for later processing.

> The project will be a pretty big and complicated markup->HTML translator.

I suggest to create a syntactic parser for the first pass, if you
require a global view over the input files. This will result in a
superset over the language, which you have to check in a semantic parse
later, but allows you to accommodate for common errors better.

Johannes


More information about the antlr-interest mailing list