CS473 – Writing a compiler for a simple language

This semester one of neatest course I have taken is CS 473: Compiler Design. Professor V. N. Venkatakrishnan is teaching the course. We will be writing a complier for a language called C-, so lots of coding and we really get to understand how the abstract concepts are implemented. It will be a series of six homework projects.

Last semester I planed to note down stuff while doing CS 450 Introduction to Networking – another programming intensive course. And due to many other things – that did not materialize. But this time, we have to submit a short essay on what we learnt in each project which gets graded. Well quite a reason to blog. Here is the first essay.

Implementation of Scanner for C– with (f)lex

What I learnt:
The basic structure of a lex program.

Still not feeling confident:
Using lex api results gives optimized results. How to make efficient usage of it in rules and user submitted routine
Apart form a few documentation, there is hardly any that’s contrite but makes you feel confident

References used:
While none were fully read, peeped into following
[1] http://dinosaur.compilertools.net/flex/
[2] http://www.cs.manchester.ac.uk/~pjj/cs5031/ho/
[3] http://docs.sun.com/app/docs/doc/802-1952/6i5uu4c0f?a=view
[4] http://www.ibm.com/developerworks/library/l-lex.html
[5] http://stackoverflow.com/questions/641701/excellent-online-tutorial-for-lex-and-yacc

Further reading planned from:
[1] lex & yacc, Second Edition – ByDoug Brown, John Levine, Tony MasonPublisher:O’Reilly Media

Just a few lines of bash scripting to do the test cases at once (assuming the test directory is in pwd).

rm -f testresult;
for i in `ls test/*.c`;do
echo $i>> testresult; cat -n $i >> testresult; echo “———–“>> testresult; ./cmlexer $i >> testresult;