Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

For a good use of operator overloading, check out Boost.Spirit, which implements EBNF grammars directly in C++: http://spirit.sourceforge.net/

An example, from the user's guide:

  struct calculator : public grammar<calculator> {
    template <typename ScannerT>
    struct definition {
      definition(calculator const& self)
      {
        group       = '(' >> expression >> ')';
        factor      = integer | group;
        term        = factor >> *(('*' >> factor) | ('/' >> factor));
        expression  = term >> *(('+' >> term) | ('-' >> term));
      }

      rule<ScannerT> expression, term, factor, group;

      rule<ScannerT> const& start() const
      {
        return expression;
      }
    };
  };
This is nowhere near as concise as it would be in, say, OCaml, but if you're already using C++, it's useful.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: