Lost Password?


Go Back   CodeCall Programming Forum > Software Development > C and C++

C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-13-2007, 12:19 PM
kenna kenna is offline
Learning Programmer
 
Join Date: Jul 2007
Posts: 30
Rep Power: 6
kenna is on a distinguished road
Default multi-pass preprocessing

Is it possible to use something like this in C? Multi-pass preprocessing that is.

Code:
#define proc0 name; \ /* define proc0 */
    (
    #define flag0 \ /* define flag0 */
    int name(void){
    )

#if defined(flag0) /* check for flag0 */
    #define proc1 name; \ /* define proc1 */
    (
    int name(void){
    )
#else
    #error proc0 must be used before proc1
#endif
I'm trying to write a simple HDL (Hardware Description Language) in C, since Lex is too bothersome.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 08-13-2007, 12:40 PM
v0id's Avatar   
v0id v0id is offline
Retired
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,654
Last Blog:
CherryPy(thon)
Rep Power: 29
v0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of light
Send a message via MSN to v0id
Default

I don't understand what you're trying to do. Can you specify it a bit?
Is it something like this you want to do; If the function func1 has been used, then func2 can be used as well. But if func1 hasn't been used, then func2 cannot be used as well? It could be done like this:
Code:
void func1()
{
    #define FUNC1_USED
    // ...
}

#ifdef FUNC1_USED
void func2()
{
    // ...
}
#else
    #error func1() has to be used, before func2()
#endif
I kinda feel like I'm on the wrong track about my understanding of what you want to do...
__________________
05-03-2007 - 11-13-2008
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 08-13-2007, 01:04 PM
kenna kenna is offline
Learning Programmer
 
Join Date: Jul 2007
Posts: 30
Rep Power: 6
kenna is on a distinguished road
Default

The purpose is to allow users to write something like this:

Code:
-- (this is a comment)

-- define process
process NAME begin
    -- beginning of normal C code
    OUT = A and B;
end
and have it translated to this:

Code:
// (this is a comment)

// define process
void NAME(void) {
    // beginning of normal C code
    OUT = A and B;
}
so even though your example would work, it would require the user to write in C, instead of the simplified HDL, and it would allow the user to more easily write malicious code.

Only within a certain region can you use normal C, and even then restricted. I might be asking for a bit too much from the C preprocessor though ^~^, just experimening.

The trick here is that the code is VERY strict, and has to be written in a certain way.

1. interface -- the physical pinout, connectors, switches, etc.
2. device -- logical interface, ports, registers, immediate memory, etc.
3. circuit -- a smaller unit that handles a certain operation
4. process -- the process of the device

Last edited by kenna; 08-13-2007 at 01:07 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 08-13-2007, 02:06 PM
v0id's Avatar   
v0id v0id is offline
Retired
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,654
Last Blog:
CherryPy(thon)
Rep Power: 29
v0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of light
Send a message via MSN to v0id
Default

It's possible to "convert" C++ into "another language," using preprocessors. I've done this my self once, just for fun. I converted a lot C++ into the danish language (my native language) and it worked quite fine, though it was different.

There's some limit though. It's, for example, not possible to change the look or representation of comments.

My programs could look like this, for example:
Code:
#include <iostream>
#include "dansk.hpp"

// Funktionen "FUNKTIONUDENPARS"
tom som returtype til funktionen FUNKTIONUDENPARS uden_parameterliste
indhold til funktionen er

	kald funktionen printf med vaerdien "Hello, World!\n" og_ikke_mere
	
slut paa funktionen


// Funktionen "FUNKTIONMEDPARS"
tom som returtype til funktionen FUNKTIONMEDPARS med parameterlisten med tallet X og tallet Y
indhold til funktionen er

	kald funktionen printf med vaerdierne "%d, %d\n" og X og Y og_ikke_mere

slut paa funktionen


// Funktionen "main"
heltal som returtype til funktionen main uden_parameterliste
indhold til funktionen er

	kald funktionen FUNKTIONUDENPARS uden_vaerdier
	kald funktionen FUNKTIONMEDPARS med vaerdierne 10 og 20 og_ikke_mere
	
	kald funktionen system med vaerdien "pause" og_ikke_mere
	returner 0;

slut paa funktionen
It's in danish, yes, but I think you get the idea. Translated into english, it would be something like:
Code:
#include <iostream>
#include "dansk.hpp"

// The function "FUNCTIONWITHOUTPARMS"
void as returntype for the function FUNCTIONWITHOUTPARMS without_parameterlist
content of the function is

	call the function printf with the values "Hello, World!\n" and_nothing_else
	
end of the function


// The function "FUNCTIONWITHPARMS"
void as returntype for the function FUNCTIONWITHPARMS with the parameterlist including the number X and the number Y
content of the function is

	call the function printf with the values "%d, %d\n" and X and Y and_nothing_else

end of the function


// The function "main"
number as returntype for the function main without_parameterlist
content of the function is

	call the function FUNCTIONWITHOUTPARMS without_values
	call the function FUNCTIONWITHPARMS with the values 10 and 20 and_nothing_else
	
	call the function system with the value "pause" and_nothing_else
	return 0;

end of the function
And in normal C++:
Code:
#include <iostream>
#include "dansk.hpp"

void FUNKTIONUDENPARS()
{
    printf("Hello, World!\n");
}

void FUNKTIONMEDPARS(int X, int Y)
{
    printf("%d, %d\n", X, Y);
}

int main()
{
    FUNKTIONUDENPARS();
    FUNKTIONMEDPARS(10, 20);

    system("pause");
    return 0;
}
It's kinda special, but works and is ready to compile, using any decent compiler. If you want to see the file "dansk.hpp," though it's danish, just tell me.
__________________
05-03-2007 - 11-13-2008
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 08-13-2007, 04:50 PM
kenna kenna is offline
Learning Programmer
 
Join Date: Jul 2007
Posts: 30
Rep Power: 6
kenna is on a distinguished road
Default

Lol, speaking swedish (finland-swedish) I did manage to understand most of it, although I find danish more difficult than norwegian ^_^ but awesome work anyway!

Sure, I can't find many "advanced" preprocessing tutorials on the internet ^^;
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #6 (permalink)  
Old 08-14-2007, 12:55 AM
v0id's Avatar   
v0id v0id is offline
Retired
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,654
Last Blog:
CherryPy(thon)
Rep Power: 29
v0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of light
Send a message via MSN to v0id
Default

Nice, are you from Sweden or Finland?
Anyways, here you get the full source from dansk.hpp:
Code:
//////////////////////////////////////////////////////////////////////////////////////////
//
//		Sprog:				Dansk
//		Projekt:			Programmering på dansk
//		Programmør:			N. 'v0id' O.
//			E-mail:			mail@v0id.dk
//			Hjemmeside:		www.v0id.dk
//		Dato:				25 April, 2007
//		Version:			1.1, beta
//		Beskrivelse:
//			Inkludér denne fil, og du vil kunne programmere
//			som du snakker, bogstaveligt talt.
//			Det er meget frit hvordan ens program skal se ud,
//			og man skal selvfølgelig også have lidt evner indenfor
//			dansk, og kunne stave nogenlunde. 
//			Dette er kun en beta-udgave, så feed-back er velkommen!				

//////////////////////////////////////////////////////////////////////////////////////////
// Operatorene
#define array					[]
#define arrayet					array
#define parameterlisten			(
#define uden_parameterliste		parameterlisten
#define vaerdierne				parameterlisten
#define vaerdien				parameterlisten
#define og						,
#define samt					og
#define indhold					){
#define og_ikke_mere			);
#define slut					}
#define uden_vaerdier			();

//////////////////////////////////////////////////////////////////////////////////////////
// Normale ord
#define med
#define er
#define returtype
#define til
#define funktionen
#define paa
#define indeholder
#define der
#define som
#define kald

//////////////////////////////////////////////////////////////////////////////////////////
// C++'s nøgleord
#define assembly_kode 			asm
#define lokal					auto
#define lokalt					lokal
#define automatisk				lokal
#define boolesk					bool
#define bryd					break
#define tilfaelde				case
#define sag						tilfaelde
#define grib					catch
#define tegn					char
#define bogstav					tegn
#define bogstaver				tegn
#define klasse					class
#define konstant				const
#define konstante				konstant
#define konstant_kast			const_cast
#define fortsaet				continue
#define standard				default
#define slet					delete
#define goer					do
#define dobbelt					double
#define dobbel					dobbelt
#define dynamisk_kast			dynamic_cast
#define ellers					else
#define enumerator				enum
#define enumeration				enumerator
#define udtryksfuld				explicit
#define udtryksfuldt			udtryksfuld
#define eksport					export
#define eksporter				eksport
#define ekstern					extern
#define eksternt				ekstern
#define falsk					false
#define ukorrekt				falsk
#define kommatal				float
#define for						for
#define ven						friend
#define gaa_til					goto
#define hvis					if
#define direkte					inline
#define heltal					int
#define tal						heltal
#define tallet					heltal
#define lang					long
#define langt					lang
#define muterbar				mutable
#define navnerum				namespace
#define ny						new
#define nyt						ny
#define operator				operator
#define privat					private
#define private					privat
#define beskyttet				protect
#define beskyt					beskyttet
#define offentligt				public
#define offentlig				offentligt
#define ekstra_speed			register
#define genfortolket_kast		reinterpret_cast
#define genfortolk_kast			genfortolket_kast
#define returner				return
#define kort					short
#define signeret				signed
#define stoerrelsen_af			sizeof
#define statisk					static
#define struktur				struct
#define skift					switch
#define skabelon				template
#define denne					this
#define dette					denne
#define kast					throw
#define sandt					true
#define korrekt					sandt
#define rigtigt					sandt
#define proev					try
#define definer_type			typedef
#define type_identifikation 	typeid
#define forsamling				union
#define usigneret				unsigned
#define brug					using
#define bruger					brug
#define virtuel					virtual
#define virtuelt				virtuel
#define tom						void
#define ingenting				tom
#define ikke_aendringsbar		volatile
#define bredt_tegn				wchar_t
#define brede_tegn				bredt_tegn
#define bredt_bogstav			bredt_tegn
#define brede_bogstaver			bredt_tegn
#define imens					while
#define mens					imens
As you see, there's no advanced preprocessing, but only simple directives. Furthermore, you can see the words under "Normale ord" ("Normal words"), they are just defined, without a value. It's so the code is easier and "better" to write, so the look like danish.

EDIT: Sorry for the bad indentation in the code, but I think my IDE screwed it up. It's still readable, though.
__________________
05-03-2007 - 11-13-2008
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 08-14-2007, 07:36 AM
kenna kenna is offline
Learning Programmer
 
Join Date: Jul 2007
Posts: 30
Rep Power: 6
kenna is on a distinguished road
Default

your IDE probably uses tabs instead of spaces, that's usually what destroyes the indentation for me X_X

I'm from Finland, near the city of Vasa ^_^
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 08-14-2007, 08:14 AM
v0id's Avatar   
v0id v0id is offline
Retired
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,654
Last Blog:
CherryPy(thon)
Rep Power: 29
v0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of light
Send a message via MSN to v0id
Default

Yeah, it's because my IDE is using tabs instead of spaces.

Oh, nice, that's funny. I was actually born in Finland, but at an age of one, my family moved to Denmark. I was born in Turku, and lived in the small town Kustavi. All of my dads family is in Finland, and I was actually visiting them two weeks ago. I'm visiting them every second year, and stays for two weeks. It's really great (except for the mosquitoes. lol.) I understand some finnish, but I'm unable to speak it, though.

Hyväa Joulua! (The only thing I can spell. lol.)
__________________
05-03-2007 - 11-13-2008
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 08-14-2007, 08:38 AM
kenna kenna is offline
Learning Programmer
 
Join Date: Jul 2007
Posts: 30
Rep Power: 6
kenna is on a distinguished road
Default

Awesome ^_^! Nice to see a fellow finn(although only for one year)/scandinavian here. I find it truly interesting how we share the same language (north germanic) and the differences we have.

My main mother tongue is finland-swedish (but I also speak fluent finnish), so I'd always want to travel to norway, denmark, and iceland sometime, to experience their language first hand.

Hyvää Joulua, although a bit early ^^ ROFL

Btw, on a completely different subject, do you have any suggestions as to how I should implement an emulator, to keep as much speed as possible? I am going for a realistic approach, so there will be memory, processor, bus, and system controller.

Are there any common traps I should look out for?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 08-14-2007, 10:09 AM
v0id's Avatar   
v0id v0id is offline
Retired
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,654
Last Blog:
CherryPy(thon)
Rep Power: 29
v0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of light
Send a message via MSN to v0id
Default

Icelandic is completely different from danish, norwegian and finnish, so I think it would be hard for you to understand. I don't understand a single word of it neither. I've been planning to learn finnish before next summer, where some of my family comes to Denmark. It would be nice if I for the first time in my life actually could talk easily with them.

About your question; I don't really understand what you want to do. Can you make an complete of how you want it to look like, and what it afterwards should do?
__________________
05-03-2007 - 11-13-2008
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
G++ Error: cannot pass objects of non-POD type Ronin C and C++ 4 10-01-2007 05:35 AM
How do I read .mbm (Multi BitMap) files? moondog General Programming 7 08-07-2007 08:08 AM
Program to pass data from text file to table. sania21 Java Help 3 05-28-2007 09:32 AM


All times are GMT -5. The time now is 02:04 AM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 100%


Complete - Celebrate!

Ads