Live data from Hacker News

Inverse Parentheses

kellett.im

31–40 of 67 posts

Re: Inverse Parentheses

#31
I am in the middle of developing a parser for a new language with original representation vs. syntax issues to resolve.

Clearly, this was the worst possible time for me to come across this brain damaging essay.

I really can’t afford it! My mathematical heart can’t help taking symmetrical precedence control seriously. But my gut is experiencing an unpleasant form of vertigo.

Re: Inverse Parentheses

#32
Is it the same as flipping every parenthesis to the other side of the number it's adjacent to, and then adding enough parentheses at the start and end?

For example,

    (1 + 2) * (3 + 4)
becomes

    1) + (2 * 3) + (4
and then we add the missing parentheses and it becomes

    (1) + (2 * 3) + (4)
which seems to achieve a similar goal and is pretty unambiguous.

Re: Inverse Parentheses

#33
post #6

I was hoping the parentheses themselves would be flipped. Like this: > 1 + )2 * 3( (1 + 2) * 3

I think surrounding the operand would make slightly more sense, as in 1 + 2 (*) 3 as if it's a "delayed form" of the operation that it represents.

If you do both (use flipped parentheses around the operators), it makes even more sense, and makes the parsing trivial to boot: just surround the entire expression with parentheses and parse normally. For instance: 1 + 2 )( 3 Becomes (1 + 2 )( 3) Which is actually just what the author wants. You might even want multiple, or an arbitrary numbers of external parentheses. Say we want to give the divide the least precedence, the multiply the middle, and the add the most. We could do that like: 1 + 2 )/( 3 ))(( 4 Surround it with two sets of parens and you have: ((1 + 2 )/( 3 ))(( 4)) I haven't just proved to myself this always does what you expect, though...

Re: Inverse Parentheses

#34
post #29
post #8

I'm all for terseness in blog writing, but I think the author forgot to add the content. I know nothing more than I did when I opened it.

And yet, this is the top entry on HN right now?! How does that happen??

I read the article twice and still doesn't make sense. I tried to make sense but no matter how I slice and dice the article, the "inverse parentheses" idea seems inconsistent or ill defined.

Two comments here which explain the ill-definedness of it:

https://news.ycombinator.com/item?id=46352560

https://news.ycombinator.com/item?id=46352697

Re: Inverse Parentheses

#35
post #29
post #8

I'm all for terseness in blog writing, but I think the author forgot to add the content. I know nothing more than I did when I opened it.

And yet, this is the top entry on HN right now?! How does that happen??

Engagement from people trying to figure it out :-)

Re: Inverse Parentheses

#36
post #21

Slightly unrelated: Instead of ordinary brackets, one can also use the dot notation. I think it was used in Principia Mathematica or slightly later: (A (B (C D))) would be A . B : C .: D Essentially, the more dots you add, the stronger the grouping operator is binding. The precedence increases with the number of dots. However, this is only a replacement for ordinary parentheses, not for these "reverse" ones discussed…

could this be the origin of lisp and ML family list notation ?

Re: Inverse Parentheses

#37

Based on this comment ( https://news.ycombinator.com/item?id=46352389 ), I think I understood the missing first paragraph: If you have the expression 1+2*3 you have three elements with two operands. You need to choose a rule to pick one of them first. In mathematics, the rule is "*/ then +-" and then from left to right. This means that usually first you do 2*3, then 1+. But what if you do want to make 1+2 first? Ther…

If we actually (as the title seems to imply) invert the parentheses, then for your example we get 1+2)*(3 .

Now all you need are the opening and closing parentheses at the start and end, and we're back to normal.

Re: Inverse Parentheses

#38

The concept of "inverse parentheses" that unbundle operators is brilliant! The tokenizer hack (friendliness score by parenthesis depth, inspired by Python INDENT/DEDENT) + precedence climbing for infinite levels is elegant – parsing solved without convoluted recursive grammar. kellett I love the twist: reversing the friendly levels gives you a classic parser, and it opens up crazy experiments like whitespace weakenin…

llm generated comment
Post reply on HN