CodeGuru
Earthweb Search
Forums Wireless Jars Gamelan Developer.com
CodeGuru Navigation
Member Sign In
User ID:
Password:
Remember Me:
Forgot Password?
Not a member?
Click here for more information and to register.

jobs.internet.com

internet.commerce
Partners & Affiliates
Promos and Premiums
Laptops
Compare Prices
Promotional Golf
PDA Phones & Cases
Baby Photo Contest
Memory Upgrades
Memory
Compare Prices
Data Center Solutions
GPS Devices
Disney World Tickets
Prepaid Phone Card
Imprinted Promotions


RSS Feeds

RSSAll

RSSVC++/C++

RSS.NET/C#

RSSVB

See more EarthWeb Network feeds

Home >> Visual C++ / C++ >> C++ >> C++ & MFC >> Parsing

Best Practices for Developing a Web Site: Checklists, Tips, Strategies & More. Download Exclusive eBook Now.

Mini Pascal Compiler
Rating: none

Zoly Farkas (view profile)
August 9, 1999

Environment: VC6


(continued)



Download these IBM resources today!
e-Kit: IBM Rational Systems Development Solution
With systems teams under so much pressure to develop products faster, reduce production costs, and react to changing business needs quickly, communication and collaboration seem to get lost. Now, theres a way to improve product quality and communication.

Webcast: Asset Reuse Strategies for Success--Innovate Don't Duplicate!
Searching for, identifying, updating, using and deploying software assets can be a difficult challenge.

eKit: Rational Build Forge Express
Access valuable resources to help you increase staff productivity, compress development cycles and deliver better software, fast.

Download: IBM Data Studio v1.1
Effectively design, develop, deploy and manage your data, databases, and database applications throughout the data management life.

eKit: Rational Asset Manager
Learn how to do more with your reusable assets, learn how Rational Asset Manager tracks and audits your assets in order to utilize them for reuse.

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.

Mini Pascal Compiler

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
For the asm and pas documents, I used the syntax coloring editor code from Adrei Stcherbachenko, that I downloaded from CodeGuru.

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.

Downloads

Download source - 169 Kb

Tools:
Add www.codeguru.com to your favorites
Add www.codeguru.com to your browser search box
IE 7 | Firefox 2.0 | Firefox 1.5.x
Receive news via our XML/RSS feed

Whitepaper: Enterprise Information Integration--Deployment Best Practices for Low-Cost Implementation
Best Practices for Developing a Web Site. Checklists, Tips & Strategies. Download Exclusive eBook Now.
Generate Complete .NET Web Apps in Minutes . Download Iron Speed Designer today.
Developing Intelligent Communications? Visit the Avaya DevConnect Center on DevX.
Guide to Developing a Web Site. Best Practices, Tips and Strategies. Download Exclusive eBook Now.


RATE THIS ARTICLE:   Excellent  Very Good  Average  Below Average  Poor  

(You must be signed in to rank an article. Not a member? Click here to register)

Latest Comments:
Pascal Compiler Problem :( - Legacy CodeGuru (06/25/2003)
Wonderful Work! - Legacy CodeGuru (05/31/2002)
Pascal Compiler - Legacy CodeGuru (03/11/2002)
Good job - Legacy CodeGuru (03/05/2002)
Extensions? - Legacy CodeGuru (03/19/2001)

View All Comments
Add a Comment:
Title:
Comment:
Pre-Formatted: Check this if you want the text to display with the formatting as typed (good for source code)



(You must be signed in to comment on an article. Not a member? Click here to register)


JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
Microsoft Article: HyperV-The Killer Feature in WinServer ‘08
Avaya Article: How to Feed Data into the Avaya Event Processor
Microsoft Article: Install What You Need with Win Server ‘08
HP eBook: Putting the Green into IT
Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
Avaya Article: Setting Up a SIP A/S Development Environment
IBM Article: How Cool Is Your Data Center?
Microsoft Article: Managing Virtual Machines with Microsoft System Center
HP eBook: Storage Networking , Part 1
Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Intel Video: Are Multi-core Processors Here to Stay?
On-Demand Webcast: Five Virtualization Trends to Watch
HP Video: Page Cost Calculator
Intel Video: APIs for Parallel Programming
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Sun Download: Solaris 8 Migration Assistant
Sybase Download: SQL Anywhere Developer Edition
Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
Red Gate Download: SQL Compare Pro 6
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
IBM Article: Collaborating in the High-Performance Workplace
HP Demo: StorageWorks EVA4400
Microsoft How-to Article: Get Going with Silverlight and Windows Live
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES