Jump to content



Welcome to KnowledgeSutra - Dear Guest , Please Register here to get Your own website. - Ask a Question / Express Opinion / Reply w/o Sign-Up!
- - - - -

Creating a Compiler


12 replies to this topic

#1 hansley

    Premium Member

  • Kontributors
  • PipPipPipPipPipPipPipPip
  • 189 posts

Posted 09 October 2004 - 08:07 AM

I got this assignment from my college:
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 arp

    Newbie [Level 1]

  • Kontributors
  • Pip
  • 10 posts

Posted 09 October 2004 - 03:49 PM

Hi;

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

#3 eldeo

    Newbie [Level 1]

  • Kontributors
  • Pip
  • 19 posts

Posted 10 October 2004 - 12:55 PM

Hi!
I wrote C interpreter, Pascal interpreter, Icon interpreter,
C->Pascal translator and C->ICON translator
(everything in ANSI C)


You should read something about Flex/Bison (lex/YACC)
(use google to find it)

--
eldeo

#4 switch

    Premium Member

  • Kontributors
  • PipPipPipPipPipPipPipPip
  • 178 posts
  • Location:NSW, Australia
  • Interests:music,<br />3d graphics programming.

Posted 29 October 2004 - 03:57 AM

wow thats brave :blink: im in year 9, hope i don't have to do anything llike that later on in life! i think ill just stick to 3d graphics, its somewhat easier <_<

#5 cse-icons

    Super Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 351 posts
  • Location:India

Posted 17 November 2004 - 07:02 AM

yeah....
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 iGuest

    Hail Caesar!

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 5,876 posts
  • Interests:Trap17 Free Web Hosting, No Ads

Posted 21 August 2008 - 10:04 AM

How to create C compiler
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 TerroR

    Newbie [Level 1]

  • Kontributors
  • Pip
  • 15 posts

Posted 28 August 2008 - 10:43 AM

Well, firstly, do not resurrect old threads.

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 bluedragon

    Super Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 384 posts
  • Gender:Male
  • Location:Jupiter
  • myCENT:26.63

Posted 19 October 2008 - 04:44 PM

View PostiGuest-satheesaran, on Aug 21 2008, 03:34 PM, said:

How to create C compiler

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 iGuest

    Hail Caesar!

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 5,876 posts
  • Interests:Trap17 Free Web Hosting, No Ads

Posted 17 March 2010 - 04:20 PM

Re: C Compiler DesignCreating a Compiler

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_*

  • Guests

Posted 10 July 2010 - 06:50 AM

Hi,

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+B)*(b+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


This post will need approval from a moderator before this post is shown.

  


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users