I'm not an instructor. I'm a student doing such course. And I'm just trying to figure out what to do, because we're not given an input language.

What kind of (input) language would you suggest for an University compiler project?

It's a project typical to the compiler course in CS programs.

However, I've been confused about, whether it would be easier to design a language for the project or use some existing programming language.

It should be able to handle the following requirements:

Readable (no binary noodles)
At least two different types of data (type errors must be captured at the latest during the run)
Integrity technology
Making choices (if tms)
Playback (loops, recursion etc)
Parameterizable subroutines (functions, methods, etc) that can use local variables

Additional features

Tables (multidimensional, 0.5 cr, one-dimensional 0.25 cr)
String input and output (0.25 cr)
String interpolation or printf-style formatting by yourself (0.25 cr)
    Complex printf formats (0.25 cr)
Records and variants (0.5 cr)
Generic (Static) Types (0.5 cr)
Classes and Late Binding (0.5 cr)
First-class functions (0.5 cr)
Garbage collection (entirely self-made) (1 cr)
Recursive pattern match (garden Haskell) (0.5 cr)
Lazy calculation (1-2 cr depending on the implementation technique)

Additionally the implementation would include:

Relatively effective interpreter without separate intermediate language 0 cr
Generation of intermediate language (eg own, JVM or LLVM) 1 cr
Generation of a machine language (eg AMD64 or ARM) from its own intermediate language
Naive register allocation 1 cr
Smart register allocation (eg graphing) 2 cr

Also, what existing programming languages would fit into all of these? Does it have to be a functional language or does even C implement all of these?

  • $\begingroup$ Since this question doesn't really reflect the mission of this SE, I thought this would be a good place to mention area51.stackexchange.com/proposals/92460/…. The proposal is getting very close to Beta, and your question would be perfect there. $\endgroup$ – Ben I. Apr 21 '17 at 13:17
  • $\begingroup$ @Choirbean I'm not an instructor. I'm a student doing such course. And I'm just trying to figure out what to do, because we're not given an input language. $\endgroup$ – mavavilj Apr 21 '17 at 13:25
  • $\begingroup$ Given Brian's answer "The choice of compiler implementation language depends on the tool set you choose to teach", it sounds like I wasn't the only one confused here. You should put that at the top of your question, because the rest of what you've written sounds like you're designing an assignment. :) $\endgroup$ – Ben I. Apr 21 '17 at 13:33
  • $\begingroup$ How about consulting the instructor, the TAs, or former students? $\endgroup$ – Yuval Filmus Apr 22 '17 at 11:11

I think you are trying to achieve too much in a single exercise. It would, in my opinion, be better to separate the compiler construction part of the exercise from the comparative language part.

Good code generation and optimisation are difficult for some of the additional features you have cited. In my view it is better that students learn to do some decent lexing, parsing, optimisation and code generation before having to handle some of the more complex features of languages.

If you create a portmanteau of a language you end up with lots of examples of rotten and partially functioning compilers which do not help them learn.

It also matters what the target language you are going to use. Are you asking them to generate CIL, Byte Code, C or some other output format? Each of these has different pedagogic reasons for their choice.

Choosing a language to build an example compiler for is like choosing a first programming language. There is no right choice.

To start building compilers I often recommend compiling something like Pascal or even simpler. (The choice of compiler implementation language depends on the tool set you choose to teach.)

| cite | improve this answer | |
  • $\begingroup$ You mean Pascal as the input language? Or as the programming language. I'm versed in few programming languages in order to write the compiler in it, but I have no experience in language design, which is why I was thinking of compiling an existing language such as Python. Which would also have constructs for all the features. $\endgroup$ – mavavilj Apr 21 '17 at 10:42
  • $\begingroup$ I was thinking that using Python as the input language might be simplest? Or would it be simpler to design one's own language? $\endgroup$ – mavavilj Apr 21 '17 at 10:47
  • $\begingroup$ I have clarified my wording. Python as an input language would be a lexical nightmare! $\endgroup$ – Brian Tompsett - 汤莱恩 Apr 21 '17 at 11:15
  • $\begingroup$ But is there any other language that would have all the features that ought to be implemented? Unless one designs one's own language. $\endgroup$ – mavavilj Apr 21 '17 at 11:19
  • $\begingroup$ Perhaps theory.stanford.edu/~aiken/software/cool/cool.html. $\endgroup$ – mavavilj Apr 21 '17 at 11:39

I recommend looking at a well-written textbook on compilers, e.g. Modern Compiler Implementation in Java by Appel/Palsberg, and use the source language of the book. It has been battle tested in classroom many times, and builds up language complexity in an incremental fashion.

The surface syntax of the language isn't all that interesting, because it gets abstracted away by lexer/parser anyway.

| cite | improve this answer | |
  • $\begingroup$ Do you know if the language there would be comparable to Cool? $\endgroup$ – mavavilj Apr 21 '17 at 12:15
  • $\begingroup$ Yes, it's similar. I think Aiken was inspired by Appel/Palsberg. Why don't you look at the book? $\endgroup$ – Martin Berger Apr 21 '17 at 13:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.