very simple code generator example?

I would like to attempt to write a very simple code generator.
Input would be XML tags, output would be C++.

Anyone have a quick reference / URL, example of doing this? For example, how to generate a "Hello World" where Hello and World would be substituted values for a couple of XML tags.

This is just for curiosity as a jumping off point, and to increase my knowledge of C++ / XML. I'm open to any suggestions on XML format as well.

I'm fairly competent with C++/STL, but limited on XML, but willing to learn!

Thanks!
There are no predefined tags in XML. Just define your own.
Did you want something like this?

<?xml version="1.0"?>

<!-- Hello, world! in XML -->

<cpp>

  <directive name="include" value="&lt;iostream&gt;" />
  <using value="namespace std" />

  <function type="int" name="main">
    <parameter number="0" type="int" name="argc" />
    <parameter number="1" type="char*[]" name="argv" />
    <body>
      <operator name="&lt;&lt;" lvalue="cout" rvalue="&quot;Hello, world!\n&quot;" />
      <return value="0" />
    </body>
  </function>

</cpp>

I use W3Schools for *ML language references, and tutorials.
http://w3schools.com/xml/default.asp
Last edited on
Topic archived. No new replies allowed.