You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.1 KiB

  1. #include "cpphoafparser/consumer/hoa_intermediate.hh"
  2. #include "cpphoafparser/consumer/hoa_consumer_null.hh"
  3. #include "cpphoafparser/parser/hoa_parser.hh"
  4. using namespace cpphoafparser;
  5. /* An HOAIntermediate that counts invocations of addState */
  6. class CountStates : public HOAIntermediate {
  7. public:
  8. typedef std::shared_ptr<CountStates> ptr;
  9. unsigned int count = 0;
  10. CountStates(HOAConsumer::ptr next) : HOAIntermediate(next) {
  11. }
  12. virtual void addState(unsigned int id,
  13. std::shared_ptr<std::string> info,
  14. label_expr::ptr labelExpr,
  15. std::shared_ptr<int_list> accSignature) override {
  16. count++;
  17. next->addState(id, info, labelExpr, accSignature);
  18. }
  19. };
  20. /** Demonstrating the use of HOAIntermediates */
  21. int main(int argc, const char* argv[]) {
  22. HOAConsumer::ptr hoaNull(new HOAConsumerNull());
  23. CountStates::ptr counter(new CountStates(hoaNull));
  24. try {
  25. HOAParser::parse(std::cin, counter);
  26. std::cout << "Number of state definitions = " << counter->count << std::endl;
  27. } catch (std::exception& e) {
  28. std::cerr << e.what() << std::endl;
  29. return 1;
  30. }
  31. return 0;
  32. }