Code Generation Example?

General discussion about C/C++

Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard

Code Generation Example?

Postby FrodoDot » Thu Apr 07, 2011 9:53 pm

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, 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.

Thanks!

BW
FrodoDot
 
Posts: 2
Joined: Thu Apr 07, 2011 9:46 pm

Re: Code Generation Example?

Postby ventsyv » Thu Apr 07, 2011 10:09 pm

May I suggest the other way around ? Use C++ to generate XML. It's easier and you'll learn a lot more.
User avatar
ventsyv
 
Posts: 2810
Joined: Mon Sep 22, 2003 5:25 pm
Location: MD USA

Re: Code Generation Example?

Postby FrodoDot » Thu Apr 07, 2011 11:22 pm

Appreciate the input :-) but my main goal is to learn how to generate common code chunks (classes, etc) in C++, where the diffs are described in an XML file. So one output may be:

cout << " Hello world " << endl;

and the next:

cout << " Fare thee well " << endl;

similar, but different.
FrodoDot
 
Posts: 2
Joined: Thu Apr 07, 2011 9:46 pm

Re: Code Generation Example?

Postby ventsyv » Thu Apr 07, 2011 11:50 pm

Reading data from an xml file and manipulating it in your program is not the the same as generating C++ code. Writing an actual code generator will not be trivial, while reading data from a file is fairly straight forward.

What is your experience with programming? C++ ? Can you explain again what are you trying to achieve?
User avatar
ventsyv
 
Posts: 2810
Joined: Mon Sep 22, 2003 5:25 pm
Location: MD USA


Return to General

Who is online

Users browsing this forum: Google [Bot] and 1 guest