'How do I start creating a small compiler for a school project in java or c#

for my final exam (to graduate from university) I’ve been asked to create a tiny compiler, with the following requirements:

The student must develop a basic compiler with all the design parts that conforms it (lexical analysis, syntaxis analysis, parsing, etc). This compiler will have an interface that shows 2 panels, a graphic representation (A) and code representation (B). The user will be able to draw a geometric shape in panel (A), and the program will show in panel B the code generated for that shape, and the if the user types code in (B) it will show the shape in (A).

This compiler must handle at least 7 primitives (I guess this means commands). The geometric shape must be created from the primitives. The student will have to include a primitive to rotate the shape.

So the thing is that we never studied compilers in depth, just the very basic theory, I only have 20 days to finish this!! and I’m pretty sure they want to make me flunk because I asked the professor to tell me what is a primitive and he said he wouldn’t answer that because that is part of the vocabulary of the course I want to pass.

So the question here is:

How should I start, how do I create this thing in .NET or how do I create my very small set of instructions to create geometric shapes?

Is there something out there similar to this requirement to take it as an example and modify it?

P.S.: I’m a .net C# developer (good skills). I know the basics of C and Java. I’m reading about parser generators (ANTLR, lex & YACC, Ray) but there’s no basic tutorial for that, there are a lot of new terms like BNF grammar (what is this, a language, a txt file?). It is so hard because there’s no easy way to start, or samples for C#. I don’t want to do this project in C or C++ because since it’s using graphics and my C knowledge is basic, I’m afraid I won’t be able to do it, I would like to use .Net



Solution 1:[1]

I recommend you implement Context-Free Art.

It will be relatively ugly to convert drawing to code - you'll inevitably describe a set of fixed shapes at fixed locations. And all your classmates will do likewise.

But by implementing the context-free grammar, you'll be able to generate absolutely stunning pictures from code. This will be massively satisfy and will spur you to polish and pass and you'll be left with something to show off afterwards.

Solution 2:[2]

It sounds like the exercise is about generating and parsing something like SVG. It also sounds like the professor is not completely clear on what a compiler is. Translating from text to graphics might be within some academic definition of compiler, but it certainly doesn't reflect any real world meaning (in spite of work done on graphical programming languages).

Perhaps to fulfill the requirement of "compiler" you could translate a subset of SVG (which is textual) to JavaScript commands for generating the graphics. For the meaning of "primitive" you could just google it. Sort of, show some initiative.

Then you could do your user interface in HTML, which would fit the time frame better than anything else I can think of. Essentially this would be something like Google Documents Draw, except with display of the drawing's representation as SVG.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Will
Solution 2 halfer