Skip to content

Implement a prettier function for (converting back to and) printing the concrete syntax of a syntax tree #9

@bubba2k

Description

@bubba2k

The current function for extracting the concrete syntax from a syntax tree and printing it lp_tree_print:

void lp_tree_print(TreeNode *node)
prints a lot of superfluous parenthesis (every operator and its operand(s) are explicitly surrounded by parenthesis to highlight precedence as given in the syntax tree). This is great for debugging the parser and checking whether it got the precedence of operators right, but not very pleasing to the end user's eye.

Implementing a prettier function that does not print explicit parenthesis every time might be in order.
Implementation idea: For each node (operator) in the tree, only print parenthesis if the parent node (operator) has higher precedence.
Might work like this, might not; to be explored.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions