Deal of the Day

Home » Main » Manning Forums » 2003 » Code Generation in Action

Thread: Code Generator

Reply to this Thread Reply to this Thread Search Forum Search Forum Back to Thread List Back to Thread List

Permlink Replies: 10 - Pages: 1 - Last Post: Apr 13, 2005 9:13 PM by: Barbelita
import-bot

Posts: 20,296
Registered: 12/6/03
Code Generator
Posted: Jan 20, 2004 4:57 PM
  Click to reply to this thread Reply

[Originally posted 9/7/03 by Anonymous]

Well, i get a project in building a code generator. but i'm just a student. i do some research on how to build it but i still very blur. I'm not sure how should I start. I need to build a code generator that accept Z specification and output code C. I know you are expert in this code generaot. can lend me a helping hand?thanx.

import-bot

Posts: 20,296
Registered: 12/6/03
Re: Code Generator
Posted: Jan 20, 2004 4:57 PM   in response to: import-bot in response to: import-bot
  Click to reply to this thread Reply

[Originally posted 9/7/03 by Anonymous]

hi, its me again. how am i can know if anyone reply message?if possible pls email me:chocolatey81@hotmail.com.
i really badly need help.

import-bot

Posts: 20,296
Registered: 12/6/03
Re: Code Generator
Posted: Jan 20, 2004 4:58 PM   in response to: import-bot in response to: import-bot
  Click to reply to this thread Reply

[Originally posted 9/7/03 by Anonymous]

Anon,

Your question is very open ended, so your unlikely to get much of a reply.

From what you have said the only advice could be 'read the book.'

The first thing to do is to get yourself some samples. Write some Z schemas, and then write the C code that would implement those Z schemas.

Then write some code generators that could generate the code from the schemas.

Then introduce another schema. See what code is generated. Is the code correct? What is wrong with it? Why does this schema fail where the existing ones succeed?

Fix the generator so it produces the correct code for your new schema.

Repeat until you are happy that your code generator is good enough.

It would be a good idea to prepare a list before hand of the z features you would like to support. Order the list by how easy you think these features would be to convert into code. Start with the easiest and work your way down the list.

Don't expect to be able to produce a generic generator that can produce code for any Z schema. What you should be looking at is a very specific type of code specified in Z. You may want to introduce some specific contstraints on the Z specification, to begin with at least. This will make your job easier.

import-bot

Posts: 20,296
Registered: 12/6/03
Re: Code Generator
Posted: Jan 20, 2004 4:58 PM   in response to: import-bot in response to: import-bot
  Click to reply to this thread Reply

[Originally posted 9/7/03 by Anonymous]

What you really need to bare in mind is the following advice from the http://www.faqs.org/faqs/z-faq Z faq:

Z is a (non-executable in general) specification language, so there is
no such thing as a Z compiler/linker/etc. as you would expect for a
programming language. Some people have looked at animating subsets of Z
for rapid prototyping purposes, using logic and functional programming
for example, but this is not really the major point of Z, which is to
increase human understandability of the specified system and allow the
possibility of formal reasoning and development. However, Prolog seems
to be the main favoured language for Z prototyping and some references
may be found in the Z bibliography (see above).

import-bot

Posts: 20,296
Registered: 12/6/03
Re: Code Generator
Posted: Jan 20, 2004 4:58 PM   in response to: import-bot in response to: import-bot
  Click to reply to this thread Reply

[Originally posted 9/7/03 by Anonymous]

Me again,

Z usually specifies implementations in terms of a http://staff.washington.edu/~jon/z/fsm.html finite state machine.

There is an open source project for a http://sourceforge.net/projects/fsmgenerator/ FSM generator. You might find it useful.

import-bot

Posts: 20,296
Registered: 12/6/03
Re: Code Generator
Posted: Jan 20, 2004 4:58 PM   in response to: import-bot in response to: import-bot
  Click to reply to this thread Reply

[Originally posted 9/7/03 by Anonymous]

thanx, so do u think this book is useful to me?

import-bot

Posts: 20,296
Registered: 12/6/03
Re: Code Generator
Posted: Jan 20, 2004 4:59 PM   in response to: import-bot in response to: import-bot
  Click to reply to this thread Reply

[Originally posted 9/7/03 by jherr]

I have both built and used code generators which take as input an FSM specification and build the corresponding code.

The book will help you with the basics on this front but does not provide an example FSM generator.

import-bot

Posts: 20,296
Registered: 12/6/03
Re: Code Generator
Posted: Jan 20, 2004 4:59 PM   in response to: import-bot in response to: import-bot
  Click to reply to this thread Reply

[Originally posted 9/7/03 by Anonymous]

ok,i will try to look for the book. by the way, how long we need to build a code generator.just a simple one.'

-jacqlyn-

import-bot

Posts: 20,296
Registered: 12/6/03
Re: Code Generator
Posted: Jan 20, 2004 4:59 PM   in response to: import-bot in response to: import-bot
  Click to reply to this thread Reply

[Originally posted 9/7/03 by Anonymous]

That depends on what you want to do, but some of the generators in the book are less than twenty lines of code. So writing them is a matter of just a couple of hours.

import-bot

Posts: 20,296
Registered: 12/6/03
Re: Code Generator
Posted: Jan 20, 2004 5:00 PM   in response to: import-bot in response to: import-bot
  Click to reply to this thread Reply

[Originally posted 9/7/03 by GedB]

Jacqlyn,

It will always take longer to write a code generator than to code by hand for the first few programs.

The payoff is that you can churn out hundreds of variations on the same code. This is great for corporate projects where you have to produce a lot of similar code. Download the free Chapters to see a good example of this.

If you only have to produce a few programs, the a Code Generator may not be the best approach.

Barbelita

Posts: 1
Registered: 4/13/05
Re: Code Generator
Posted: Apr 13, 2005 9:13 PM   in response to: import-bot in response to: import-bot
  Click to reply to this thread Reply

Hi,

Do you have finished your Code-Generator?
Can you help me by some questions?

Best regards,
Bärbel




Legend
Gold: 300 + pts
Silver: 100 - 299 pts
Bronze: 25 - 99 pts
Manning Author
Manning Staff
Manning Developmental Editor