Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syntax trees #9

Closed
goodmami opened this issue Apr 20, 2020 · 1 comment
Closed

Syntax trees #9

goodmami opened this issue Apr 20, 2020 · 1 comment
Labels
enhancement New feature or request

Comments

@goodmami
Copy link
Owner

pe does not work with overt syntax trees, whether concrete (CST) or abstract (AST), but they can be useful for debugging. I think it is straightforward to implement both:

For CSTs, a recursive function similar to the optimizers would traverse the parse graph and make each expression a rule with an action that generates a CST node. This modified grammar is separate from the one normally used for parsing and is used only for debugging.

For ASTs, node-generating rules are inserted only where it makes sense. One method is to replace existing actions with the AST node action, since nodes with actions are generally semantically meaningful. It would also be nice to accept a collection of nonterminal names and those specifically get node actions, which allows the user to create arbitrary ASTs and can also show what the normal semantic actions below those nodes are returning. Semantic actions above AST nodes would either have to be disabled, or the AST nodes need to somehow pass up their values so the actions don't break on unexpected input.

@goodmami goodmami added the enhancement New feature or request label Apr 20, 2020
goodmami added a commit that referenced this issue Apr 23, 2020
goodmami added a commit that referenced this issue Apr 23, 2020
@goodmami
Copy link
Owner Author

I think this was essentially done in d347f33

ASTs and CSTs help with debugging, but if someone actually wants a tree to be the result of parsing, they can create a custom action for it. At some point it might make sense to provide such an action, but for now the DEBUG solution is enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant