Writing a compiler - how?

Programming, for all ages and all languages.
JuEeHa
Member
Member
Posts: 30
Joined: Thu Mar 10, 2011 4:24 am

Re: Writing a compiler - how?

Post by JuEeHa »

turdus wrote: For me at the university in the first 2 semesters we learned programming by only matchematical mean with paper and pencil. I'm pretty sure you cannot imagine this (or even imagine how to learn programming without a computer). You can bet most of you would cry if had to understand the matchematical formula of a simple loop (for the courious, I've attached it). So my learning language was math. Later I had courses that tought how specific languages like C, ADA, Eiffel, Java etc. implement that theory.
That seems pretty interesting. Are there any online courses where it would be possible to learn programming that way?
Using 700MHz Pentium III machine with 64MB of RAM because I feel like it.
ed implementation in C: main(a){for(;;;){read(0,&a,1);if(a=='\n')write(1,"?\n",2);}}
User avatar
turdus
Member
Member
Posts: 496
Joined: Tue Feb 08, 2011 1:58 pm

Re: Writing a compiler - how?

Post by turdus »

JuEeHa wrote:That seems pretty interesting. Are there any online courses where it would be possible to learn programming that way?
Don't think so, did not find anything on the university's homepage (only student exchange program). But I've found an english description of the training:
http://www.inf.elte.hu/english/studies/ ... ammes.aspx
Funny how things change, when I attended to (several years ago), there was no such thing, BSc/MSc just an university degree. There was no geoinformatics then, and no media courses.
I feel old...
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Writing a compiler - how?

Post by Combuster »

The closest thing to program logic I know is http://www.cs.uu.nl/docs/vakken/pc/1112 ... s/main.pdf - and fortunately it was in English. It's probably nowhere near ancient CS teachings and it basically works the opposite direction by reducing code to a mathematical representation.

More on topic would be http://www.cs.uu.nl/wiki/pub/TC/CourseM ... 111101.pdf - I don't have the dragon book so I can't say how much better it is, but this is definitely cheaper :D.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: Writing a compiler - how?

Post by JamesM »

MessiahAndrw wrote:
Rudster816 wrote:I think you need to read your own link ;). Number 8 is >, <, >=, <=. Number 13 is &&.
I stand corrected. May explain a couple of bugs I've encountered in the past.

I've got into the habit of explicitly using brackets lately since I deal with many languages day-to-day, just for situations like this!
You were correct, Rudster816 was wrong.

That table is ordered lowest-to-highest precedence. I have my C99 standard open in front of me, but to save me typing it all out I below paste part of the comment from Clang's function "ParseExpression".

Code: Select all

///       multiplicative-expression: [C99 6.5.5]
///     Note: in C++, apply pm-expression instead of cast-expression
///         cast-expression
///         multiplicative-expression '*' cast-expression
///         multiplicative-expression '/' cast-expression
///         multiplicative-expression '%' cast-expression
///
///       additive-expression: [C99 6.5.6]
///         multiplicative-expression
///         additive-expression '+' multiplicative-expression
///         additive-expression '-' multiplicative-expression
///
///       shift-expression: [C99 6.5.7]
///         additive-expression
///         shift-expression '<<' additive-expression
///         shift-expression '>>' additive-expression
///
///       relational-expression: [C99 6.5.8]
///         shift-expression
///         relational-expression '<' shift-expression
///         relational-expression '>' shift-expression
///         relational-expression '<=' shift-expression
///         relational-expression '>=' shift-expression
///
///       equality-expression: [C99 6.5.9]
///         relational-expression
///         equality-expression '==' relational-expression
///         equality-expression '!=' relational-expression
///
///       AND-expression: [C99 6.5.10]
///         equality-expression
///         AND-expression '&' equality-expression
///
///       exclusive-OR-expression: [C99 6.5.11]
///         AND-expression
///         exclusive-OR-expression '^' AND-expression
///
///       inclusive-OR-expression: [C99 6.5.12]
///         exclusive-OR-expression
///         inclusive-OR-expression '|' exclusive-OR-expression
///
///       logical-AND-expression: [C99 6.5.13]
///         inclusive-OR-expression
///         logical-AND-expression '&&' inclusive-OR-expression
///
///       logical-OR-expression: [C99 6.5.14]
///         logical-AND-expression
///         logical-OR-expression '||' logical-AND-expression
///
///       conditional-expression: [C99 6.5.15]
///         logical-OR-expression
///         logical-OR-expression '?' expression ':' conditional-expression
/// [GNU]   logical-OR-expression '?' ':' conditional-expression
/// [C++] the third operand is an assignment-expression
///
///       assignment-expression: [C99 6.5.16]
///         conditional-expression
///         unary-expression assignment-operator assignment-expression
/// [C++]   throw-expression [C++ 15]
///
///       assignment-operator: one of
///         = *= /= %= += -= <<= >>= &= ^= |=
///
///       expression: [C99 6.5.17]
///         assignment-expression ...[opt]
///         expression ',' assignment-expression ...[opt]
Post Reply