|
||||||
| 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. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
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
|
| Sponsored Links |
|
|
|
|||
|
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
Code:
// (this is a comment)
// define process
void NAME(void) {
// beginning of normal C code
OUT = A and B;
}
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. |
|
|||||
|
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 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 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;
}
|
|
|||
|
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 ^^; |
| Sponsored Links |
|
|
|
|||||
|
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
EDIT: Sorry for the bad indentation in the code, but I think my IDE screwed it up. It's still readable, though. |
|
|||||
|
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.) |
|
|||
|
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? |
|
|||||
|
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? |
| Sponsored Links |
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
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 |
| 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 |