3 ms·
Very interesting. I am actually working for a few days now on something very related: Generate syntax tree data structures (in Swift) from a grammar (which is t
by auggierose 6y ago
Very interesting. I am actually working for a few days now on something very related: Generate syntax tree data structures (in Swift) from a grammar (which is the actual grammar used for parsing). What I found very useful is to distinguish between hidden, auxiliary and visible symbols. Hidden symbols don't appear in the tree, visible symbols appear as normal, and for auxiliary symbols only their children appear in the syntax tree. Seems to work very nicely so far. This way, left oder right recursion for example doesn't matter if your recursion symbol is auxiliary, because it will just be flattened into a list anyway. Therefore I can use regular expressions in a grammar by desugaring them via auxiliary symbols in the usual way via context-free rules, and have a sensible syntax tree generated for that.
- barrkel 6y agoLeft or right recursion makes a semantic difference for non-associative operators like subtraction.
- auggierose 6y agoIn those cases I'd suggest you don't make the corresponding symbol auxiliary.