I am thinking of making my own programming language,
How would i make a compiler in C or C++??
know where i can get a good tutorial?
Please help...
I am thinking of making my own programming language,
How would i make a compiler in C or C++??
know where i can get a good tutorial?
Please help...
>> know where i can get a good tutorial?
I doubt that it could be all summed up in a single tutorial!
I'm not completely sure, but I think you'd probably have to use inline asm in your C/C++ app to directly access the hardware. Dont know how you would create the actual .exe assuming you are talking about Windows, though...sorry, I dont know much on this topic.
After taking in all considerations and observing your posts, I think that its fair to say that you are not likely to be ready for this type of task.
You could invent your own language, and when compiling it you transform it into C/C++ code, ready to be compiled with a C-compiler.
Other than that, I guess you can create EXE files using binary write functions, though it will be very hard .
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
you can create a script that would be interpreted by a program you write. thats what i did for my bot
I know, i am not ready to make a compiler, i just want to get some info, and a tutorial on the basics, can i just see some example code, on how to read in text from a text file, then output it into another text file, but the code has to be interpreted, into C++ or any other language, i just want to see an example of how this is done
I know i am not ready to build a compiler (since i'm stating off in C++) but i am going to make my own programming language, i just want to know the basics.
So please, tell me if you know where i can get some good tutorials, Please help...
Ciao
Just make a calculator that lets you write something like
this
x = 5;
y = 3;
x + y * 5 + (3 + x) ;
It would then printout
x = 5
y = 3
28
You can do this by writing a grammer for the language.
A good example is http://java.sun.com/docs/books/jls/s.../jTOC.doc.html
Then you have to figure out a way to parse the data.
The easiest way doing it yourself is recursive decent.
If you use c io the functions you would use are
fgetc, ungetc, scanf
http://compilers.iecc.com/crenshaw/
"are you talking about making a compiler or making a high-level language?
Source code in a high-level language is converted to assembly, which then is converted to binary. Assembly is kind of easy, but you know how it is...for one line of a high-level language, you have *at least* 3 lines of assembly code...so that'll get really long.
Once you have the assembly code, you can then use an assembly compiler.
Thus if you wanted your own language, you'll need to determine the rules, tokens, etc...and then develop the compiler that compiles it into intermediate code (ie: assembly).
Now, if you wanted to convert assembly to binary...it shouldn't be too difficult. In my electrical engineering class, we had to learn how to translate assembly code into binary (there's the op code, source register, destination register, and the data). It's dependent on the machine that it runs on though.
Doesn't sound too hard, but it does sound very, very long. By myself, it would probably take a year or so :P"
My Avatar says: "Stay in School"
Rocco is the Boy!
"SHUT YOUR LIPS..."
For now this is all i want to know, if i typed in the word:
MainFunction
how would i convert it to to the word:
Main
this is the sort of thing i want to do (this example converts a number, i want to know how to convert words):
#include <iostream.h>
int main(int arg, char* args[])
{
int number = 1;
if(number == 1)
{
cout << "2" << endl;
}
return 0;
}
This converts a number. What i want to do is something like this:
(This is incorrect, i know i can't do this, but i am using it as an example!) So please somebody tell me how i can do something liker this:
#include <iostream.h>
int main(int arg, char* args)
{
char string = "MainFunction";
if(string == "MainFunction")
{
cout << "Main" << endl;
}
return 0;
}
Do you understand what i am getting at? so how could i do something like that?
int main(int arg, char* args)
{
char string = "MainFunction";
if(string == "MainFunction")
{
cout << "Main" << endl;
}
return 0;
}
You should never name anything with string since that's
a c++ class.
Code:#include <iostream> #include <string> using namespace std; int main(int arg, char* args) { char s= "MainFunction"; if(!strcmp(s, "MainFunction")) { cout << "Main" << endl; } return 0; }
Code:char* String1 = "Hello world!"; char* String2 = "Hello world!"; if(strcmp(String1, String2) == 0) { cout << "Both strings are equal!"; } else { cout << "The strings are not equal!"; }
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
That's not a compiler, that's even not a parser!Originally posted by Perica
Do you understand what i am getting at? so how could i do something like that?
if(!strcmp(str,"MainFunction")) strcpy(str,"main");
A compiler or interpreter is much more complex!
Ich think you should read some tutorials covering the basic of C++
Hope you don't mind my bad english, I'm Austrian!
Hey hey hey,
wait a minute...i asked them to give me this code and they did. Thank you.
And you mean i can actuall diclare strings like that:
char str = "string";
cool, i never knew
Thnaks, but, whats the deal with this " char* str;" whats the pointer for, if somebody could please explain.
And also what is a Parser. And when you said that a High-level Language compiles into assembler, do you mean nasm assembler or what??
Cya.
char Str = "Hello!";
This is invalid. You can't store a string (x bytes) or the address to a string (4 bytes) in a single char (1 byte).
What you could do is declare a pointer and make it point to that string:
char* Str = "Hello again!";
Or if you want a modifyable string:
char Str[5] = "Bye!";
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
What do you mean modifyable, can't i modify this:
char* str = "str";
?
This looks more like an array:
char* str[5] = "str";
ciao
Hey,
the only one that worked is the one that Magos wrote, i use MS VC++ 6 by the way.
But i got a question, how come when you do strcmp, do you check if the strings are equall to 0??