Menu

Operators

2017-04-17
2019-10-25
  • Brian Tiffin

    Brian Tiffin - 2017-04-17

    Finally taking a more serious stab at the Operators chapter of the UP docs.

    I may have read the precedence table in src/unicon/unigram.y wrong

    expr8   : expr9 ;
            | postfixthreadop ;
            | expr9 CARET expr8 { $$ := node("Bcaret", $1,$2,$3);} ;
    
    postfixthreadop:
              expr9 SND { $$ := node("Bsnd", $1,$2,EmptyNode);} ;
            | expr9 SNDBK { $$ := node("Bsndbk", $1,$2,EmptyNode);} ;
            | expr9 RCV { $$ := node("Brcv", $1,$2,EmptyNode);} ;
            | expr9 RCVBK { $$ := node("Brcvbk", $1,$2,EmptyNode);} ;
    
    expr9   : expr10 ;
            | expr9 BACKSLASH expr10 { $$ := node("limit", $1,$2,$3);} ;
            | expr9 AT expr10 { $$ := node("at", $1,$2,$3);} ;
            | expr9 SND expr10 { $$ := node("Bsnd", $1,$2,$3);} ;
            | expr9 SNDBK expr10 { $$ := node("Bsndbk", $1,$2,$3);} ;
            | expr9 RCV expr10 { $$ := node("Brcv", $1,$2,$3);} ;
            | expr9 RCVBK expr10 { $$ := node("Brcvbk", $1,$2,$3);} ;
            | expr9 BANG expr10 { $$ := node("apply", $1,$2,$3);};
    

    unigram.y

    I take that as placing the postfix >@ send operator (and friends) at a lower precedence than the infix form. But now I'm thinking they are all at "level 9", (or are they wedged in between at 8b)?

    See the precedence chart (based on the ProIcon docs and modified) at

    http://btiffin.users.sourceforge.net/up/operators.html

    Is exponentiation grouped with e1 >@ or should postifx >@ be grouped with infix e1 >@ e2 ?

    I think I have this wrong, and could use some expert advice.

    Cheers,
    Brian

     
    • Bruce Rennie

      Bruce Rennie - 2017-04-17

      Good evening Brian,

      The @>, @>>, <@ and <<@ have problematic precedence as they are unary
      prefix, unary postfix, binary and operandless. The actual design is

      [x] op [y]

      with both x and y optional. Hence, giving rise to unary prefix, unary
      postfix, binary and operandless. Based on previous discussion (thanks
      Jafar), they should be considered binary with the missing operand
      defaulting to a specific value for each case. The precedence of each
      operand is spread over a number of levels, more than just between expr8
      and expr9 (you also need to include expr11 as well).

      I, personally, think that the grammar description needs more thought and
      clarification. But at this point, I am not sure what should be proposed.
      I am having a look at various renderings to see what happens, but I am
      not far into this process.

      One proposal so far is

      exprx :

             expr9  SND  {  $$  :=  node("Bsnd",  $1,$2,EmptyNode);}  ;
           |  expr9  SNDBK  {  $$  :=  node("Bsndbk",  $1,$2,EmptyNode);}  ;
           |  expr9  RCV  {  $$  :=  node("Brcv",  $1,$2,EmptyNode);};
           |  expr9  RCVBK  {  $$  :=  node("Brcvbk",  $1,$2,EmptyNode);}  ;
           |expr9  SND  expr10{  $$  :=  node("Bsnd",  EmptyNode,$2,$3);}  ;
           |  expr9  SNDBK  expr10 {  $$  :=  node(Bsndbk,EmptyNode,$2,$3);}  ;
           |  expr9  RCV  expr10{  $$  :=  node("Brcv",  EmptyNode,$2,$3);}  ;
           |  expr9  RCVBK  expr10{  $$  :=  node("Brcvbk",  Emptynode,$2,$3);}  ;
           | SND{  $$  :=  node("Bsnd",  EmptyNode,$1,EmptyNode);}  ;
           |  SNDBK  {  $$  :=  node("Bsndbk",  EmptyNode,$1,EmptyNode);}  ;
           |  RCV  {  $$  :=  node("Brcv",  EmptyNode,$1,EmptyNode);};
           |  RCVBK  {  $$  :=  node("Brcvbk",  EmptyNode,$1,EmptyNode);}  ;
      

      But I don't know what ramification this would have.

      Jafar has clarified some questions I have had. I still don't have
      enough clarity as to what is a cleaner set of productions.

      regards

      Bruce Rennie

       
      • Brian Tiffin

        Brian Tiffin - 2017-04-18

        Thanks, Bruce. Clarifies a little bit. I'm going to leave the chart as-is for the moment, perhaps add the exceptions in prose following the table.

        Cheers,
        Brian

         
  • Jafar

    Jafar - 2017-04-18

    You are correct Bruce. I view the communication operators as binary operators, missing right operands defaults to the current thread , while missing left operand defaults to null. If I remember our initial design, the intention was all forms have the same priority with them being resolved left to right.

    Cheers,
    Jafar

     
    • Jafar

      Jafar - 2017-04-18

      Of course, as you and I discussed before Bruce, default left operand make sense with @> and @>> where you just send &null. with <<@ it the left operand is a timeout of how long you are willing to block, but there is no intuitive clear meaning for <@. I have experiementd with a few but was not satisfied. If you can think if some good use for it please let me knwo.

      --Jafar

       
      • Bruce Rennie

        Bruce Rennie - 2017-04-18

        I am thinking of making a change to the grammar as I sort of outlined
        earlier and see what this does with the current system. But I won't be
        ready for this until after I have finished the things currently on my
        plate, including a new lexer sub-system for the regexp facility.

        regards

        Bruce Rennie

         
  • Charles Evans

    Charles Evans - 2017-07-31

    Great resource, Brian, thanks!

     
  • Charles Evans

    Charles Evans - 2017-08-01

    Could you put a link to your string scanning page in the "?" operator section? Thanks.

     
    • Brian Tiffin

      Brian Tiffin - 2019-10-25

      Umm, two years later, ... noticed.

      Should be fixed in 0.6.148. Which might contain a few loose edges at the moment, a reindexing work is in progress.

      https://unicon.sourceforge.io/up/operators.html#string-scan

      Sorry, Charles, and thanks for the hint.

      Have good

       

      Last edit: Brian Tiffin 2019-10-25

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.