Solved

Writing a code generator

Posted on 2001-08-06
10
277 Views
Last Modified: 2010-04-15
I want to write a code generator to do some repetitive tasks...

I have heard of state machines and parsers being used to to this, but don't have a clear
picture of how to go about doing this...


Any help in this direction would be greatly appreciated.
Shell scripting also is o.k.


Thanks,
arut
0
Comment
Question by:arut
10 Comments
 
LVL 2

Expert Comment

by:obg
ID: 6355438
Please specify what you want to do. I don't think there is a generic code generator out there...
0
 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 6355565
>>Any help in this direction would be greatly appreciated.

If you use C++, see STL (Standart Template Library).
For C I recomend you C Code Generator
http://www.ida.ing.tu-bs.de/academics/labs/sweng/beschreibung/tau_htmlhelp/ccode.html 
0
 
LVL 86

Expert Comment

by:jkr
ID: 6355595
I've written some code generators, and the complexity of this task ranges from 'simple' to 'highly complex', depending on what to comply with - what is your goal?
0
 

Expert Comment

by:gaurangbhatt
ID: 6359263
The best way to write a code generater is using scripts.
Using any other compiling languages would be like you are not making use of the language efficiently.

I prefer nawk but you can use perl as well. I have never used perl.

Hope this helps.
0
 
LVL 2

Accepted Solution

by:
obg earned 100 total points
ID: 6359745
Why not yacc? (It's a code generator for parsing text and semantics) Search for it on the net.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Expert Comment

by:digized
ID: 6365185
PERL, baby!
0
 

Author Comment

by:arut
ID: 6371288
Shell scripts is a good idea.Basically I want to start of writing a code generator based
on a state machine and parser to do some trivial repetitive kind of a task.

Maybe copying lines of text from one file to another( Couldn't think of a better example ).

Later on, once I get the hang of it I would like to do more complex stuff.


I need a working model to start with.


arut
0
 

Assisted Solution

by:prabhuram
prabhuram earned 100 total points
ID: 6396597
you start with scanning the input, it can be easily done thru LEX (lexical anayser) and in the second phase you go for YACC (parser) which parses the tokens supplied and after that you have to construct the parse trees and validate them and you need to generate code at the end of validation. for the remaining part mentioned above, i suggest you to go for using C.
-prabhuram
<edited by YensidMod>
0
 
LVL 1

Expert Comment

by:nhuanvn
ID: 6485298
Yeah, LEX + YACC is good to start with. I recommend
BISON [A variant of LEX + YACC] which has both
Windows and Unix versions.
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9412382
No comment has been added lately and this question is therefore classified abandoned.

If asker wishes to close the question, then refer to
http://www.experts-exchange.com/help/closing.jsp

Otherwise, I will leave a recommendation in the Cleanup topic area that this question is:
PAQed with 120:80 split between obg  and prabhuram

Please leave any comments here within the next seven days. It is assumed that any participant not responding to this request is no longer interested in its final disposition.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Sunny
EE Cleanup Volunteer
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Binary Bomb: Phase 4 func4 3 310
Coverting 24 hour time to 12 hour in C++ 15 168
Linux context switch  - loop takes long time to process 6 109
Need example 5 107
An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now