3

Apologies for asking such an open-ended question, but I want to emulate some synthetic assembly (not for a real processor) in C++ and I want to decouple the assembly from the implementation of the simulator it runs on.

Writing a DSL or similar seems like the obvious way and I have some experience of this, having done something like it (actually a mixture between a DSL and an interpreter) in Groovy.

boost::proto seems like the obvious choice, but I find the documentation utterly impenetrable, even though, as I say, I have some grasp of the basics.

Is there any alternative tutorial or similar out there that explains - in a way that focuses on the practicalities of writing a DSL rather than the theory of ASTs etc - how to do this. Or is there an alternative? Right now I am stuck with implementing the assembly instructions as methods of classes that make up the simulator, which makes them very tightly bound and extremely difficult to maintain the code base.

adrianmcmenamin
  • 1,081
  • 1
  • 15
  • 44
  • the obvious choice is LLVM IR:http://llvm.org/docs/LangRef.html – Alexander Oh Aug 17 '15 at 20:52
  • Thanks for the suggestion, but it looks like LLVM is a way to write stand alone executables, while want I want is something I can plug through my simulator, instruction by instruction: what I really want to model is memory access patterns. – adrianmcmenamin Aug 17 '15 at 21:02
  • 1
    so this is not in the question. Put your requirements into the question. writing a simulator is inherently different from writing a DSL. what should this DSL do, what are you trying to solve with it. good Instruction simulators for instance compile your code for faster execution – Alexander Oh Aug 17 '15 at 21:10
  • @sehe I think [this](http://pastebin.com/By8cBTCf) is the "interpreter" you mentioned. I found a [great tutorial](https://github.com/sabel83/metaparse_tutorial) by the author of metaparse that explains how to do something similar with Boost.Xpressive. – llonesmiz Aug 18 '15 at 06:59
  • @cv_and_he indeed. I seem to remember you made it :) That tutorial is nice. On the reading stack! – sehe Aug 18 '15 at 07:30
  • My problem is not writing the simulator. – adrianmcmenamin Aug 18 '15 at 07:51
  • Here is something you can try if you want to do things that aren't valid C++ syntax: http://stackoverflow.com/questions/17783393/how-to-parse-text-for-a-dsl-at-compile-time Now that Metaparse is part of Boost this link might help: http://www.boost.org/doc/libs/master/doc/html/metaparse/getting_started_with_boost_metap.html – Jerry Jeremiah Oct 14 '16 at 00:26
  • Metaparse even takes something that looks like BNF to define the DSL: http://www.boost.org/doc/libs/master/doc/html/metaparse/user_manual.html#metaparse.user_manual.what_is_a_parser.grammars – Jerry Jeremiah Oct 14 '16 at 00:32

1 Answers1

1

I second the comments suggesting that you may have a badly matched XY-problem here.

Meanwhile, the best introduction to applied Boost Proto for an embedded eDSL was on Dave Abrahams' cpp-next.com blog. Sadly, that has gone off the air.

Eric Niebler, author of Boost Proto, has offerred to send people the raw dumps of those pages, on request:

The C++ community is suffering from the loss of the cpp-next.com website and all the great content that was once hosted there. In the past 2 months, I’ve gotten many questions both about the site and about the fate of my “Expressive C++” article series. In response, I will re-post my old articles on this blog. But I’m busy and it’ll take time. In the meanwhile, if you have a desperate need for a readable introduction to Boost.Proto and domain-specific embedded languages in C++, and you don’t mind reading raw markdown, email me. I’ll send you what I have.

http://ericniebler.com/2014/05/24/cpp-next-com-and-the-expressive-cxx-series-2/

In the mean time, waybackmachine has some of it, e.g.:

Community
  • 1
  • 1
sehe
  • 374,641
  • 47
  • 450
  • 633
  • Thanks for this, I too searched through the wayback machine stuff from the cpp-next blog (before I posted the question) but I cannot seem to find an article that starts the series. [b]Update[/b] ah, have found the start of the series now - I'll see if that helps. – adrianmcmenamin Aug 18 '15 at 13:08
  • Incidentally, I don't agree on the XY problem issue. I have a simulator that models the memory hierarchy I want. I want to be able to get it to execute various parallel algorithms, on a step by step basis. So I think an embedded DSL is a good match. I am willing to consider other things of course. – adrianmcmenamin Aug 18 '15 at 13:38
  • The xy was related to Proto – sehe Aug 18 '15 at 13:39
  • 1
    The series starts [here](https://web.archive.org/web/20120628021148/http://cpp-next.com/archive/2010/08/expressive-c-introduction/). – Eric Niebler Aug 18 '15 at 18:10