Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

A Simple Compiler for the Common Language Runtime

, 11 May 2003
An end-to-end example of a bottom up LALR(1) compiler for a fictitious language targeting the Common Language Runtime
compiler_demo.zip
Bubble Sort
Bubble Sort.shp
Config.dck
mike.exe
Sort.exe
Sort.pdb
Sort.sh
compiler_src.zip
Core
App.ico
bin
Core.csproj.user
Core.suo
Magic IDE
App.ico
bin
Debug
Config.dck
Images.bmp
Sharp.cgt
ICSharpCode.TextEditor.dll
Magic IDE.csproj.user
Magic IDE.suo
MagicLibrary.DLL
UtilityLibrary.dll
/*
Magic IDE
Copyright (C) 2003  Michael Bebenita

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

using System.IO;

namespace Magic_IDE
{
	/// <summary>
	/// Summary description for NewFileWizard.
	/// </summary>
	public class NewFileWizard : System.Windows.Forms.Form
	{
		private Crownwood.Magic.Controls.WizardControl m_Wizard;
		private Crownwood.Magic.Controls.WizardPage m_Page1;
		private System.Windows.Forms.TextBox m_txtFileName;
		private System.Windows.Forms.Label label1;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		private Project m_Project = null;
		public NewFileWizard(Project project)
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
			m_Project = project;
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.m_Wizard = new Crownwood.Magic.Controls.WizardControl();
			this.m_Page1 = new Crownwood.Magic.Controls.WizardPage();
			this.m_txtFileName = new System.Windows.Forms.TextBox();
			this.label1 = new System.Windows.Forms.Label();
			this.m_Page1.SuspendLayout();
			this.SuspendLayout();
			// 
			// m_Wizard
			// 
			this.m_Wizard.Name = "m_Wizard";
			this.m_Wizard.SelectedIndex = 0;
			this.m_Wizard.ShowBackButton = Crownwood.Magic.Controls.WizardControl.Status.No;
			this.m_Wizard.ShowNextButton = Crownwood.Magic.Controls.WizardControl.Status.No;
			this.m_Wizard.Size = new System.Drawing.Size(476, 352);
			this.m_Wizard.TabIndex = 0;
			this.m_Wizard.Title = "Create New File Wizard";
			this.m_Wizard.WizardPages.AddRange(new Crownwood.Magic.Controls.WizardPage[] {
																							 this.m_Page1});
			this.m_Wizard.CancelClick += new System.EventHandler(this.m_Wizard_CancelClick);
			this.m_Wizard.FinishClick += new System.EventHandler(this.m_Wizard_FinishClick);
			// 
			// m_Page1
			// 
			this.m_Page1.CaptionTitle = "(Page Title)";
			this.m_Page1.Controls.AddRange(new System.Windows.Forms.Control[] {
																				  this.m_txtFileName,
																				  this.label1});
			this.m_Page1.FullPage = false;
			this.m_Page1.Name = "m_Page1";
			this.m_Page1.Size = new System.Drawing.Size(476, 223);
			this.m_Page1.SubTitle = "(Page Description not defined)";
			this.m_Page1.TabIndex = 3;
			// 
			// m_txtFileName
			// 
			this.m_txtFileName.Location = new System.Drawing.Point(112, 40);
			this.m_txtFileName.Name = "m_txtFileName";
			this.m_txtFileName.Size = new System.Drawing.Size(328, 21);
			this.m_txtFileName.TabIndex = 3;
			this.m_txtFileName.Text = "";
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(16, 44);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(84, 16);
			this.label1.TabIndex = 2;
			this.label1.Text = "Project Name:";
			// 
			// NewFileWizard
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(476, 350);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.m_Wizard});
			this.Name = "NewFileWizard";
			this.Text = "NewFileWizard";
			this.m_Page1.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		private void m_Wizard_CancelClick(object sender, System.EventArgs e)
		{
			DialogResult = DialogResult.Cancel;
			Close();
		}

		public ProjectFile ProjectFile;

		private void m_Wizard_FinishClick(object sender, System.EventArgs e)
		{
			string fileName = m_txtFileName.Text;

			if(!Path.HasExtension(fileName))
				fileName += ".sh";
			
			if(File.Exists(m_Project.Directory + "\\" + fileName))
			{
				MessageBox.Show("File already exists.");
				return;
			}

			ProjectFile = ProjectFile.Create(m_Project,m_Project.Directory + "\\" + fileName);
			DialogResult = DialogResult.OK;
			Close();
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Michael Bebenita
Web Developer
United States United States
Currently a graduate student at UCI.

| Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 12 May 2003
Article Copyright 2003 by Michael Bebenita
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid