Click here to Skip to main content
15,896,450 members
Articles / Programming Languages / C#

C# CodeDOM parser

Rate me:
Please Sign up or sign in to vote.
4.56/5 (14 votes)
27 Jun 20026 min read 248.2K   4.3K   70  
This is a utility which parses C# source code and creates the CODEDOM tree of the code.
//
// GenericParser.cs: The Base Parser for the Mono compilers
//
// Author: A Rafael D Teixeira (rafaelteixeirabr@hotmail.com)
//
// Licensed under the terms of the GNU GPL
//
// Copyright (C) 2001 Ximian, Inc.
//
using System;
using System.Text;

namespace Mono.Languages
{
	using System.Collections;

	/// <summary>
	/// Base class to support multiple Jay generated parsers
	/// </summary>
	public abstract class GenericParser
	{
		protected int global_errors;

		// Name of the file we are parsing
		public string name;

		// Input stream to parse from.
		public System.IO.Stream input;

		public abstract int parse ();

		public virtual string[] extensions()
		{
			string [] list = { ".cs" };
			return list;
		}

		/// <summary>
		/// Emits error messages and increments a global count of them
		/// </summary>
		/// <param name="code"></param>
		/// <param name="desc"></param>
		public void error (int code, string desc)
		{
			Console.WriteLine ("Error "+code+": "+ desc);
			global_errors++;
		}

		// Emits error messages with location info.
		// FIXME : Ideally, all error reporting should happen
		// with Report.Error but how do you get at that non-static
		// method everywhere you need it ?
		public void error (int code, Mono.CSharp.Location l, string text)
		{
			Console.WriteLine (l.Name + "(" + l.Row + "," + 
					   "): Error CS" + code + ": " + text);
			global_errors++;
		}
		
		public GenericParser()
		{
			//
			// DO NOTHING: Derived classes should do their iniatilization here duties
			//
		}

		protected bool yacc_verbose_flag = false;

		public bool yacc_verbose
		{
			set
			{
				yacc_verbose_flag = value;
			}

			get
			{
				return yacc_verbose_flag;
			}
		}
	}
}



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


Written By
Czech Republic Czech Republic
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions