Click here to Skip to main content
15,891,253 members
Articles / Hosted Services / Serverless

Peer Graph - Search Criteria Helper

Rate me:
Please Sign up or sign in to vote.
4.17/5 (2 votes)
16 Jan 20067 min read 35.9K   510   14  
Expression conversion to XML search criteria for a Peer Graph, using Microsoft's Peer-to-Peer technology.
'----------------------------------------------------------------------
' Gold Parser engine.
' See more details on http:'www.devincook.com/goldparser/
' 
' Original code is written in VB by Devin Cook (GOLDParser@DevinCook.com)
'
' This translation is done by Vladimir Morozov (vmoroz@hotmail.com)
' 
' The translation is based on the other engine translations:
' Delphi engine by Alexandre Rai (riccio@gmx.at)
' C# engine by Marcus Klimstra (klimstra@home.nl)
'----------------------------------------------------------------------

Imports System
Imports System.Text

Namespace GoldParser
    ''' <summary>
    ''' Represents individual syntactic units.
    ''' </summary>
    ''' <remarks>
    ''' While the Symbol represents a class of terminals and nonterminals, 
    ''' the Token represents an individual piece of information.
    ''' </remarks>
    Class Token
        Private m_symbol As Symbol
        Private m_data As Object
        Private m_reduction As Reduction
        Private m_state As LalrState
        Private m_lineNumber As Integer = 0

        ''' <summary>
        ''' Create a new instance of <c>Token</c> class.
        ''' </summary>
        ''' <param name="symbol">Symbol associated with the token.</param>
        ''' <param name="data">Source object associated with the token.</param>
        ''' <param name="lineNumber">Line number where the token parsed.</param>
        Public Sub New(ByVal symbol As Symbol, ByVal data As Object, ByVal lineNumber As Integer)
            m_symbol = symbol
            m_data = data
            m_lineNumber = lineNumber
        End Sub

        ''' <summary>
        ''' Create a new instance of <c>Token</c> class.
        ''' </summary>
        ''' <param name="symbol">Symbol associated with the token.</param>
        ''' <param name="reduction">Reduction associated with the token.</param>
        Public Sub New(ByVal symbol As Symbol, ByVal reduction As Reduction)
            m_symbol = symbol
            m_reduction = reduction
        End Sub

        ''' <summary>
        ''' Gets the line number for the token.
        ''' </summary>
        Public ReadOnly Property LineNumber() As Integer
            Get
                If Not m_reduction Is Nothing Then
                    Return m_reduction.LineNumber
                End If
                Return m_lineNumber
            End Get
        End Property

        ''' <summary>
        ''' Gets the token data object.
        ''' </summary>
        Public ReadOnly Property Data() As Object
            Get
                Return m_data
            End Get
        End Property

        ''' <summary>
        ''' Gets or sets the token symbol.
        ''' </summary>
        Public Property Symbol() As Symbol
            Get
                Return m_symbol
            End Get
            Set(ByVal value As Symbol)
                m_symbol = value
            End Set
        End Property

        ''' <summary>
        ''' Gets or sets the token reduction.
        ''' </summary>
        Public Property Reduction() As Reduction
            Get
                Return m_reduction
            End Get
            Set(ByVal value As Reduction)
                m_reduction = value
            End Set
        End Property

        ''' <summary>
        ''' Gets or sets the LALR state for the token.
        ''' </summary>
        Public Property LalrState() As LalrState
            Get
                Return m_state
            End Get
            Set(ByVal value As LalrState)
                m_state = value
            End Set
        End Property

        ''' <summary>
        ''' Gets the symbol type.
        ''' </summary>
        Public ReadOnly Property SymbolType() As SymbolType
            Get
                Return Symbol.SymbolType
            End Get
        End Property

        ''' <summary>
        ''' Gets the symbol name.
        ''' </summary>
        Public ReadOnly Property Name() As String
            Get
                Return Symbol.Name
            End Get
        End Property

        ''' <summary>
        ''' Returns string representation of the token.
        ''' </summary>
        ''' <returns>String representation of the token.</returns>
        Public Overrides Function ToString() As String
            If (SymbolType <> SymbolType.Terminal) Then
                Return Symbol.ToString()
            End If

            Dim sb As StringBuilder = New StringBuilder
            For i As Integer = 0 To CType(m_data, String).Length - 1
                Dim ch As Char = CType(m_data, String).Chars(i)
                If ch < " "c Then
                    Select Case ch
                        Case ChrW(10)
                            sb.Append("{LF}")
                        Case ChrW(13)
                            sb.Append("{CR}")
                        Case ChrW(9)
                            sb.Append("{HT}")
                    End Select
                Else
                    sb.Append(ch)
                End If
            Next
            Return sb.ToString()
        End Function
    End Class
End 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 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
Web Developer
Canada Canada
Adrian Moore is the Development Manager for the SCADA Vision system developed by ABB Inc in Calgary, Alberta.

He has been interested in compilers, parsers, real-time database systems and peer-to-peer solutions since the early 90's. In his spare time, he is currently working on a SQL parser for querying .NET DataSets (http://www.queryadataset.com).

Adrian is a Microsoft MVP for Windows Networking.

Comments and Discussions