Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

Campbell Ritchie
Posts: 50699
  • Mark post as helpful
  • send pies
  • 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.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic