Mini Pascal Compiler
Environment: VC6
I had to make a project last month for the Compiler Techniques course at the university where I study. This project was to make a simple Pascal compiler for an imaginary virtual machine. I also work for a software company so I had to make the project in my free time after university and work, so in some places the code is made in a rush (you know what I mean). Anyway, this program is a nice compiler sample, and for people who are interested, might me a good source of ideas.
The program is a multi document/view based application. It supports 3 types of files:
- *.rez, a token result file that is generated after parsing the source code
- *.asm, an assembler file containing virtual machine code, that is generated by the compiler together with the binary file
- *.pas, Pascal source files
This sample was made using Visual C++ v 6.0, and contains 2 projects: the compiler and the virtual code interpreter.
General Structure
I used the following class hierarchy:CObject -> CStringTokenizer -> CPascalLexAnalyzer -> CPascalCompiler
I tried to modularize the compiling process so that the reusability of the classes would be higher. For example, the CStringTokenizer class can be used for tokenizing strings and command line parameters and can be used to make a C Lexical analyzer, etc. The CPascalLexAnalyzer is used to tokenize the Pascal source, and the CPascalCompiler is responsible for making syntactical and semantically verifications and for the actual compilation.

Comments
Pascal Compiler Problem :(
Posted by Legacy on 06/25/2003 12:00amOriginally posted by: victor
ReplyWonderful Work!
Posted by Legacy on 05/31/2002 12:00amOriginally posted by: Peter
I would be grateful if you could provide me the principle description of the codes. It is difficult for me to research source codes without guider documents. I would appreciate it if you could contact me as: petersia@hotmail.com. Thanks!
ReplyGood job
Posted by Legacy on 03/05/2002 12:00amOriginally posted by: Sanjoy chowdhury
Good job. Thanks
ReplyExtensions?
Posted by Legacy on 03/19/2001 12:00amOriginally posted by: Sia, Kelvin
Do you have a simple C lexical parser?
ReplyDo you have a version of the source in CBuilder?
What is Result?
Posted by Legacy on 09/16/2000 12:00amOriginally posted by: Taegoon
I want compile result
what is result?
~.pas -> compile -> ~.exe
Replywhere are execute file?
Output Directory
Posted by Legacy on 05/30/2000 12:00amOriginally posted by: John A. Donaldson
How do I override the default output directory? Presently
Replyit is set to E:\
How to do?
Posted by Legacy on 05/28/2000 12:00amOriginally posted by: Daniel Anderson
ReplyNice Editor
Posted by Legacy on 10/27/1999 12:00amOriginally posted by: Ernest L.
The editor is nice!
It helps me with my design.
Thanks and keep your good work.
Ernest L.
Reply
Good - 1 error in the zipped source
Posted by Legacy on 08/26/1999 12:00amOriginally posted by: rinix
Really good
I'm doing an universal editor like UltraEdit, but with improved capacities with command line compilers (all languages)
But after downloading the sources, I've compiled them, and there were a little error on the TypeInfo struct
the assignment operator must return a value and there's no return statment in the code, so I've placed the statment
TypeInfo & operator = (TypeInfo &info)
{
m_nClass = info.m_nClass;
m_nType = info.m_nType;
m_nIndMin = info.m_nIndMin;
m_nIndMax = info.m_nIndMax;
m_nSize = info.m_nSize;
m_VarList.RemoveAll( );
m_VarList.AddTail( &info.m_VarList );
// my added code
return *this;
}
Gook luck in continuing
regards, rinix
ReplyGood job!
Posted by Legacy on 08/12/1999 12:00amOriginally posted by: webdog
Thank you and your good job
Reply