About Trees
2 posts
• Page 1 of 1
About Trees
Hi All,
With help of this page http://dfns.dyalog.com/n_parse.htm
i try :
good result for automatic process, hardest for (standard) human reader.
Have you idea for how to transform it in
easier to see the difffrence for ,,
but for human reader, .∘, make senses in ⍵ F ⍵
each leaves make senses for human reader
Have a good day,
Yves
With help of this page http://dfns.dyalog.com/n_parse.htm
i try :
parse '{,⍵∘.,,⍵∘.,,⍵∘.,⍵}'sorry for the fixed font.
┌─┬────────────────────────────────┬─┐
│{│ A │}│
│ │┌───┴───┐ │ │
│ │, ┌────┴─────┐ │ │
│ │ ┌┴─┐ ┌───┴───┐ │ │
│ │ ⍵ ┌┴─┐ , ┌────┴────┐ │ │
│ │ ∘ ┌┴┐ ┌┴─┐ ┌──┴──┐ │ │
│ │ . , ⍵ ┌┴─┐ , ┌──┴───┐│ │
│ │ ∘ ┌┴┐ ┌┴─┐ ⍵│ │
│ │ . , ⍵ ┌┴─┐ │ │
│ │ ∘ ┌┴┐ │ │
│ │ . , │ │
└─┴─────────────────────────────────┴─┘
good result for automatic process, hardest for (standard) human reader.
Have you idea for how to transform it in
┌─┬────────────────────────────────────┬─┐
│{│ A │}│
│ │ ┌──┴───┐ │ │
│ │ , ┌───┼───────┐ │ │
│ │ ⍵ ∘ ┌──┴──┐ │ │
│ │ ┌┴┐ , ┌───┼──────┐ │ │
│ │ . , ⍵ ∘ ┌──┴──┐ │ │
│ │ ┌┴┐ , ┌───┼───┐ │ │
│ │ . , ⍵ ∘ ⍵ │ │
│ │ ┌┴┐ │ │
│ │ . , │ │
└─┴─────────────────────────────────────┴─┘
easier to see the difffrence for ,,
but for human reader, .∘, make senses in ⍵ F ⍵
┌─┬────────────────────────────────────┬─┐
│{│ A │}│
│ │ ┌─┴───┐ │ │
│ │ , ┌───┼──────┐ │ │
│ │ ⍵ .∘, ┌──┴──┐ │ │
│ │ , ┌───┼───────┐ │ │
│ │ ⍵ .∘, ┌───┴──┐ │ │
│ │ , ┌───┼───┐ │ │
│ │ ⍵ .∘, ⍵ │ │
└─┴────────────────────────────────────┴─┘
each leaves make senses for human reader
Have a good day,
Yves
- Yves
- Posts: 39
- Joined: Mon Nov 30, 2015 11:33 am
Re: About Trees
The Bunda-Gerth parser at http://dfns.dyalog.com/n_parse.htm returns a binary expression tree by:
- binding left arguments and right operands to derive monadic functions and operators
- binding adjacent pairs of array items (vectors) and functions (trains) from the left.
It also preserves brackets.
I think what Yves would prefer is an n-ary tree with the components of vectors and tacit functions at the same level.
or collecting together "simple" components such as +⌿ and +.×:
I don't have such a function but perhaps someone out there does?
- binding left arguments and right operands to derive monadic functions and operators
- binding adjacent pairs of array items (vectors) and functions (trains) from the left.
It also preserves brackets.
)xload dfns
... saved ...
try ← scripts._dyalog∘parse ⍝ parser with sample Dyalog syntax table
try'1 2 3 4' ⍝ vector
A
┌─┴─┐
┌┴─┐ 4
┌┴┐ 3
1 2
try'+-×÷' ⍝ train
F
┌─┴─┐
┌┴─┐ ÷
┌┴┐ ×
+ -
try'(+⌿÷≢)⍺(⍺+⍵)(⍺+.×⍵)⍵' ⍝ a more complex expression
A
┌─────────┴──────────┐
┌──┴──┐ ┌──────┴───────┐
( ┌─┴─┐ ┌────┴─────┐ ⍵
┌┴─┐ ≢ ┌─┴─┐ ┌──┴──┐
┌┴┐ ÷ ⍺ ┌─┴─┐ ( ┌──┴───┐
+ ⌿ ( ┌┴─┐ ┌┴─┐ ⍵
┌┴┐ ⍵ ⍺ ┌┴─┐
⍺ + + ┌┴┐
. ×
I think what Yves would prefer is an n-ary tree with the components of vectors and tacit functions at the same level.
try'1 2 3 4'
┌─┬┴┬─┐
1 2 3 4
try'+-×÷'
┌─┬┴┬─┐
+ - × ÷
try'(+⌿÷≢)⍺(⍺+⍵)(⍺+.×⍵)⍵'
┌─────┴─────┐
┌──┼─┐ ┌───┬───┴───┬─────┐
┌┴┐ ÷ ≢ ⍺ ┌─┼─┐ ┌───┼───┐ ⍵
+ ⌿ ⍺ + ⍵ ⍺ ┌─┼─┐ ⍵
+ . ×
or collecting together "simple" components such as +⌿ and +.×:
try'(+⌿÷≢)⍺(⍺+⍵)(⍺+.×⍵)⍵'
┌───┴─────┐
┌─┼─┐ ┌──┬──┴──┬────┐
+⌿ ÷ ≢ ⍺ ⍺+⍵ ┌──┼──┐ ⍵
⍺ +.× ⍵
I don't have such a function but perhaps someone out there does?
- JohnS|Dyalog
2 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group