Forums

Chuk ! Can you briefly explain how you made your compiler.

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

Chuk ! Can you briefly explain how you made your compiler.

Postby SANTOSH273 » Mon Apr 06, 2009 10:10 am

Hi,

Your help really helped me in working with my project. My professor is pleased with our work and research paper on Cobra.
We are now studying on compilers. Can you help me in knowing how to build a compiler by your experience.
So that it would explore my knowledge int hat world.

Thanq,
SANTOSH KUMAR.P.
SANTOSH273
 
Posts: 9

Re: Chuk ! Can you briefly explain how you made your compiler.

Postby Charles » Mon Apr 06, 2009 10:47 am

Hi Santosh, would you be willing to share your paper on Cobra either here in the forums or directly to me? I'd like to see it.

Regarding your question on how I built Cobra:

I built the first compiler in Python. It read .cobra files and emitted C# files. It took a lot of shortcuts and relied on C# for a lot of error checking, so it was more of a translator.

Then I rebuilt the compiler in Cobra. Again the program read .cobra files and emitted C#. But this time the error checking is much more thorough--the compiler really knows the semantics.

The compiler is broken into phases which are roughly:
-- lex
-- parse
-- bind use
-- bind inheritance
-- bind implementation
-- generate code

The parse phase produces "AST nodes" or "Abstract Syntax Tree Nodes". Often just called ASTs. Each AST represents a specific language construct such as an if-statement, method-declaration, etc. Each AST is an object with a class like IfStatement, Method, etc.

More details are found in a text file with the source code. If you check out a copy of the repository, look in <workspace>\Developer\ImplementationNotes.text
Charles
 
Posts: 2515
Location: Los Angeles, CA


Return to Discussion

Who is online

Users browsing this forum: No registered users and 26 guests