Subscribe to Stuck in an Infiniteloop        RSS Feed
-----

Semantic Analysis is the Devil

Icon Leave Comment
Or How To Think of Every Edge Case Ever.

Currently taking a compiler class and on the semantic analysis stage. I have this here Abstract Syntax Tree based on some code I have determined to be syntactically correct. Now I get to see if the author of said code was a dumbass. We're using a subset of C, C- (C-, that's one minus) which is C with a bunch of crap stripped out so one could hope to get a working compiler done in a semester (well, and work full time).

Essentially you have integers and void, no pointer arithmetic, global/local/parameter variables, no prototypes, main must be the last function in a file, so on and so forth. It's relatively trivial to add code to check for things that are stupid, but then there are things you don't think about.

For example, it is syntactically correct to do void z[10];, but it makes no sense. Ten voids? What?

The best part is there isn't an actual list of semantics, well in list form. The textbook has a little discussion on each part of the BNF, but left to my own imagination I think of nonsense like the above.

When this is all said and done I feel a loooooong post on compilation coming up. If you're contemplating taking a compiler course, you should totally do it! The material is fascinating.

0 Comments On This Entry

 

December 2014

S M T W T F S
 123456
78910111213
14151617 18 1920
21222324252627
28293031   

Tags

    Recent Entries

    Recent Comments

    Search My Blog

    1 user(s) viewing

    1 Guests
    0 member(s)
    0 anonymous member(s)