Jump to content
xisto Community
Sign in to follow this  
hansley

Creating a Compiler The Nightmare of a Comp Science Students

Recommended Posts

I got this assignment from my college:To create a working Compiler or InterpreterYou 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_TBtw, 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.

Share this post


Link to post
Share on other sites

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 isthen write your pattern-matching code to look for these thingsnow 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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

How to create C compiler

 

Creating a Compiler

<a href=http://forums.xisto.com/topic/2561-creating-a-compiler-the-nightmare-of-a-comp-science-students/ to eldeo</a><a href=http://forums.xisto.com/topic/2561-creating-a-compiler-the-nightmare-of-a-comp-science-students/ 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 :)

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

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" languageto fetch the file contents and create a symbol table likefile.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 interpreterIn 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"

Share this post


Link to post
Share on other sites

I made my own programming language. It was really easy but i made my compiler in a programming language called C#. If you go onto youtube and search up 'C# Advanced Tutorial How to make your OWN programming language! part 1'. all you need to do after that is to follow what the guy sais through all of the videos and he will teach you how to make your own compiler. I hope this is helpful.

Share this post


Link to post
Share on other sites

I am assigned to do a project,which has to compile and run a java program written in Tamil.How do i create a compiler which understand the language and make it to produce the proper output?

Share this post


Link to post
Share on other sites

Well, first you have to look at the Tamil commands and figure out to which Java commands they correspond. Then you would convert that code to Java. Finally, you would compile that program (since probably they don't expect you to know machine code to do the compilation directly...).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.