parser(expressions).vb

来自「大名鼎鼎的mono是.NET平台的跨平台(支持linux」· VB 代码 · 共 1,598 行 · 第 1/5 页

VB
1,598
字号
' ' Visual Basic.Net Compiler' Copyright (C) 2004 - 2007 Rolf Bjarne Kvinge, RKvinge@novell.com' ' This library is free software; you can redistribute it and/or' modify it under the terms of the GNU Lesser General Public' License as published by the Free Software Foundation; either' version 2.1 of the License, or (at your option) any later version.' ' This library 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' Lesser General Public License for more details.' ' You should have received a copy of the GNU Lesser General Public' License along with this library; if not, write to the Free Software' Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA' Partial Class Parser    Private Function ParseGlobalExpression(ByVal Parent As ParsedObject) As GlobalExpression        tm.AcceptIfNotInternalError(KS.Global)        Return New GlobalExpression(Parent)    End Function    Private Function ParseBuiltInTypeExpression(ByVal Parent As ParsedObject) As BuiltInTypeExpression        Dim result As New BuiltInTypeExpression(Parent)        Dim m_Type As BuiltInDataTypes        Helper.Assert(tm.CurrentToken.Equals(Enums.BuiltInTypeTypeNames))        m_Type = CType(tm.CurrentToken.Keyword, BuiltInDataTypes)        tm.NextToken()        result.Init(m_Type)        Return result    End Function    ''' <summary>    ''' MemberAccessExpression ::= [ [ MemberAccessBase ] "." ] IdentifierOrKeyword    ''' MemberAccessBase ::= Expression | BuiltInTypeName | "Global" | "MyClass" | "MyBase"    '''     ''' TODO: Is this correct? Is the "." optional in a MemberAccessExpression?    ''' LAMESPEC: IdentifierOrKeyword should be followed by type parameters...    ''' MemberAccessExpression ::= [ [ MemberAccessBase ] "." ] IdentifierOrKeyword [ TypeParametersList ]    ''' </summary>    ''' <param name="FirstExpression"></param>    ''' <returns></returns>    ''' <remarks></remarks>    Private Function ParseMemberAccessExpression(ByVal Parent As ParsedObject, ByVal FirstExpression As Expression) As MemberAccessExpression        Dim result As New MemberAccessExpression(Parent)        Dim m_First As Expression        Dim m_Second As IdentifierOrKeywordWithTypeArguments        m_First = FirstExpression 'Might be nothing.        If m_First IsNot Nothing Then m_First.Parent = result        'According to the language specification, the dot is optional,        'but that doesn't seem to be correct... so let's make it         'required        tm.AcceptIfNotInternalError(KS.Dot)        'Specifically, this is not a MemberAccessExpression without the        'dot, so it is an internal error.        m_Second = ParseIdentifierOrKeywordWithTypeArguments(result)        If m_Second Is Nothing Then Helper.ErrorRecoveryNotImplemented()        result.Init(m_First, m_Second)        Return result    End Function    Private Function ParseIdentifierOrKeywordWithTypeArguments(ByVal Parent As ParsedObject) As IdentifierOrKeywordWithTypeArguments        Dim result As New IdentifierOrKeywordWithTypeArguments(Parent)        Dim m_TypeArguments As TypeArgumentList        Dim m_Token As Token        If tm.CurrentToken.IsIdentifierOrKeyword Then            m_Token = tm.CurrentToken            tm.NextToken()        Else            Helper.ErrorRecoveryNotImplemented()            Return Nothing        End If        If tm.CurrentToken.Equals(KS.LParenthesis) AndAlso tm.PeekToken.Equals(KS.Of) Then            m_TypeArguments = ParseTypeArgumentList(result)            If m_TypeArguments Is Nothing Then Helper.ErrorRecoveryNotImplemented()        Else            m_TypeArguments = Nothing        End If        result.Init(m_Token, m_TypeArguments)        Return result    End Function    ''' <summary>    ''' DictionaryAccessExpression ::= [Expression] "!" IdentifierOrKeyword    ''' </summary>    ''' <remarks></remarks>    Private Function ParseDictionaryAccessExpression(ByVal Parent As ParsedObject, ByVal FirstPart As Expression) As DictionaryAccessExpression        Dim result As New DictionaryAccessExpression(Parent)        Dim m_FirstPart As Expression        Dim m_SecondPart As IdentifierOrKeyword        m_FirstPart = FirstPart        If m_FirstPart IsNot Nothing Then m_FirstPart.Parent = result        tm.AcceptIfNotInternalError(KS.Exclamation)        If tm.CurrentToken.IsIdentifierOrKeyword Then            m_SecondPart = ParseIdentifierOrKeyword(result)            If m_SecondPart Is Nothing Then Helper.ErrorRecoveryNotImplemented()        Else            Compiler.Report.ShowMessage(Messages.VBNC30203)            Return Nothing        End If        result.Init(m_FirstPart, m_SecondPart)        Return result    End Function    Private Function ParseCByteExpression(ByVal Parent As ParsedObject) As CByteExpression        Dim result As New CByteExpression(Parent)        Dim m_Expression As Expression        tm.AcceptIfNotInternalError(KS.CByte)        m_Expression = ParseParenthesizedExpression(Parent)        If m_Expression Is Nothing Then Helper.ErrorRecoveryNotImplemented()        result.Init(m_Expression)        Return result    End Function    Private Function ParseCBoolExpression(ByVal Parent As ParsedObject) As CBoolExpression        Dim result As New CBoolExpression(Parent)        Dim m_Expression As Expression        tm.AcceptIfNotInternalError(KS.CBool)        m_Expression = ParseParenthesizedExpression(Parent)        If m_Expression Is Nothing Then Helper.ErrorRecoveryNotImplemented()        result.Init(m_Expression)        Return result    End Function    Private Function ParseCCharExpression(ByVal Parent As ParsedObject) As CCharExpression        Dim result As New CCharExpression(Parent)        Dim m_Expression As Expression        tm.AcceptIfNotInternalError(KS.CChar)        m_Expression = ParseParenthesizedExpression(Parent)        If m_Expression Is Nothing Then Helper.ErrorRecoveryNotImplemented()        result.Init(m_Expression)        Return result    End Function    Private Function ParseCDateExpression(ByVal Parent As ParsedObject) As CDateExpression        Dim result As New CDateExpression(Parent)        Dim m_Expression As Expression        tm.AcceptIfNotInternalError(KS.CDate)        m_Expression = ParseParenthesizedExpression(Parent)        If m_Expression Is Nothing Then Helper.ErrorRecoveryNotImplemented()        result.Init(m_Expression)        Return result    End Function    Private Function ParseCDblExpression(ByVal Parent As ParsedObject) As CDblExpression        Dim result As New CDblExpression(Parent)        Dim m_Expression As Expression        tm.AcceptIfNotInternalError(KS.CDbl)        m_Expression = ParseParenthesizedExpression(Parent)        If m_Expression Is Nothing Then Helper.ErrorRecoveryNotImplemented()        result.Init(m_Expression)        Return result    End Function    Private Function ParseCDecExpression(ByVal Parent As ParsedObject) As CDecExpression        Dim result As New CDecExpression(Parent)        Dim m_Expression As Expression        tm.AcceptIfNotInternalError(KS.CDec)        m_Expression = ParseParenthesizedExpression(Parent)        If m_Expression Is Nothing Then Helper.ErrorRecoveryNotImplemented()        result.Init(m_Expression)        Return result    End Function    Private Function ParseCIntExpression(ByVal Parent As ParsedObject) As CIntExpression        Dim result As New CIntExpression(Parent)        Dim m_Expression As Expression        tm.AcceptIfNotInternalError(KS.CInt)        m_Expression = ParseParenthesizedExpression(Parent)        If m_Expression Is Nothing Then Helper.ErrorRecoveryNotImplemented()        result.Init(m_Expression)        Return result    End Function    Private Function ParseCLngExpression(ByVal Parent As ParsedObject) As CLngExpression        Dim result As New CLngExpression(Parent)        Dim m_Expression As Expression        tm.AcceptIfNotInternalError(KS.CLng)        m_Expression = ParseParenthesizedExpression(Parent)        If m_Expression Is Nothing Then Helper.ErrorRecoveryNotImplemented()        result.Init(m_Expression)        Return result    End Function    Private Function ParseCObjExpression(ByVal Parent As ParsedObject) As CObjExpression        Dim result As New CObjExpression(Parent)        Dim m_Expression As Expression        tm.AcceptIfNotInternalError(KS.CObj)        m_Expression = ParseParenthesizedExpression(Parent)        If m_Expression Is Nothing Then Helper.ErrorRecoveryNotImplemented()        result.Init(m_Expression)        Return result    End Function    Private Function ParseCSByteExpression(ByVal Parent As ParsedObject) As CSByteExpression        Dim result As New CSByteExpression(Parent)        Dim m_Expression As Expression        tm.AcceptIfNotInternalError(KS.CSByte)        m_Expression = ParseParenthesizedExpression(Parent)        If m_Expression Is Nothing Then Helper.ErrorRecoveryNotImplemented()        result.Init(m_Expression)        Return result    End Function    Private Function ParseCShortExpression(ByVal Parent As ParsedObject) As CShortExpression        Dim result As New CShortExpression(Parent)        Dim m_Expression As Expression        tm.AcceptIfNotInternalError(KS.CShort)        m_Expression = ParseParenthesizedExpression(Parent)        If m_Expression Is Nothing Then Helper.ErrorRecoveryNotImplemented()        result.Init(m_Expression)        Return result    End Function    Private Function ParseCSngExpression(ByVal Parent As ParsedObject) As CSngExpression        Dim result As New CSngExpression(Parent)        Dim m_Expression As Expression        tm.AcceptIfNotInternalError(KS.CSng)        m_Expression = ParseParenthesizedExpression(Parent)        If m_Expression Is Nothing Then Helper.ErrorRecoveryNotImplemented()        result.Init(m_Expression)        Return result    End Function    Private Function ParseCStrExpression(ByVal Parent As ParsedObject) As CStrExpression        Dim result As New CStrExpression(Parent)        Dim m_Expression As Expression        tm.AcceptIfNotInternalError(KS.CStr)        m_Expression = ParseParenthesizedExpression(Parent)        If m_Expression Is Nothing Then Helper.ErrorRecoveryNotImplemented()        result.Init(m_Expression)        Return result

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?