• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can you mix left-associative and right-associative operators on the same line in a grammar?

 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a grammar to write, which includes the operations for range restriction and subtraction, and domain restriction and subtraction, which I shall call RROp, RSOp, DROp and DSOp. The operators for restriction are little triangles, which have 25b7 and 25c1 as their Unicode numbers, and the subtraction operators are similar with a - superimposed, and I am blowed if I can find them in Unicode at all

Now, I think I can get away with a BNF grammar like this

restrictedSet ::= relationSet | relationSet RROp flatSet | relationSet RSOP flatSet | flatSet DROp relationSet | flatSet DSOp relationSet

Where A and B are each homogeneous sets, and a flat set is one described by [member of]P(A), and a relation set is one described by [member of] P(A x B) where the large P is as near as I can get to "powerset." A flat set is homogeneous, containing only members of one type, no included sets, and the relation set is also homogeneous, containing only ordered pairs (or mappings) of one or two consistent types. That example would work for domain restriction; for range restriction you would swap the A and B around.

Now that means, I think, that the two operators have the same precedence, and DROp associates to the right, and RROp associates to the left.

Has anybody got any idea whether I am correct there, or mistaken? If I am mistaken, I shall change the grammar so DROp associates to the right, and has a higher precedence than RROp, which still associates to the left.

This little bit of code shows the operators, or as near as I can get to it:I can't get the triangles and - superimposed. Maybe somebody else can. The operators show nicely on my Linux shell, but will probably appear as boxes on a DOS/Windows command window.
 
Morning came much too soon and it brought along a friend named Margarita Hangover, and a tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic