Click here to Skip to main content
15,892,537 members
Articles / Programming Languages / C#

Irony - .NET Compiler Construction Kit

Rate me:
Please Sign up or sign in to vote.
4.97/5 (86 votes)
4 Jan 2008MIT19 min read 295.4K   3.2K   201  
Introduction to Irony - a new technology of parser/compiler construction for .NET.
#region License
/* **********************************************************************************
 * Copyright (c) Roman Ivantsov
 * This source code is subject to terms and conditions of the MIT License
 * for Irony. A copy of the license can be found in the License.txt file
 * at the root of this distribution. 
 * By using this source code in any fashion, you are agreeing to be bound by the terms of the 
 * MIT License.
 * You must not remove this notice from this software.
 * **********************************************************************************/
#endregion

using System;
using System.Collections.Generic;
using System.Text;

namespace Irony.Compiler {

  public class TokenList : List<Token> {}

  //Tokens are produced by scanner and fed to parser, possibly passing through Token filters first. 
  // Token is derived from AstNode because tokens are pushed into Parser stack (like non-terminal nodes),
  // and then they can be included as sub-nodes into AST tree. So Token is a kind of AstNode. 
  public class Token : AstNode  {
    public Token(Terminal terminal, SourceLocation location, string text, object value)
      : this(terminal, location, text){
      _value = value;
    }
    public Token(Terminal terminal, SourceLocation location, string text)   : base (null, terminal, location, null){
      _text = text;
      _value = text;
      if (text != null)
        _length = text.Length;
    }
    
    public Terminal Terminal   {
      get {return base.Element as Terminal;}
    } 

    public int Length  {
      get {return _length;}
    } int  _length;

    public string Text  {
      get {return _text;}
      set {_text = value;}
    } string  _text;

    public object Value {
      get { return _value; }
      set { _value = value; }
    } object _value;

    public override string ToString() {
      if (Value == null)
        return "null";
      string result = Value.ToString();
      if (result != Terminal.ToString())
        result += ", " + Terminal.ToString();
      return result;
    }

  }//class


}//namespace

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, along with any associated source code and files, is licensed under The MIT License


Written By
Software Developer (Senior) Microsoft
United States United States
25 years of professional experience. .NET/c#, databases, security.
Currently Senior Security Engineer, Cloud Security, Microsoft

Comments and Discussions