The Artima Developer Community
Sponsored Link

Heron-Centric: Ruminations of a Language Designer
Heron Operator Precedence
by Christopher Diggins
September 6, 2005
Operator precedence in Heron is tricky, because any sequence of legal operator characters is a legal operator.


At the present moment I leaning towards setting operator precedence in Heron :

  1. unary expressions (prefix operations)
  2. multiplicative * / %
  3. additive + -
  4. other
  5. assignment =
  6. comma ,

Here is the problem I am facing: In Heron there are no predefined operators. Any sequence of operator characters is in fact a legal operator. All operators map to a specifically named member function of the left hand value.

An example of a problem with just following C++ operator precedence rules is that an overloaded pipe operator (|) might actually mean to create a pipe and not bitwise or. Even > could have multiple meanings like redirect output to a file or greater than. Giving it a specific precedence based on usage of bitwise or is not a good idea. What about entirely new operators, like &&= which means assignment boolean and. It should be at the same level as the other assignment operators. Anyway the list of complications goes on and on. I think beyond the simple arithmetic precedence rules, it is best if I rely on disamibguation rules.

Maybe there is another way that everyone can be happy: I wonder if there there is an elegant way to implement precedence directly within a language? Maybe there would be an expression reordering step, that is controllable from code. Perhaps something inspired by expression template machinery? Perhaps operators could map to types or function pointers? I am open to new ideas here.

Talk Back!

Have an opinion? Readers have already posted 5 comments about this weblog entry. Why not add yours?

RSS Feed

If you'd like to be notified whenever Christopher Diggins adds a new entry to his weblog, subscribe to his RSS feed.

About the Blogger

Christopher Diggins is a software developer and freelance writer. Christopher loves programming, but is eternally frustrated by the shortcomings of modern programming languages. As would any reasonable person in his shoes, he decided to quit his day job to write his own ( ). Christopher is the co-author of the C++ Cookbook from O'Reilly. Christopher can be reached through his home page at

This weblog entry is Copyright © 2005 Christopher Diggins. All rights reserved.

Sponsored Links


Copyright © 1996-2018 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use