Click here to Skip to main content
15,886,666 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
1. create my own variable
2. create my own reserve words
3. have the estructure (start/finish) (need to have a cycle *for, wile* and a conditional
Posted
Comments
Sergey Alexandrovich Kryukov 15-Nov-12 18:31pm    
Sorry, but his is illiterate, ignorant and even rude. It looks like you give orders to us: "create my own variable"...
From your text, I can see that you are not yes ready for creation of languages, sorry. Maybe later, when you learn just a bit how existing languages work.
--SA
[no name] 15-Nov-12 22:00pm    
You seem to have already succeeded.
[no name] 17-Nov-12 6:17am    
can you more explain?
it's not clearly.

In addition to Christian's reply, you really need to read and understand something like 'The Dragon Book'

"Compilers: Principles, Techniques, and Tools"

to be able to do this ...

http://en.wikipedia.org/wiki/Compilers:_Principles,_Techniques,_and_Tools[^]
 
Share this answer
 
As already suggested you need to create a compiler.
Generally speaking creating a compiler is a rather difficult task. However it really depends on the requirements of your language (a simple and 'regular' language would make your task easier). Anyway you need some background on compiler construction techniques. I might suggest:

  • The dragon book - (already suggested) provides a strong theoretical approach.
  • lcc, A Retargetable Compiler for ANSI C[^] - shows a complete implementation of a C compiler (might be the 'natural' practical complement of the dragon book).

You may find more 'introductory' material in


It is worthy nothing there are many tools that try to automate the 'compiler generation' process. The classical example is bison[^]/flex[^] pair, while a more recent one is ANTLR[^] (if you you find yourself creative then have a look at the LPeg Lua[^] library).
Since you tagged your question as C++, I should also mention the Boost Spirit[^] library.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 15-Nov-12 18:34pm    
My 5; interesting references and all. I hope you understand how much unrelated all this is from the OP's "question"... I don't really care -- some people can use it, anyway.
--SA
CPallini 16-Nov-12 4:05am    
Well, the OP question is poorly written, nevertheless he/she might have a genuine interest on the topic.
By the way, thank you.
Sergey Alexandrovich Kryukov 16-Nov-12 11:32am    
Hopefully. Genuine interest is the key. And you are very welcome.
:-)
--SA
pasztorpisti 18-Nov-12 15:16pm    
+5, However I would put Crenshaw's tutorial on the top as it introduces the basics in a quite engaging and easy way for pure humans, maybe Wirth's tutorial as second. The Dragon book + LCC can be a bit long and dry for first but its a necessary bible to read. An important thing is that deeply understanding compiler construction involves some assembly that seems to be painful for some...
CPallini 18-Nov-12 15:52pm    
Thank you.
Yes, the order you proposed probably makes more sense.
To do that you need to write your own compiler. I am not sure what 1 means - create your own variable type ? You can use macros to create new names for existing things, but something brand new, you need to write a compiler to understand your new objects. The first version of C++ just turned C++ in to C and then ran a C compiler on it, so perhaps you can do something similar.
 
Share this answer
 
Comments
CutenPam 15-Nov-12 15:46pm    
#include <iostream>
using namespace std;

union unEjemplo {
int A;
char B;
double C;
} UnionEjemplo;

int main() {
UnionEjemplo.A = 100;
cout << UnionEjemplo.A << endl;
UnionEjemplo.B = 'a';


UNION its like my own variable! like when we use INT ... just that i have to create my own... i dont know how can i do this program ... i only know that i need help hehehe
Christian Graus 15-Nov-12 15:51pm    
Read my answer again. IF you want to add new language features, you need to write a compiler or a precompiler
Richard MacCutchan 16-Nov-12 6:36am    
C/C++ already contains the union type.
Christian Graus 16-Nov-12 7:35am    
I know that, obviously. But that's not really what he's talking about. He wants to 'create his own'
Richard MacCutchan 16-Nov-12 7:37am    
I never doubted you, my reply was directed at OP.
Good luck for your nice thought.Language creation is not simple as you think.
it has it's own risk. First you should create a pre-compiler.
pls refer the link below.
Create Your Own Programming Language
 
Share this answer
 
Use the typedef keyword to create your own custom data types from other types.

C++
using namespace std; 

typedef union _unEjemplo
{ 
   int A; 
   char B; 
   double C; 
}  tdUnionEjemplo; 


int main() 
{ 
   tdUnionEjemplo UnionEjemplo;

   UnionEjemplo.A = 100; 
   cout << UnionEjemplo.A << endl; 
   UnionEjemplo.B = 'a';

   return 0;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900