| |
|
Welcome to KnowledgeSutra - Dear Guest | |
Creating a Compiler
#1
Posted 09 October 2004 - 08:07 AM
To create a working Compiler or Interpreter
You need to design your own Language
And build the compiler using Java or preferably C.
This is one scary nightmare...dang....I wish I can just wake me up...
but I can't this is not a nightmare. T_T
Btw, does anyone here has any experience on creating compiler or interpreter using C?
I am designing a language which is the combination of C and PHP.
And I need help.
#2
Posted 09 October 2004 - 03:49 PM
Any more parameters for this assignment? number of statements, functions etc..
it sounds hard, but just take a deep breath...
start with the actual syntax:
identifiers, functions, operators, separators, etc...
decide what legal and illegal syntax is
then write your pattern-matching code to look for these things
now that you can identify the parts of your language, all you need to do is translate it to C and compile and voila, u r done.
start with a simple arithmetic language, i.e. make sure the operators are infix (or postfix or prefix or whatever u like). make sure the operands are valid (i.e. numeric)
now expand it by adding variables. make sure variables are declared before being used.
i think u see where I am going now...
good luck!
- arp
#5
Posted 17 November 2004 - 07:02 AM
first of all design the syntax... and get the patterns/ regular expressions to identify the tokens( identifier/variable, constructs, expressions etc).
you can then use lex to generate a program which reads the source and generates the tokens...
call this program from your program.. now that u have the tokens... process then in your program accordingly....
I have heard of yacc but never used it... just find out more abt it and c if that would help...
all the best...
rest assured that though it is difficult, it would be very satisfying once u c the result....
#6
Posted 21 August 2008 - 10:04 AM
Creating a Compiler
Replying to eldeoReplying to eldeo
Hello Mr.Eldeo .I am sathees and I am studying fourth year IT (UG) in PSG college of technology coimbatore Tamil nadu.I am assigned a project of creating a 'C' compiler. Can you please help me to create a model C compiler.
-question by satheesaran
#7
Posted 28 August 2008 - 10:43 AM
Anyway...
What do u mean, a 'C' compiler? A compiler written in C or a compiler that converts C -> executable file?
For the first one... try reading some of the posts above, they are really useful. Any in-detail questions?
#8
Posted 19 October 2008 - 04:44 PM
iGuest-satheesaran, on Aug 21 2008, 03:34 PM, said:
Creating a Compiler
<a href=http://www.trap17.com/forums/index.php?showtopic=2561&view=findpost&p=19167>Replying to eldeo</a><a href=http://www.trap17.com/forums/index.php?showtopic=2561&view=findpost&p=19167>Replying to eldeo</a>
Hello Mr.Eldeo .I am sathees and I am studying fourth year IT (UG) in PSG college of technology coimbatore Tamil nadu.I am assigned a project of creating a 'C' compiler. Can you please help me to create a model C compiler.
-question by satheesaran
Hey Eldeo. I believe its a Compiler Construction assignment that you are having and It would be something like construct a C Compiler using Java. There are many of these available freely. Google for it and I am sure you'll find one. Otherwise if you want to build it on your own. It will take some time but you'll surely be able to build it. find some good books on Compiler Construction. And build a Flow Chart first. Then you need to proceed step-by-step as in the book.
Lexical analyser, symantic analyser, Syntax analyser, etc.
I also did a similar minor project in my fourth year
#9
Posted 17 March 2010 - 04:20 PM
I am also a student who had a task to design the Lexical and Parser for C language. It was a night mare for me, but compiler design is one of the simplest task of all
These is what you need
1. Know 6 phases of compilation, you can refer dragon book (By Aho, Ulman ..)
2. You will need a knowledge of Context Free Grammar (especially during Syntanx analyzation)
3. You will also need knowledge on NFA and DFA and Regular expression
4. Then you need to write your compiler, you can use any language which you are comfortable to write a compiler for any language (I prefare C on myside)
5. With the knowledge above Compiler writing is easy , what remains is your creativity
-reply by Ndimangwa Fadhili#10 Guest_pulsar coder_*
Posted 10 July 2010 - 06:50 AM
I have created a new language named "Think" it is an interpreter.
First you need to know what are the components of the compiler,
Then write a sample program in "C" language
to fetch the file contents and create a symbol table like
file.txt // file to be scanned
content of this file is as follows,
int a,b,c;
float af,bf,cf;
you just print the output as
integer variables [a,b,c]
float variables [af,bf,cf]
Then for further reference just take a look at the last chapter of "C Complete Reference" written by
"Herbt Schildt"
In that he wrote a full interpreter in C language and named it as little C interpreter
In which he have used recursive calculator for expression manipulation like c = (a+
If you able to understand the code of little C then its very easy you can
create a new compiler or interpreter by yourself.
Further contact mail to "pulsarcoder@gmail.com"
Reply to this topic

1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users














