This post originated from an RSS feed registered with Python Buzz
by Fabiano Weimar dos Santos.
Original Post: NABA Compiler
Feed Title: [Xiru].org
Feed URL: http://xiru.org/blog/search_rss?path=/Xiru/blog
Feed Description: [Xiru].org - Fabiano Weimar dos Santos' Website. Usefull information about xiru's projects, Plone and Zope community and Python hacks.
In the begging of this week, I "finished" a compiler prototype. I
called it NABA, a worst version of a Java compiler. NABA is written in
Python and It's not made to be a real compiler. For me, It's some kind
of "prof of concepts". However, the code could be very usefull for
"educational" use.
NABA have a lexical parser written using regular expressions. That
part of the code is very clean and robust (my favorite part). The
sintatic and semantic parser was written manually, without any "yacc"
like tool. It is a recursive implementation based on a ambiguous
grammar. However, the code is clear and very well organized. The
semantic actions and type verification are made using an interesting
approach, based on dynamic lookheads between recursion calls and an
object tree to represent the symbols escopes.
At least for now, I don't want to finish this project. I'm publishing
the code to make it avaliable for everyone. If you like it, use it to
create your own code or for simple inspiration. Make a compiler is not
a trivial task, but with a code snipted it could be more interesting
and funny.