LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-17-2004, 04:48 PM   #1
h/w
Senior Member
 
Registered: Mar 2003
Location: New York, NY
Distribution: Debian Testing
Posts: 1,286

Rep: Reputation: 46
writing a compiler


hello. gonna start writing a compiler now for a pascal-like language. im thinking of doing it in C. anyone have any tips/suggestions before i start?

how long do you think it would take a reasonably good C programmer to do this?
thanks.
 
Old 01-17-2004, 04:51 PM   #2
Chris Weimer
Member
 
Registered: Jan 2004
Location: NYC
Distribution: Fedora XFCE
Posts: 91

Rep: Reputation: Disabled
Qdepartment on yahoo.com is a really good forum/group to help with compilers/interpretors, I think in C/C++ only, though I'm sure there must be others there who knows Pascal. Yet everything I've seen so far is only for C/C++.
 
Old 01-17-2004, 04:53 PM   #3
h/w
Senior Member
 
Registered: Mar 2003
Location: New York, NY
Distribution: Debian Testing
Posts: 1,286

Original Poster
Rep: Reputation: 46
cool. well, the grammar is similar to pascal. the implementing language can be any.
 
Old 01-17-2004, 06:05 PM   #4
wapcaplet
LQ Guru
 
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
Learn all you can about Flex and Bison, as they will save you many hours of programming tedium with any reasonably complex language.

I did a couple of compilers for course projects at university. A compiler for a very simple language, written in C++ without the aid of Flex or Bison, took most of a semester to write. Probably 40 or 50 hours went into it; part of it was already written for us. The next semester, I wrote a compiler for a language that was nearly as complex as C is (probably 2 or 3 times as complicated as the language used in the previous semester), which, thanks to Flex and Bison, took far less time to write - maybe more like 20 hours to finish, once I understood how to do it.
 
Old 01-17-2004, 06:10 PM   #5
h/w
Senior Member
 
Registered: Mar 2003
Location: New York, NY
Distribution: Debian Testing
Posts: 1,286

Original Poster
Rep: Reputation: 46
hey wapcaplet - thanks.
i did write a scanner using flex/bison.
are u saying that you had a compiler from scanner to code generator done in ~20 hours in total?
i think im startin to feel ill now. i'll now downgrade "reasonably good C programmer" to something else.
 
Old 01-17-2004, 06:41 PM   #6
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
Yacc is a pretty good tool as well. If you get the right set of tools all you really need to make your own little compiler is a good grammer. I did a compiler project in college for a simple language kind of like lisp (hey... it was an assignment) and once I had a good understanding of lex and yacc I got it working in about 10 hours. Of course the grammer was really simple so that is partially why it took so little time. That and the fact the language really was useless.

Perl was designed in Lex and Yacc so they must be good for something.
 
Old 01-17-2004, 07:05 PM   #7
h/w
Senior Member
 
Registered: Mar 2003
Location: New York, NY
Distribution: Debian Testing
Posts: 1,286

Original Poster
Rep: Reputation: 46
10 hours? ill go kill myself now.
 
Old 01-17-2004, 08:16 PM   #8
wapcaplet
LQ Guru
 
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
You could probably accomplish it in less than 10 hours if you've done it a few times before, or if you don't care about it actually working
 
Old 01-19-2004, 02:57 PM   #9
nibbler
Member
 
Registered: Oct 2003
Location: Croatia
Distribution: Fedora 4
Posts: 46

Rep: Reputation: 15
10 hours? for my mother. for me 2-3 hours.



kiddin' lol
 
Old 01-19-2004, 02:57 PM   #10
Kurt M. Weber
Member
 
Registered: Oct 2003
Distribution: Slackware
Posts: 335

Rep: Reputation: 36
Quote:
Originally posted by jtshaw
Yacc is a pretty good tool as well.
From what I understand, Bison is just the GNU implementation of yacc.
 
Old 01-19-2004, 06:25 PM   #11
brig_sam
LQ Newbie
 
Registered: Sep 2003
Posts: 7

Rep: Reputation: 0
If you are doing it for a college project you can use the any language and I prefer C or C++ for the first time people because there is much docs about it and implementations as well so you can learn by example (memory mapping!) and if you are doing it for business (only you can calculate its outcome/income!).
 
Old 01-19-2004, 07:39 PM   #12
h/w
Senior Member
 
Registered: Mar 2003
Location: New York, NY
Distribution: Debian Testing
Posts: 1,286

Original Poster
Rep: Reputation: 46
its for college. and ill be doing it in C. hope to start on it soon.
 
Old 01-20-2004, 01:19 AM   #13
megaspaz
Senior Member
 
Registered: Nov 2002
Location: Silly Con Valley
Distribution: Red Hat 7.3, Red Hat 9.0
Posts: 2,054

Rep: Reputation: 46
while bison, yacc, and flex are indeed great tools for getting compilers written faster, imo, there's still something to be said about the nitty gritty theory on creating a language especially if your prof, like mine, won't allow you to use those tools.

great for reference at least.

http://www.amazon.com/exec/obidos/tg...57424?v=glance
 
Old 01-20-2004, 10:03 AM   #14
Kurt M. Weber
Member
 
Registered: Oct 2003
Distribution: Slackware
Posts: 335

Rep: Reputation: 36
Well, language design and language implementation are two entirely different things. All bison and flex do is automate the fairly simple (but all too time-consuming) task of writing a parser for the language. You still have to design the language properly, write the code-generation stuff yourself as well as the optimizer if you're going to have one, etc. The hard part you still have to do yourself.
 
Old 01-20-2004, 10:09 AM   #15
Kurt M. Weber
Member
 
Registered: Oct 2003
Distribution: Slackware
Posts: 335

Rep: Reputation: 36
Also, if the design of the language is what you want to concentrate on first (which you should if you're developing a serious language rather than a toy language so you can concentrate on the compiler), check out this:
http://www.nondot.org/sabre/Mirrored/AdvProgLangDesign/
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
checking for C compiler default output... configure: error: C compiler cannot create fiorejm Linux - Software 6 11-12-2009 12:35 PM
Compiler/interpreter writing dub.wav Programming 6 09-15-2005 08:50 PM
Compiler conundrum: Which came first, a compiler, or it's source code? fr0zen Programming 21 01-29-2004 04:31 AM
Writing CD Writing Software starunj Linux - Software 1 12-28-2003 05:05 AM
cd writing software which supports multisession writing jayakrishnan Linux - General 3 03-24-2003 05:51 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:06 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration