Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++
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 15-Nov-12 10:34am
Comments
Sergey Alexandrovich Kryukov at 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
pwasser at 15-Nov-12 22:00pm
   
You seem to have already succeeded.
Mahdi Nejadsahebi at 17-Nov-12 6:17am
   
can you more explain?
it's not clearly.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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.
  Permalink  
Comments
Sergey Alexandrovich Kryukov at 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 at 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 at 16-Nov-12 11:32am
   
Hopefully. Genuine interest is the key. And you are very welcome.
:-)
--SA
pasztorpisti at 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 at 18-Nov-12 15:52pm
   
Thank you.
Yes, the order you proposed probably makes more sense.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Comments
CutenPam at 15-Nov-12 15:46pm
   
#include
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 at 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 at 16-Nov-12 6:36am
   
C/C++ already contains the union type.
Christian Graus at 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 at 16-Nov-12 7:37am
   
I never doubted you, my reply was directed at OP.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

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
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Use the typedef keyword to create your own custom data types from other types.
 
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;
}
  Permalink  

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



Advertise | Privacy | Mobile
Web04 | 2.8.150327.1 | Last Updated 15 Nov 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100