kosen13s / tiny

A tiny programming language to improve kosen13s' skills
MIT License
4 stars 0 forks source link

Constructing syntax trees #11

Closed Roadagain closed 7 years ago

Roadagain commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

@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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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

Roadagain commented 7 years ago

well... i will try it.

Roadagain commented 7 years ago

succeeded. is there any job not-implemented?

Iruyan-Zak commented 7 years ago

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

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

Iruyan-Zak commented 7 years ago

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

Roadagain commented 7 years ago

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

Roadagain commented 7 years ago

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