Click here to Skip to main content
Click here to Skip to main content
Articles » Languages » C# » General » Downloads
 
Add your own
alternative version

Conscript: An embeddable, compiled scripting language for .NET

, 5 Sep 2008 CPOL
An API for enhancing any .NET application with a scripting language
conscript_api_and_demo_source.zip
Conscript_API_&_Demo_Source
Conscript
ConscriptDemo
Conscript.ico
Properties
Settings.settings
vssver2.scc
Resources
Conscript.ico
vssver2.scc
vssver2.scc
Collections
vssver2.scc
Compiler
vssver2.scc
Conscript.doxyfile
Properties
vssver2.scc
Resources
Conscript.ico
vssver2.scc
Runtime
vssver2.scc
vssver2.scc
SampleScripts
BubbleSort.cns
Dungeon.cns
Factorial.cns
HelloWorld.cns
vssver2.scc
using System;
using System.Collections.Generic;
using System.Text;

namespace Conscript.Compiler
{
    /// <summary>
    /// Represents a lexing token generated by the script lexer and used
    /// by the parser.
    /// </summary>
    public class Token
    {
        #region Private Variables

        private TokenType m_tokenType;
        private object m_objectLexeme;
        private int m_iSourceLine;
        private int m_iSourceChar;
        private String m_strSourceLine;

        #endregion

        #region Public Methods

        /// <summary>
        /// Creats a token with the given <see cref="TokenType"/>, lexeme,
        /// source line and character position and source text for the given
        /// line.
        /// </summary>
        /// <param name="tokenType">The token's <see cref="TokenType"/>.
        /// </param>
        /// <param name="objectLexeme">The lexeme associated with the token.
        /// </param>
        /// <param name="iSourceLine">The source line number where the token
        /// occurs.</param>
        /// <param name="iSourceChar">The source character number where the
        /// token occurs.</param>
        /// <param name="strSourceLine">The source text line where the token
        /// occurs.</param>
        public Token(TokenType tokenType, object objectLexeme,
            int iSourceLine, int iSourceChar, String strSourceLine)
        {
            m_tokenType = tokenType;
            m_objectLexeme = objectLexeme;
            m_iSourceLine = iSourceLine;
            m_iSourceChar = Math.Max(0, iSourceChar - objectLexeme.ToString().Length - 1);
            m_strSourceLine = strSourceLine;
        }

        /// <summary>
        /// Returns a string representation of the token.
        /// </summary>
        /// <returns>String representation of the token.</returns>
        public override String ToString()
        {
            return m_tokenType + " (\"" + m_objectLexeme.ToString() + "\")";
        }

        #endregion

        #region Public Methods

        /// <summary>
        /// The token's <see cref="TokenType"/>.
        /// </summary>
        public TokenType Type
        {
            get { return m_tokenType; }
        }

        /// <summary>
        /// The lexeme associated with the token.
        /// </summary>
        public object Lexeme
        {
            get { return m_objectLexeme; }
        }

        /// <summary>
        /// The source line number where the token occurs.
        /// </summary>
        public int SourceLine
        {
            get { return m_iSourceLine; }
        }

        /// <summary>
        /// The source character position where the token occurs.
        /// </summary>
        public int SourceCharacter
        {
            get { return m_iSourceChar; }
        }

        /// <summary>
        /// The source text line where the token occurs.
        /// </summary>
        public String SourceText
        {
            get { return m_strSourceLine; }
        }

        #endregion
    }
}

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 Code Project Open License (CPOL)

Share

About the Author

Colin Vella
Software Developer (Senior)
Malta Malta
No Biography provided

| Advertise | Privacy | Mobile
Web02 | 2.8.141015.1 | Last Updated 5 Sep 2008
Article Copyright 2007 by Colin Vella
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid