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

Constructing syntax trees #11

Closed
Roadagain opened this issue Jun 29, 2017 · 11 comments
Closed

Constructing syntax trees #11

Roadagain opened this issue Jun 29, 2017 · 11 comments

Comments

@Roadagain
Copy link
Member

Roadagain commented Jun 29, 2017

i guess the trees will be like this constructed by values and binary operators.

data Tree token = Leaf token | Node (Tree token) token (Tree token)

i have 2 questions:

  1. is it cool?
  2. how should we configure prefix and postfix operators (include unary operators)?
@Roadagain
Copy link
Member Author

i guess constructing unary operators as Unary token (Tree token) and renaming Node to Binary.
then it changes like this:

data Tree token = Leaf token |
                  Binary (Tree token) token (Tree token) |
                  Unary token (Tree token)

if we use this construction, should we rename Leaf too?

@Iruyan-Zak
Copy link
Collaborator

@Roadagain

  1. is it cool?

agree to your idea completely.

  1. how should we configure prefix and postfix operators (include unary operators)?

Your last comment is better.
In my head, the order between prefix and suffix operators is suffix priority.

  1. should we rename Leaf too?

I think it's no problem naming.
Because Binary is regarded as an omission of "binary tree" and Unary too, so Leaf means "the leaf of a binary or unary tree."
Further, Tree is general naming and usable generally, so Leaf should be also general one. (or rename Tree.)

@Roadagain
Copy link
Member Author

constructing trees has been done by a2a266d, but it doesn't seem beautiful.

i have two ideas:

  1. rewrite Tree (with StateT?)
  2. reconfigure trees

if you have something else, write here.

Roadagain added a commit that referenced this issue Jul 6, 2017
Roadagain added a commit that referenced this issue Jul 6, 2017
Move past TreeState to LexicalTreeState
Roadagain added a commit that referenced this issue Jul 6, 2017
Roadagain added a commit that referenced this issue Jul 6, 2017
@Roadagain
Copy link
Member Author

bugfix has been done, then i wish to implement prioritized construct.
i hope to add a new field holds priority (maybe Int) to Token.

@Iruyan-Zak
Copy link
Collaborator

Cannot you deal with it with an associated array (operator => priority)?

@Roadagain
Copy link
Member Author

well... i will try it.

@Roadagain
Copy link
Member Author

succeeded.
is there any job not-implemented?

@Iruyan-Zak
Copy link
Collaborator

Great job. roll function looks cool solution for me!!!

btw, I was surprised by returning an unary tree from binary function...

@Iruyan-Zak
Copy link
Collaborator

If you think it is a no important problem, please create PR now.

@Roadagain
Copy link
Member Author

i've forgotten it is implemented to make easier to test.
i will add an integrated function to construct syntax trees.

@Roadagain
Copy link
Member Author

i guess no functions can surprise u already.
can i create pull-req?

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

No branches or pull requests

2 participants